r179 - trunk/code/qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Oct 26 13:09:50 EDT 2005


Author: tma
Date: 2005-10-26 13:09:50 -0400 (Wed, 26 Oct 2005)
New Revision: 179

Modified:
   trunk/code/qcommon/vm.c
Log:
* Fixed a bug with QVM loading on big endian architectures


Modified: trunk/code/qcommon/vm.c
===================================================================
--- trunk/code/qcommon/vm.c	2005-10-25 13:34:47 UTC (rev 178)
+++ trunk/code/qcommon/vm.c	2005-10-26 17:09:50 UTC (rev 179)
@@ -373,33 +373,42 @@
 		return NULL;
 	}
 
-	// byte swap the header
-	for ( i = 0 ; i < sizeof( *header ) / 4 ; i++ ) {
-		((int *)header)[i] = LittleLong( ((int *)header)[i] );
-	}
+	if( LittleLong( header->vmMagic ) == VM_MAGIC_VER2 ) {
+		Com_Printf( "...which has vmMagic VM_MAGIC_VER2\n" );
 
-	if( header->vmMagic == VM_MAGIC_VER2 ) {
-		Com_Printf( "...which has vmMagic VM_MAGIC_VER2\n" );
+		// byte swap the header
+		for ( i = 0 ; i < sizeof( vmHeader_t ) / 4 ; i++ ) {
+			((int *)header)[i] = LittleLong( ((int *)header)[i] );
+		}
+
 		// validate
-		if ( header->vmMagic != VM_MAGIC_VER2
-			|| header->jtrgLength < 0 
-			|| header->bssLength < 0 
-			|| header->dataLength < 0 
-			|| header->litLength < 0 
+		if ( header->jtrgLength < 0
+			|| header->bssLength < 0
+			|| header->dataLength < 0
+			|| header->litLength < 0
 			|| header->codeLength <= 0 ) {
 			VM_Free( vm );
 			Com_Error( ERR_FATAL, "%s has bad header", filename );
 		}
-	} else {
+	} else if( LittleLong( header->vmMagic ) == VM_MAGIC ) {
+		// byte swap the header
+		// sizeof( vmHeader_t ) - sizeof( int ) is the 1.32b vm header size
+		for ( i = 0 ; i < ( sizeof( vmHeader_t ) - sizeof( int ) ) / 4 ; i++ ) {
+			((int *)header)[i] = LittleLong( ((int *)header)[i] );
+		}
+
 		// validate
-		if ( header->vmMagic != VM_MAGIC
-			|| header->bssLength < 0 
-			|| header->dataLength < 0 
-			|| header->litLength < 0 
+		if ( header->bssLength < 0
+			|| header->dataLength < 0
+			|| header->litLength < 0
 			|| header->codeLength <= 0 ) {
 			VM_Free( vm );
 			Com_Error( ERR_FATAL, "%s has bad header", filename );
 		}
+	} else {
+		VM_Free( vm );
+		Com_Error( ERR_FATAL, "%s does not have a recognisable "
+				"magic number in its header", filename );
 	}
 
 	// round up to next power of 2 so all data operations can




More information about the quake3-commits mailing list