Skip to content

Commit

Permalink
Fixed bytecode parser's main loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 3, 2009
1 parent 5ecf4a9 commit 34b1863
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mojoshader.c
Expand Up @@ -7481,6 +7481,15 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
ctx->parse_phase = MOJOSHADER_PARSEPHASE_WORKING;
rc = parse_version_token(ctx, profile);

if ( ((uint32) rc) > ctx->tokencount )
{
fail(ctx, "Corrupted or truncated shader");
ctx->tokencount = rc;
} // if

ctx->tokens += rc;
ctx->tokencount -= rc;

// parse out the rest of the tokens after the version token...
while (ctx->tokencount > 0)
{
Expand All @@ -7494,17 +7503,15 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
// reset for every token, and consider an error if it ever overflows!
ctx->scratchidx = 0;

rc = parse_token(ctx);
if ( ((uint32) rc) > ctx->tokencount )
{
fail(ctx, "Corrupted or truncated shader");
break;
} // if
else
{
ctx->tokens += rc;
ctx->tokencount -= rc;
rc = parse_token(ctx);
} // else

ctx->tokens += rc;
ctx->tokencount -= rc;
} // while

ctx->parse_phase = MOJOSHADER_PARSEPHASE_DONE;
Expand Down

0 comments on commit 34b1863

Please sign in to comment.