scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 5a05103353eb4b3c5fa387cfb287b781fd06359b
parent 0f0cbf03f9dcbee4dba981e29a7ea43d96e648e7
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  7 Sep 2015 23:20:17 +0200

Fix readint()

There were several errors in the overflow condition and
the maximum of the type was not updated in type upgrade.

Diffstat:
Mcc1/lex.c | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -211,9 +211,9 @@ readint(char *s, int base, Symbol *sym) max = (tp->sign) ? lim->max.u : lim->max.i; - for (u = 0; isxdigit(c = *s++); u = u * base + val) { + for (u = 0; isxdigit(c = *s++); u = u*base + val) { val = (c <= '9') ? c - '0' : 10 + c - 'A'; - if (u <= max/base + val) + if (u <= max/base && u*base <= max - val) continue; if (tp->sign) { if (tp == inttype) { @@ -235,6 +235,7 @@ readint(char *s, int base, Symbol *sym) } } sym->type = tp; + max = (tp->sign) ? lim->max.u : lim->max.i; } if (tp->sign)