mirror of
https://github.com/UberGames/ioef.git
synced 2024-11-27 14:32:55 +00:00
* Fixed a bug with QVM loading on big endian architectures
This commit is contained in:
parent
d5af2e3d45
commit
9f55ae2dce
1 changed files with 29 additions and 20 deletions
|
@ -373,33 +373,42 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// byte swap the header
|
if( LittleLong( header->vmMagic ) == VM_MAGIC_VER2 ) {
|
||||||
for ( i = 0 ; i < sizeof( *header ) / 4 ; i++ ) {
|
|
||||||
((int *)header)[i] = LittleLong( ((int *)header)[i] );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( header->vmMagic == VM_MAGIC_VER2 ) {
|
|
||||||
Com_Printf( "...which has vmMagic VM_MAGIC_VER2\n" );
|
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
|
// validate
|
||||||
if ( header->vmMagic != VM_MAGIC_VER2
|
if ( header->jtrgLength < 0
|
||||||
|| header->jtrgLength < 0
|
|| header->bssLength < 0
|
||||||
|| header->bssLength < 0
|
|| header->dataLength < 0
|
||||||
|| header->dataLength < 0
|
|| header->litLength < 0
|
||||||
|| header->litLength < 0
|
|| header->codeLength <= 0 ) {
|
||||||
|
VM_Free( vm );
|
||||||
|
Com_Error( ERR_FATAL, "%s has bad header", filename );
|
||||||
|
}
|
||||||
|
} 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->bssLength < 0
|
||||||
|
|| header->dataLength < 0
|
||||||
|
|| header->litLength < 0
|
||||||
|| header->codeLength <= 0 ) {
|
|| header->codeLength <= 0 ) {
|
||||||
VM_Free( vm );
|
VM_Free( vm );
|
||||||
Com_Error( ERR_FATAL, "%s has bad header", filename );
|
Com_Error( ERR_FATAL, "%s has bad header", filename );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// validate
|
VM_Free( vm );
|
||||||
if ( header->vmMagic != VM_MAGIC
|
Com_Error( ERR_FATAL, "%s does not have a recognisable "
|
||||||
|| header->bssLength < 0
|
"magic number in its header", filename );
|
||||||
|| header->dataLength < 0
|
|
||||||
|| header->litLength < 0
|
|
||||||
|| header->codeLength <= 0 ) {
|
|
||||||
VM_Free( vm );
|
|
||||||
Com_Error( ERR_FATAL, "%s has bad header", filename );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// round up to next power of 2 so all data operations can
|
// round up to next power of 2 so all data operations can
|
||||||
|
|
Loading…
Reference in a new issue