This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
cpp bugfix
- To: gcc-patches at gcc dot gnu dot org
- Subject: cpp bugfix
- From: Jeffrey A Law <law at cygnus dot com>
- Date: Sun, 31 Oct 1999 01:43:16 -0600
- Reply-To: law at cygnus dot com
This is an adaptation of a patch that was sent to gcc-bugs back in July
by Nathan Kurz.
Basically if an argument to a cpp macro was omitted we could segfault in
cpp due to an out of range write in macroexpand.
Dave B. has informed me that the cpplib based cpp doesn't have this problem.
Anyway, here's the revised patch:
* cccp.c (macroexpand): Avoid out of range accesses for omitted
arguments.
Index: cccp.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cccp.c,v
retrieving revision 1.82
diff -c -3 -p -r1.82 cccp.c
*** cccp.c 1999/10/28 08:45:37 1.82
--- cccp.c 1999/10/31 07:49:12
*************** macroexpand (hp, op)
*** 8581,8587 ****
Also count number of times each arg is used. */
xbuf_len = defn->length;
for (ap = defn->pattern; ap != NULL; ap = ap->next) {
! if (ap->stringify)
xbuf_len += args[ap->argno].stringified_length_bound;
else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional)
/* Add 4 for two newline-space markers to prevent
--- 8581,8592 ----
Also count number of times each arg is used. */
xbuf_len = defn->length;
for (ap = defn->pattern; ap != NULL; ap = ap->next) {
! if (ap->stringify && args[ap->argno].stringified_length_bound == 0)
! /* macarg is not called for omitted arguments, as a result
! stringified_length_bound will be zero. We need to make
! enough space for "". */
! xbuf_len += 2;
! else if (ap->stringify)
xbuf_len += args[ap->argno].stringified_length_bound;
else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional)
/* Add 4 for two newline-space markers to prevent