1
0
Fork 0
mirror of https://github.com/pnx/m16vm synced 2026-06-16 03:44:55 +02:00

as/lexer/number.c: should not stop parsing if we overflow.

This commit is contained in:
Henrik Hautakoski 2019-04-03 16:45:53 +02:00
parent 502f284ebd
commit a105d5087e
No known key found for this signature in database
GPG key ID: 839F3A7EAFAEAFAA

View file

@ -55,10 +55,16 @@ int lexer_read_num_dec(FILE *fp, int neg, int *out) {
int c, val = 0, oflow = 0;
while((c = fgetc(fp)) != EOF) {
if (!lexer_is_num(c)) {
ungetc(c, fp);
break;
}
// Ignore if we have overflowed, but keep reading all numbers.
if (oflow)
continue;
val = (val * 10) + (c - '0');
// Cool trick here.
@ -67,10 +73,10 @@ int lexer_read_num_dec(FILE *fp, int neg, int *out) {
if (val > (0x80 - !neg)) {
// Truncate value.
val = 0x80 - !neg;
oflow = 1;
break;
}
// Set overflow flag.
oflow = 1;
}
}
*out = neg ? -1 * val : val;