[quake3-commits] r2180 - trunk/code/qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Sep 27 17:49:01 EDT 2011


Author: thilo
Date: 2011-09-27 17:49:01 -0400 (Tue, 27 Sep 2011)
New Revision: 2180

Modified:
   trunk/code/qcommon/vm.c
Log:
Add some checks when reloading QVMs via VM_Restart()


Modified: trunk/code/qcommon/vm.c
===================================================================
--- trunk/code/qcommon/vm.c	2011-09-27 21:17:21 UTC (rev 2179)
+++ trunk/code/qcommon/vm.c	2011-09-27 21:49:01 UTC (rev 2180)
@@ -447,15 +447,28 @@
 	}
 	dataLength = 1 << i;
 
-	if( alloc ) {
+	if(alloc)
+	{
 		// allocate zero filled space for initialized and uninitialized data
-		vm->dataBase = Hunk_Alloc( dataLength, h_high );
+		vm->dataBase = Hunk_Alloc(dataLength, h_high);
 		vm->dataMask = dataLength - 1;
-	} else {
-		// clear the data
-		Com_Memset( vm->dataBase, 0, dataLength );
 	}
+	else
+	{
+		// clear the data, but make sure we're not clearing more than allocated
+		if(vm->dataMask + 1 != dataLength)
+		{
+			VM_Free(vm);
+			FS_FreeFile(header.v);
 
+			Com_Printf(S_COLOR_YELLOW "Warning: Data region size of %s not matching after"
+					"VM_Restart()\n", filename);
+			return NULL;
+		}
+		
+		Com_Memset(vm->dataBase, 0, dataLength);
+	}
+
 	// copy the intialized data
 	Com_Memcpy( vm->dataBase, (byte *)header.h + header.h->dataOffset,
 		header.h->dataLength + header.h->litLength );
@@ -465,19 +478,35 @@
 		*(int *)(vm->dataBase + i) = LittleLong( *(int *)(vm->dataBase + i ) );
 	}
 
-	if( header.h->vmMagic == VM_MAGIC_VER2 ) {
-		vm->numJumpTableTargets = header.h->jtrgLength >> 2;
-		Com_Printf( "Loading %d jump table targets\n", vm->numJumpTableTargets );
+	if(header.h->vmMagic == VM_MAGIC_VER2)
+	{
+		Com_Printf("Loading %d jump table targets\n", vm->numJumpTableTargets);
 
-		if( alloc ) {
-			vm->jumpTableTargets = Hunk_Alloc( header.h->jtrgLength, h_high );
-		} else {
-			Com_Memset( vm->jumpTableTargets, 0, header.h->jtrgLength );
+		header.h->jtrgLength &= ~0x03;
+
+		if(alloc)
+		{
+			vm->jumpTableTargets = Hunk_Alloc(header.h->jtrgLength, h_high);
+			vm->numJumpTableTargets = header.h->jtrgLength >> 2;
 		}
+		else
+		{
+			if((header.h->jtrgLength >> 2) != vm->numJumpTableTargets)
+			{
+				VM_Free(vm);
+				FS_FreeFile(header.v);
 
-		Com_Memcpy( vm->jumpTableTargets, (byte *)header.h + header.h->dataOffset +
-				header.h->dataLength + header.h->litLength, header.h->jtrgLength );
+				Com_Printf(S_COLOR_YELLOW "Warning: Jump table size of %s not matching after"
+						"VM_Restart()\n", filename);
+				return NULL;
+			}
 
+			Com_Memset(vm->jumpTableTargets, 0, header.h->jtrgLength);
+		}
+
+		Com_Memcpy(vm->jumpTableTargets, (byte *) header.h + header.h->dataOffset +
+				header.h->dataLength + header.h->litLength, header.h->jtrgLength);
+
 		// byte swap the longs
 		for ( i = 0 ; i < header.h->jtrgLength ; i += 4 ) {
 			*(int *)(vm->jumpTableTargets + i) = LittleLong( *(int *)(vm->jumpTableTargets + i ) );



More information about the quake3-commits mailing list