foxygit / doom Log in
commit 9531cdfcfadc0d4c2b767f27238bc9ac742787e0
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Sep 13 02:39:50 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Sep 13 02:39:50 2014 -0400

    dehacked: Set stricter scoping for magic comments.

    Magic comments allow some of the Vanilla limits to be overridden, but
    they should only apply to the files in which they were defined. Reset
    the flag variables that control these overrides before every new
    Dehacked file is parsed, so that a flag set in one file cannot spill
    over into other files that are parsed subsequently.
---
 src/deh_main.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/src/deh_main.c b/src/deh_main.c
index e201ce38..a7846975 100644
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -358,6 +358,13 @@ int DEH_LoadFile(char *filename)
         deh_initialized = true;
     }

+    // Before parsing a new file, reset special override flags to false.
+    // Magic comments should only apply to the file in which they were
+    // defined, and shouldn't carry over to subsequent files as well.
+    deh_allow_long_strings = false;
+    deh_allow_long_cheats = false;
+    deh_allow_extended_strings = false;
+
     printf(" loading %s\n", filename);

     context = DEH_OpenFile(filename);
@@ -367,9 +374,9 @@ int DEH_LoadFile(char *filename)
         fprintf(stderr, "DEH_LoadFile: Unable to open %s\n", filename);
         return 0;
     }
-
+
     DEH_ParseContext(context);
-
+
     DEH_CloseFile(context);

     return 1;
@@ -381,7 +388,6 @@ int DEH_LoadFile(char *filename)
 int DEH_LoadLump(int lumpnum, boolean allow_long)
 {
     deh_context_t *context;
-    boolean long_strings, long_cheats;

     if (!deh_initialized)
     {
@@ -389,13 +395,10 @@ int DEH_LoadLump(int lumpnum, boolean allow_long)
         deh_initialized = true;
     }

-    if (allow_long)
-    {
-        long_strings = deh_allow_long_strings;
-        long_cheats = deh_allow_long_cheats;
-        deh_allow_long_strings = true;
-        deh_allow_long_cheats = true;
-    }
+    // Reset all special flags to defaults.
+    deh_allow_long_strings = allow_long;
+    deh_allow_long_cheats = allow_long;
+    deh_allow_extended_strings = false;

     context = DEH_OpenLump(lumpnum);

@@ -409,13 +412,6 @@ int DEH_LoadLump(int lumpnum, boolean allow_long)

     DEH_CloseFile(context);

-    // Restore old value of long flags.
-    if (allow_long)
-    {
-        deh_allow_long_strings = long_strings;
-        deh_allow_long_cheats = long_cheats;
-    }
-
     return 1;
 }