[hackers] [scc] Fix integer constant parsing || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 7 Sep 2015 17:18:47 +0200 (CEST)

commit 99083f8dd0647e0f1a455918c7ccd0152f753895
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Sep 7 17:07:49 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Sep 7 17:07:49 2015 +0200

    Fix integer constant parsing
    
    Sign cannot be part of the constant, it is an unary operator.

diff --git a/cc1/lex.c b/cc1/lex.c
index 0a4132a..1344c32 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -206,35 +206,30 @@ readint(char *s, int base, Symbol *sym)
 {
         Type *tp = sym->type;
         struct limits *lim = getlimits(tp);
- TUINT u, val, max, factor = 1;
+ TUINT u, val, max;
         int c;
 
         max = (tp->sign) ? lim->max.u : lim->max.i;
- switch (*s++) {
- case '-': factor = -1; break;
- default: --s;
- case '+': factor = 1; break;
- }
 
         for (u = 0; isxdigit(c = *s++); u = u * base + val) {
                 val = (c <= '9') ? c - '0' : 10 + c - 'A';
                 if (u <= max/base + val)
                         continue;
                 if (tp->sign) {
- if (tp == inttype)
+ if (tp == inttype) {
                                 tp = longtype;
- else if (tp == longtype)
+ } else if (tp == longtype) {
                                 tp == llongtype;
- else {
+ } else {
                                 errorp("overflow in integer constant");
                                 break;
                         }
                 } else {
- if (tp == uinttype)
+ if (tp == uinttype) {
                                 tp = ulongtype;
- else if (tp == ulongtype)
+ } else if (tp == ulongtype) {
                                 tp == ullongtype;
- else {
+ } else {
                                 errorp("overflow in integer constant");
                                 break;
                         }
_AT_@ -243,7 +238,7 @@ readint(char *s, int base, Symbol *sym)
         }
 
         if (tp->sign)
- sym->u.i = u * factor;
+ sym->u.i = u;
         else
                 sym->u.u = u;
 
Received on Mon Sep 07 2015 - 17:18:47 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 07 2015 - 17:24:11 CEST