This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: memset (0, 0, 0);
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: "Thomas,Stephen" <stephen dot thomas at superh dot com>
- Cc: "Geoff Keating" <geoffk at geoffk dot org>, gdb at sources dot redhat dot com, "McGoogan, Sean" <sean dot mcgoogan at superh dot com>, Richard dot Earnshaw at arm dot com, Andrew Cagney <ac131313 at redhat dot com>
- Date: Tue, 08 Apr 2003 14:17:41 +0100
- Subject: Re: memset (0, 0, 0);
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
[I've trimmed the cc list, cos the message was bouncing at
sources.redhat.com]
>
> Hi Geoff,
>
> Which xmalloc are you referring to? The xmalloc in this case is a gdb internal function, defined in gdb/utils.c:
>
> PTR xmalloc (size_t size)
> {
> return xmmalloc (NULL, size);
> }
>
> And xmmalloc is:
>
> void * xmmalloc (void *md, size_t size)
> {
> void *val;
>
> if (size == 0)
> {
> val = NULL;
> }
> else
> {
> val = mmalloc (md, size);
> if (val == NULL)
> nomem (size);
> }
> return (val);
> }
>
> So size=0 does indeed return NULL. Also, I have single stepped this code to verify that this is actually what happens.
It looks as though that implementation of xmalloc doesn't match the
general specification of xmalloc, which is that xmalloc must *never*
return NULL (see libiberty/xmalloc.c for the specification).
I'm not sure why gdb is trying to provide its own implementation of these
functions and not use those in libiberty. Andrew?
R.