This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: memset (0, 0, 0);
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: Richard dot Earnshaw at arm dot com
- Cc: "Thomas,Stephen" <stephen dot thomas at superh dot com>,Geoff Keating <geoffk at geoffk dot org>, gdb at sources dot redhat dot com,newlib at sources dot redhat dot com, bug-glibc at gnu dot org,"McGoogan, Sean" <sean dot mcgoogan at superh dot com>,Andrew Cagney <ac131313 at redhat dot com>
- Date: Tue, 8 Apr 2003 09:25:59 -0400
- Subject: Re: memset (0, 0, 0);
- References: <9FF3133289A7A84E81E2ED8F5E56B379604386@sh-uk-ex01.uk.w2k.superh.com> <200304080929.h389TuE03840@pc960.cambridge.arm.com>
On Tue, Apr 08, 2003 at 10:29:55AM +0100, Richard Earnshaw wrote:
> >
> > 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?
The ones in libiberty call exit; the ones in gdb call error() and
unwind cleanups. GDB prefers not to abort when it runs out of memory,
esp. if it can just abort the current operation and reclaim memory.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer