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

as/lexer/number.c: cleaning up lexer_read_num_dec() abit, skipping goto.

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

View file

@ -52,7 +52,7 @@ overflow:
int lexer_read_num_dec(FILE *fp, int neg, int *out) {
int c, val = 0;
int c, val = 0, oflow = 0;
while((c = fgetc(fp)) != EOF) {
if (!lexer_is_num(c)) {
@ -64,14 +64,15 @@ int lexer_read_num_dec(FILE *fp, int neg, int *out) {
// Cool trick here.
// because the range is -128 (0x80) to +127 (0x7F)
// We can do 0x80 - 1 if it is NOT a negative number.
if (val > (0x80 - !neg))
goto overflow;
if (val > (0x80 - !neg)) {
// Truncate value.
val = 0x80 - !neg;
oflow = 1;
break;
}
}
*out = neg ? -1 * val : val;
return 0;
overflow:
*out = neg ? -1 * 0x80 : 0x7F;
return -1;
return -oflow;
}