shithub: scc

Download patch

ref: 99083f8dd0647e0f1a455918c7ccd0152f753895
parent: 609bb6b7743e8a37538a2701df3aaa3b652ebfb7
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Sep 7 13:07:49 EDT 2015

Fix integer constant parsing

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

--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -206,15 +206,10 @@
 {
 	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';
@@ -221,20 +216,20 @@
 		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;
 			}
@@ -243,7 +238,7 @@
 	}
 
 	if (tp->sign)
-		sym->u.i = u * factor;
+		sym->u.i = u;
 	else
 		sym->u.u = u;