[hackers] [scc] Fix readint() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 7 Sep 2015 23:44:56 +0200 (CEST)

commit 5a05103353eb4b3c5fa387cfb287b781fd06359b
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Sep 7 23:20:17 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Sep 7 23:20:17 2015 +0200

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

diff --git a/cc1/lex.c b/cc1/lex.c
index a0750c4..06364ca 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -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) {
_AT_@ -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)
Received on Mon Sep 07 2015 - 23:44:56 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 07 2015 - 23:48:16 CEST