Fixed ctab_add_bytes().
authorRyan C. Gordon <icculus@icculus.org>
Sun, 21 Dec 2008 09:55:10 -0500
changeset 527 7bc4c80ef02c
parent 526 ba7df2cd0371
child 528 3ce47a5d9fe4
Fixed ctab_add_bytes().
mojoshader_assembler.c
--- a/mojoshader_assembler.c	Sun Dec 21 05:06:05 2008 -0500
+++ b/mojoshader_assembler.c	Sun Dec 21 09:55:10 2008 -0500
@@ -1692,12 +1692,18 @@
     if (len <= (ctx->ctab_len - extra))
     {
         void *ptr = ctx->ctab + extra;
-        while ((ptr = memchr(ptr, bytes[0], ctx->ctab_len - len)) != NULL)
-        {
-            if (memcmp(ptr, bytes, len) == 0)  // already have it?
-                return ( (uint32) (ctx->ctab - ((uint8 *) ptr)) );
-            ptr++;
-        } // while
+        if (len == 0)
+            return ( (uint32) (((uint8 *) ptr) - ctx->ctab) );
+        else if ((len == 1) && ((ptr = memchr(ptr, bytes[0], ctx->ctab_len - len)) != NULL))
+            return ( (uint32) (((uint8 *) ptr) - ctx->ctab) );
+        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) );
+                ptr++;
+            } // while
+        } // else
     } // if
 
     // add it to the byte pile...