PATCH : free(NULL) in cpphash.c

Michael Meissner meissner@cygnus.com
Tue Apr 4 22:04:00 GMT 2000


On Tue, Apr 04, 2000 at 09:54:20PM -0700, Zack Weinberg wrote:
> On Wed, Apr 05, 2000 at 06:49:15AM +0200, Philippe De Muyter wrote:
> > In cpphash.c/_cpp_free_definition, one frees d->argnames iff d->nargs >= 0.
> > But in collect_expansion, nargs is copied from argc which itself is a copy
> > of arglist->argc while argnames is copied from arglist->namebuf.  And in
> > collect_formal_parameters, argc can set to 0 while namebuf is set to NULL.
> > 
> > In short, argnames can be NULL even when nargs >= 0.
> 
> free(NULL) is defined to be a no-op, so the code should be safe as is.
> Can you provide a test case which does not work with the existing
> code?

You can't count on that behavior.  Suns running SunOS trap if given free(NULL)
if memory serves.  Please add appropriate checks.

> I will apply the patch anyway, because it's clearer that way; thank
> you for pointing out the inconsistency.
> 
> zw

-- 
Michael Meissner, Cygnus Solutions, a Red Hat company.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


More information about the Gcc-patches mailing list