aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-10-26 17:09:50 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-10-26 17:09:50 +0000
commit54ab6164f52286508e77f4ba7936e9f23b4e02bd (patch)
tree6fa697ee3beb695fcf81e8e107e66641b823ff3c
parente65c1571677ec577e9a98b595a4a0989b62c95fc (diff)
downloadioquake3-aero-54ab6164f52286508e77f4ba7936e9f23b4e02bd.tar.gz
ioquake3-aero-54ab6164f52286508e77f4ba7936e9f23b4e02bd.zip
* Fixed a bug with QVM loading on big endian architectures
git-svn-id: svn://svn.icculus.org/quake3/trunk@179 edf5b092-35ff-0310-97b2-ce42778d08ea
-rw-r--r--code/qcommon/vm.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/code/qcommon/vm.c b/code/qcommon/vm.c
index fc795cd..8ebe73d 100644
--- a/code/qcommon/vm.c
+++ b/code/qcommon/vm.c
@@ -373,33 +373,42 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) {
return NULL;
}
- // byte swap the header
- for ( i = 0 ; i < sizeof( *header ) / 4 ; i++ ) {
- ((int *)header)[i] = LittleLong( ((int *)header)[i] );
- }
-
- if( header->vmMagic == VM_MAGIC_VER2 ) {
+ if( LittleLong( 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