Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Richard Earnshaw <rearnsha@arm.com>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: Richard.Earnshaw@arm.com, "Thomas,
	Stephen" <stephen.thomas@superh.com>,
	Geoff Keating <geoffk@geoffk.org>,
	gdb@sources.redhat.com, newlib@sources.redhat.com,
	bug-glibc@gnu.org, "McGoogan, Sean" <sean.mcgoogan@superh.com>,
	Andrew Cagney <ac131313@redhat.com>
Subject: Re: memset (0, 0, 0);
Date: Tue, 08 Apr 2003 16:40:00 -0000	[thread overview]
Message-ID: <200304081345.h38DjBb05553@pc960.cambridge.arm.com> (raw)
In-Reply-To: Your message of "Tue, 08 Apr 2003 09:25:59 EDT." <20030408132559.GA24135@nevyn.them.org>

> 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.
>

That's ok, but the bit about returning NULL isn't.  If we want a "malloc" 
routine that always returns NULL on zero size, we shouldn't call it 
xmalloc.

R.


  reply	other threads:[~2003-04-08 16:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-08  7:52 Thomas,Stephen
2003-04-08 13:10 ` Richard Earnshaw
2003-04-08 13:26   ` Daniel Jacobowitz
2003-04-08 16:40     ` Richard Earnshaw [this message]
2003-04-08 20:51     ` Andrew Cagney
2003-04-08 17:57 ` Richard Earnshaw
  -- strict thread matches above, loose matches on Subject: below --
2003-04-07  9:22 Thomas,Stephen
2003-04-07 13:07 ` Daniel Jacobowitz
2003-04-07 17:18 ` Geoff Keating
2003-04-04 16:12 Petr Vandrovec
2003-04-04 21:36 ` Andreas Schwab
2003-04-04 14:54 Joern Rennecke
2003-04-04 15:04 ` Daniel Jacobowitz
2003-04-04 15:16 ` Andrew Cagney
2003-04-04 15:21 ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200304081345.h38DjBb05553@pc960.cambridge.arm.com \
    --to=rearnsha@arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=ac131313@redhat.com \
    --cc=bug-glibc@gnu.org \
    --cc=drow@mvista.com \
    --cc=gdb@sources.redhat.com \
    --cc=geoffk@geoffk.org \
    --cc=newlib@sources.redhat.com \
    --cc=sean.mcgoogan@superh.com \
    --cc=stephen.thomas@superh.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox