Preprocessor: fixed logic bug introduced when migrating to Buffer.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 15 Nov 2010 17:43:01 -0500
changeset 952 7e7d5737f9a6
parent 951 6ef73d06ecb0
child 953 ebcde4f1e376
Preprocessor: fixed logic bug introduced when migrating to Buffer. Fixes failing unit tests.
mojoshader_preprocessor.c
--- a/mojoshader_preprocessor.c	Mon Nov 15 17:29:29 2010 -0500
+++ b/mojoshader_preprocessor.c	Mon Nov 15 17:43:01 2010 -0500
@@ -1431,7 +1431,9 @@
 
         if (saw_params < expected)
         {
+            const int origdeflen = (int) buffer_size(origbuffer);
             char *origdefinition = buffer_flatten(origbuffer);
+            const int deflen = (int) buffer_size(buffer);
             char *definition = buffer_flatten(buffer);
             Define *p = get_define(ctx);
             if ((!origdefinition) || (!definition) || (!p))
@@ -1446,7 +1448,7 @@
 
             // trim any whitespace from the end of the string...
             int i;
-            for (i = (int) buffer_size(buffer) - 1; i >= 0; i--)
+            for (i = deflen - 1; i >= 0; i--)
             {
                 if (definition[i] == ' ')
                     definition[i] = '\0';
@@ -1454,7 +1456,7 @@
                     break;
             } // for
 
-            for (i = (int) buffer_size(origbuffer) - 1; i >= 0; i--)
+            for (i = origdeflen - 1; i >= 0; i--)
             {
                 if (origdefinition[i] == ' ')
                     origdefinition[i] = '\0';