This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH COMMITTED: Fix overflow check in cp-demangle.c
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 31 Mar 2008 10:42:51 -0700
- Subject: PATCH COMMITTED: Fix overflow check in cp-demangle.c
A libiberty testsuite failure pointed out that I bollixed the overflow
check in cp-demangle.c to rely on signed overflow, which as we all
know is undefined. I committed this patch to fix the problem.
Bootstrapped and tested on i686-pc-linux-gnu.
Ian
2008-03-31 Ian Lance Taylor <iant@google.com>
* cp-demangle.c (d_substitution): Correct overflow check to avoid
-fstrict-overflow optimizations.
Index: cp-demangle.c
===================================================================
--- cp-demangle.c (revision 133760)
+++ cp-demangle.c (working copy)
@@ -2681,21 +2681,24 @@ d_substitution (struct d_info *di, int p
c = d_next_char (di);
if (c == '_' || IS_DIGIT (c) || IS_UPPER (c))
{
- int id;
+ unsigned int id;
id = 0;
if (c != '_')
{
do
{
+ unsigned int new_id;
+
if (IS_DIGIT (c))
- id = id * 36 + c - '0';
+ new_id = id * 36 + c - '0';
else if (IS_UPPER (c))
- id = id * 36 + c - 'A' + 10;
+ new_id = id * 36 + c - 'A' + 10;
else
return NULL;
- if (id < 0)
+ if (new_id < id)
return NULL;
+ id = new_id;
c = d_next_char (di);
}
while (c != '_');
@@ -2703,7 +2706,7 @@ d_substitution (struct d_info *di, int p
++id;
}
- if (id >= di->next_sub)
+ if (id >= (unsigned int) di->next_sub)
return NULL;
++di->did_subs;