aboutsummaryrefslogtreecommitdiff
path: root/gcc/cexp.y
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1992-09-17 02:46:36 +0000
committerRichard Stallman <rms@gnu.org>1992-09-17 02:46:36 +0000
commit3292923dd1d498fbd3cf472164972636f8925220 (patch)
tree215e3d5edb9bc5c18ed8fc824165dfbc01affc74 /gcc/cexp.y
parent58939c25bdc16c2a1a31e08b640980119994cac6 (diff)
downloadgcc-3292923dd1d498fbd3cf472164972636f8925220.zip
gcc-3292923dd1d498fbd3cf472164972636f8925220.tar.gz
gcc-3292923dd1d498fbd3cf472164972636f8925220.tar.bz2
(parse_number): Warn about '9' in octal constants.
Commonize overflow detection for various radices. From-SVN: r2139
Diffstat (limited to 'gcc/cexp.y')
-rw-r--r--gcc/cexp.y30
1 files changed, 17 insertions, 13 deletions
diff --git a/gcc/cexp.y b/gcc/cexp.y
index 4cb3674..c0fbca5 100644
--- a/gcc/cexp.y
+++ b/gcc/cexp.y
@@ -347,6 +347,7 @@ parse_number (olen)
register int base = 10;
register int len = olen;
register int overflow = 0;
+ register int digit, largest_digit = 0;
int spec_long = 0;
for (c = 0; c < len; c++)
@@ -370,19 +371,14 @@ parse_number (olen)
for (; len > 0; len--) {
c = *p++;
- if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
-
- if (c >= '0' && c <= '9') {
- overflow |= ULONG_MAX_over_base < n;
- nd = n * base + c - '0';
- overflow |= nd < n;
- n = nd;
- } else if (base == 16 && c >= 'a' && c <= 'f') {
- overflow |= ULONG_MAX_over_base < n;
- nd = n * 16 + c - 'a' + 10;
- overflow |= nd < n;
- n = nd;
- } else {
+
+ if (c >= '0' && c <= '9')
+ digit = c - '0';
+ else if (base == 16 && c >= 'a' && c <= 'f')
+ digit = c - 'a' + 10;
+ else if (base == 16 && c >= 'A' && c <= 'F')
+ digit = c - 'A' + 10;
+ else {
/* `l' means long, and `u' means unsigned. */
while (1) {
if (c == 'l' || c == 'L')
@@ -407,6 +403,11 @@ parse_number (olen)
/* Don't look for any more digits after the suffixes. */
break;
}
+ if (largest_digit < digit)
+ largest_digit = digit;
+ nd = n * base + digit;
+ overflow |= ULONG_MAX_over_base < n | nd < n;
+ n = nd;
}
if (len != 0) {
@@ -414,6 +415,9 @@ parse_number (olen)
return ERROR;
}
+ if (base <= largest_digit)
+ warning ("integer constant contains digits beyond the radix");
+
if (overflow)
warning ("integer constant out of range");