jscript: Fix integer/double parsing.

This commit is contained in:
Piotr Caban 2009-05-27 01:10:49 +02:00 committed by Alexandre Julliard
parent f2c1095a80
commit 063df731ac
2 changed files with 22 additions and 6 deletions

View file

@ -17,6 +17,7 @@
*/
#include <math.h>
#include <limits.h>
#include "jscript.h"
#include "activscp.h"
@ -374,12 +375,18 @@ static int parse_double_literal(parser_ctx_t *ctx, LONG int_part, literal_t **li
{
double d, tmp = 1.0;
if(ctx->ptr == ctx->end || !isdigitW(*ctx->ptr)) {
ERR("No digit after point\n");
if(ctx->ptr == ctx->end || (!isdigitW(*ctx->ptr) &&
*ctx->ptr!='.' && *ctx->ptr!='e' && *ctx->ptr!='E')) {
ERR("Illegal character\n");
return 0;
}
d = int_part;
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
d = d*10 + *(ctx->ptr++) - '0';
if(*ctx->ptr == '.') ctx->ptr++;
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
d += (tmp /= 10.0)*(*ctx->ptr++ - '0');
@ -458,13 +465,20 @@ static int parse_numeric_literal(parser_ctx_t *ctx, literal_t **literal)
}
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
l = l*10 + *(ctx->ptr++)-'0';
{
d = l*10 + *(ctx->ptr)-'0';
/* Check for integer overflow */
if (l > INT_MAX/10 || d < 0)
return parse_double_literal(ctx, l, literal);
l = d;
ctx->ptr++;
}
if(ctx->ptr < ctx->end) {
if(*ctx->ptr == '.') {
ctx->ptr++;
if(*ctx->ptr == '.' || *ctx->ptr == 'e' || *ctx->ptr == 'E')
return parse_double_literal(ctx, l, literal);
}
if(is_identifier_char(*ctx->ptr)) {
WARN("unexpected identifier char\n");

View file

@ -33,6 +33,8 @@ ok(true === true, "true === true is false");
ok(null === null, "null === null is false");
ok(undefined === undefined, "undefined === undefined is false");
ok(!(undefined === null), "!(undefined === null) is false");
ok(1E0 === 1, "1E0 === 1 is false");
ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false");
ok(1 !== 2, "1 !== 2 is false");
ok(null !== undefined, "null !== undefined is false");