shithub: choc

Download patch

ref: f4f2242c5534a64ab4c208479a6a722cf7f6a877
parent: 53e98bc707cc0a37773985cfdce5419a7491da26
author: Simon Howard <[email protected]>
date: Fri Jan 5 15:26:13 EST 2018

hexen: Use ReadCodeInt() to parse header.

This needs to be validated too, and it's simplest to just reuse the
same mechanism used for executing code.

--- a/src/hexen/p_acs.c
+++ b/src/hexen/p_acs.c
@@ -374,18 +374,17 @@
 void P_LoadACScripts(int lump)
 {
     int i;
-    int *buffer;
     acsHeader_t *header;
     acsInfo_t *info;
 
-    header = W_CacheLumpNum(lump, PU_LEVEL);
-    ActionCodeBase = (byte *) header;
+    ActionCodeBase = W_CacheLumpNum(lump, PU_LEVEL);
     ActionCodeSize = W_LumpLength(lump);
-    buffer = (int *) ((byte *) header + LONG(header->infoOffset));
 
-    ACScriptCount = LONG(*buffer);
-    ++buffer;
+    header = (acsHeader_t *) ActionCodeBase;
+    PCodeOffset = LONG(header->infoOffset);
 
+    ACScriptCount = ReadCodeInt();
+
     if (ACScriptCount == 0)
     {                           // Empty behavior lump
         return;
@@ -395,15 +394,10 @@
     memset(ACSInfo, 0, ACScriptCount * sizeof(acsInfo_t));
     for (i = 0, info = ACSInfo; i < ACScriptCount; i++, info++)
     {
-        info->number = LONG(*buffer);
-        ++buffer;
+        info->number = ReadCodeInt();
+        info->offset = ValidateLumpOffset(ReadCodeInt(), "script header");
+        info->argCount = ReadCodeInt();
 
-        info->offset = ValidateLumpOffset(LONG(*buffer), "script header");
-        ++buffer;
-
-        info->argCount = LONG(*buffer);
-        ++buffer;
-
         if (info->argCount > MAX_SCRIPT_ARGS)
         {
             fprintf(stderr, "Warning: ACS script #%i has %i arguments, more "
@@ -425,15 +419,15 @@
             info->state = ASTE_INACTIVE;
         }
     }
-    ACStringCount = LONG(*buffer);
-    ++buffer;
 
+    ACStringCount = ReadCodeInt();
+    ACSAssert(ACStringCount >= 0, "negative string count %d", ACStringCount);
     ACStrings = Z_Malloc(ACStringCount * sizeof(char *), PU_LEVEL, NULL);
 
     for (i=0; i<ACStringCount; ++i)
     {
         ACStrings[i] = (char *) ActionCodeBase +
-                       ValidateLumpOffset(LONG(buffer[i]), "string header");
+                       ValidateLumpOffset(ReadCodeInt(), "string header");
     }
 
     memset(MapVars, 0, sizeof(MapVars));