summaryrefslogtreecommitdiffstats
path: root/gcc/cexp.y
diff options
context:
space:
mode:
authorrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>1992-09-17 21:11:17 +0000
committerrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>1992-09-17 21:11:17 +0000
commitd27efafbf18c541ac8da26aa8d1cb77769fa1df8 (patch)
tree67c9ce01a89e18445ea9e479980e6fbe8213a638 /gcc/cexp.y
parent34a5ca59fb3a0e5d8128ed7f937e855813799041 (diff)
downloadppe42-gcc-d27efafbf18c541ac8da26aa8d1cb77769fa1df8.tar.gz
ppe42-gcc-d27efafbf18c541ac8da26aa8d1cb77769fa1df8.zip
(parse_escape): Diagnose '\x' with no digits.
Diagnose integer overflow when parsing \x escapes. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@2147 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cexp.y')
-rw-r--r--gcc/cexp.y15
1 files changed, 10 insertions, 5 deletions
diff --git a/gcc/cexp.y b/gcc/cexp.y
index c0fbca561b3..9530a37c3ce 100644
--- a/gcc/cexp.y
+++ b/gcc/cexp.y
@@ -803,23 +803,28 @@ parse_escape (string_ptr)
}
case 'x':
{
- register int i = 0;
+ register unsigned i = 0, overflow = 0, digits_found = 0, digit;
for (;;)
{
c = *(*string_ptr)++;
if (c >= '0' && c <= '9')
- i = (i << 4) + c - '0';
+ digit = c - '0';
else if (c >= 'a' && c <= 'f')
- i = (i << 4) + c - 'a' + 10;
+ digit = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
- i = (i << 4) + c - 'A' + 10;
+ digit = c - 'A' + 10;
else
{
(*string_ptr)--;
break;
}
+ overflow |= i ^ (i << 4 >> 4);
+ i = (i << 4) + digit;
+ digits_found = 1;
}
- if ((i & ~((1 << BITS_PER_UNIT) - 1)) != 0)
+ if (!digits_found)
+ yyerror ("\\x used with no following hex digits");
+ if (overflow | (i & ~((1 << BITS_PER_UNIT) - 1)))
{
i &= (1 << BITS_PER_UNIT) - 1;
warning ("hex character constant does not fit in a byte");
OpenPOWER on IntegriCloud