Skip to content

Commit

Permalink
Fixed ctab_add_bytes().
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 21, 2008
1 parent f264e95 commit 6c30f4b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mojoshader_assembler.c
Expand Up @@ -1692,12 +1692,18 @@ static uint32 add_ctab_bytes(Context *ctx, const uint8 *bytes, const size_t len)
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...
Expand Down

0 comments on commit 6c30f4b

Please sign in to comment.