This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix PR 11679: Varray out-of-bounds ICE in--enable-checking mode
- From: Raja R Harinath <harinath at cs dot umn dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 20 Aug 2003 12:37:32 -0500
- Subject: [C++ PATCH] Fix PR 11679: Varray out-of-bounds ICE in--enable-checking mode
- Cancel-lock: sha1:vWkt4tB6REdAFeWzB8oBsNQVZdY=
- Organization: Dept. of Computer Science, Univ. of Minnesota
Hi,
This is an improved version of the patches in
http://gcc.gnu.org/ml/gcc-patches/2003-07/msg02566.html
http://gcc.gnu.org/ml/gcc-patches/2003-07/msg02568.html
It appears that VARRAYs don't support indexing one-past-the-end,
which is reasonable, except when you just want a pointer past the
end. The fix is slightly unclean since accessing index '0' of an
empty VARRAY is also an error.
- Hari
--
Raja R Harinath ------------------------------ harinath@cs.umn.edu
Index: gcc/cp/ChangeLog
from Raja R Harinath <harinath@acm.org>
PR c++/11679
* decl2.c (finish_file): Avoid indexing past the end of a VARRAY.
Index: gcc/cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.662
diff -u -p -u -r1.662 decl2.c
--- gcc/cp/decl2.c 20 Aug 2003 07:06:41 -0000 1.662
+++ gcc/cp/decl2.c 20 Aug 2003 17:13:27 -0000
@@ -2727,12 +2727,12 @@ finish_file ()
them to the beginning of the array, then get rid of the
leftovers. */
n_new = VARRAY_ACTIVE_SIZE (unemitted_tinfo_decls) - n_old;
- memmove (&VARRAY_TREE (unemitted_tinfo_decls, 0),
- &VARRAY_TREE (unemitted_tinfo_decls, n_old),
- n_new * sizeof (tree));
- memset (&VARRAY_TREE (unemitted_tinfo_decls, n_new),
- 0,
- n_old * sizeof (tree));
+ if (n_old)
+ {
+ tree *varray_begin = &VARRAY_TREE (unemitted_tinfo_decls, 0);
+ memmove (varray_begin, varray_begin + n_old, n_new * sizeof (tree));
+ memset (varray_begin + n_new, 0, n_old * sizeof (tree));
+ }
VARRAY_ACTIVE_SIZE (unemitted_tinfo_decls) = n_new;
/* The list of objects with static storage duration is built up