Navigation Menu

Skip to content

Commit

Permalink
Fixed parse_num().
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 12, 2009
1 parent 71e3dfe commit d26f1aa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mojoshader_assembler.c
Expand Up @@ -982,13 +982,23 @@ static int parse_args_NULL(Context *ctx)
static int parse_num(Context *ctx, const int floatok, uint32 *value)
{
union { float f; int32 si32; uint32 ui32; } cvt;
int negative = 0;
Token token = nexttoken(ctx);

if (token == ((Token) '-'))
{
negative = 1;
token = nexttoken(ctx);
} // if

const Token token = nexttoken(ctx);
if (token == TOKEN_INT_LITERAL)
{
int d = 0;
sscanf(ctx->token, "%d", &d);
cvt.si32 = (int32) d;
if (floatok)
cvt.f = (float) ((negative) ? -d : d);
else
cvt.si32 = (int32) ((negative) ? -d : d);
} // if
else if (token == TOKEN_FLOAT_LITERAL)
{
Expand All @@ -999,6 +1009,8 @@ static int parse_num(Context *ctx, const int floatok, uint32 *value)
return 0;
} // if
sscanf(ctx->token, "%f", &cvt.f);
if (negative)
cvt.f = -cvt.f;
} // if
else
{
Expand Down

0 comments on commit d26f1aa

Please sign in to comment.