]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
[q3map2] Unwind script stack in case of script loading error.
authorThomas Köppe <tkoeppe@google.com>
Mon, 8 Jan 2018 15:18:29 +0000 (15:18 +0000)
committerThomas Debesse <dev@illwieckz.net>
Sat, 27 Jan 2018 20:27:50 +0000 (21:27 +0100)
Also avoid type punning read into char* variable (even though char* and void* happen to be layout-compatible).

tools/quake3/common/scriplib.c

index 359a078dcfce541b4795cc3768ad42adc00f38a1..f41d53031a6c2cede444a2f929dbc86b1aa7cff2 100644 (file)
@@ -58,6 +58,7 @@ qboolean tokenready;                     // only qtrue if UnGetToken was just ca
  */
 void AddScriptToStack( const char *filename, int index ){
        int size;
+       void* buffer;
 
        script++;
        if ( script == &scriptstack[MAX_INCLUDES] ) {
@@ -65,10 +66,11 @@ void AddScriptToStack( const char *filename, int index ){
        }
        strcpy( script->filename, ExpandPath( filename ) );
 
-       size = vfsLoadFile( script->filename, (void **)&script->buffer, index );
+       size = vfsLoadFile( script->filename, &buffer, index );
 
        if ( size == -1 ) {
                Sys_Printf( "Script file %s was not found\n", script->filename );
+               script--;
        }
        else
        {
@@ -78,11 +80,12 @@ void AddScriptToStack( const char *filename, int index ){
                else{
                        Sys_Printf( "entering %s\n", script->filename );
                }
-       }
 
-       script->line = 1;
-       script->script_p = script->buffer;
-       script->end_p = script->buffer + size;
+               script->buffer = buffer;
+               script->line = 1;
+               script->script_p = script->buffer;
+               script->end_p = script->buffer + size;
+       }
 }