Offsets into CTAB need to start immediately _after_ the ID field.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 21 Dec 2008 17:59:47 -0500
changeset 529 e77225cd13ae
parent 528 3ce47a5d9fe4
child 530 8bb8fc38f751
Offsets into CTAB need to start immediately _after_ the ID field.
mojoshader_assembler.c
--- a/mojoshader_assembler.c	Sun Dec 21 09:56:13 2008 -0500
+++ b/mojoshader_assembler.c	Sun Dec 21 17:59:47 2008 -0500
@@ -1693,15 +1693,15 @@
     {
         void *ptr = ctx->ctab + extra;
         if (len == 0)
-            return ( (uint32) (((uint8 *) ptr) - ctx->ctab) );
+            return ( (uint32) (((uint8 *) ptr) - ctx->ctab) ) - sizeof (uint32);
         else if ((len == 1) && ((ptr = memchr(ptr, bytes[0], ctx->ctab_len - len)) != NULL))
-            return ( (uint32) (((uint8 *) ptr) - ctx->ctab) );
+            return ( (uint32) (((uint8 *) ptr) - ctx->ctab) ) - sizeof (uint32);
         else  // search for the string of bytes...
         {
             while ((ptr = memchr(ptr, bytes[0], ctx->ctab_len - len)) != NULL)
             {
                 if (memcmp(ptr, bytes, len) == 0)  // this is it?
-                    return ( (uint32) (((uint8 *) ptr) - ctx->ctab) );
+                    return ( (uint32) (((uint8 *) ptr) - ctx->ctab) ) - sizeof (uint32);
                 ptr++;
             } // while
         } // else
@@ -1727,7 +1727,7 @@
         ctx->ctab = (uint8 *) ptr;
     } // if
 
-    const uint32 retval = ctx->ctab_len;
+    const uint32 retval = ctx->ctab_len - sizeof (uint32);
     memcpy(ctx->ctab + ctx->ctab_len, bytes, len);
     ctx->ctab_len += len;
     return retval;