This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
array bound violation in reg-stack.c
- To: egcs-patches at egcs dot cygnus dot com
- Subject: array bound violation in reg-stack.c
- From: Herman ten Brugge <Haj dot Ten dot Brugge at net dot HCC dot nl>
- Date: Fri, 16 Jul 1999 20:21:11 +0100 (WEST)
Hello,
I am currently working on using bounds-checking on gcc itself. I found
a problem in reg-stack.c. The problem is with the statement (in change_stack):
while (old->reg[old->top] != new->reg[new->top])
The value of 'old->top' and 'new->top' can be -1. This will result
in some random data being used for the compare. This problem is present
since gcc-2.7.2.1.
The patch to fix this is simple:
1999-07-13 Herman A.J. ten Brugge <Haj.Ten.Brugge@net.HCC.nl>
* reg-stack.c (change_stack) Fixed problem with negative array index.
--- reg-stack.c.org Tue Jul 13 18:21:58 1999
+++ reg-stack.c Tue Jul 13 18:47:18 1999
@@ -2647,7 +2647,7 @@ change_stack (insn, old, new, when)
other regs. But since we never swap any other reg away from
its correct slot, this algorithm will converge. */
- do
+ if (new->top != -1) do
{
/* Swap the reg at top of stack into the position it is
supposed to be in, until the correct top of stack appears. */