From: "Thomas,Stephen" <stephen.thomas@superh.com>
To: "Geoff Keating" <geoffk@geoffk.org>
Cc: <gdb@sources.redhat.com>, <newlib@sources.redhat.com>,
<bug-glibc@gnu.org>, "McGoogan,Sean" <sean.mcgoogan@superh.com>
Subject: RE: memset (0, 0, 0);
Date: Tue, 08 Apr 2003 07:52:00 -0000 [thread overview]
Message-ID: <9FF3133289A7A84E81E2ED8F5E56B379604386@sh-uk-ex01.uk.w2k.superh.com> (raw)
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.
Steve Thomas
SuperH (UK) Ltd.
-----Original Message-----
From: Geoff Keating [mailto:geoffk@geoffk.org]
Sent: 07 April 2003 18:18
To: Thomas,Stephen
Cc: gdb@sources.redhat.com; newlib@sources.redhat.com; bug-glibc@gnu.org; McGoogan,Sean
Subject: Re: memset (0, 0, 0);
"Thomas,Stephen" <stephen.thomas@superh.com> writes:
> Hi,
>
> gdb appears to call memset(0,0,0) from build_regcache() in
> gdb/regcache.c. I can't really claim to understand how this works, but
> this function appears to get called 3 times during gdb initialization:
>
> static void build_regcache (void)
> {
> ...
> int sizeof_register_valid;
> ...
> sizeof_register_valid = ((NUM_REGS + NUM_PSEUDO_REGS) * sizeof (*register_valid));
> register_valid = xmalloc (sizeof_register_valid);
> memset (register_valid, 0, sizeof_register_valid);
> }
>
> On the 1st time of calling, none of the gdbarch stuff is set up, so
> NUM_REGS = NUM_PSEUDO_REGS = 0. So xmalloc gets called with size=0.
> That returns 0 as the 'address', which gets passed to memset. I guess
> this just works OK on other architectures (it does on x86 anyway).
>
> Easy enough to fix I suppose, but is that really the point?
xmalloc is never supposed to return 0, and in fact, there's code to prevent it:
if (size == 0)
size = 1;
newmem = malloc (size);
if (!newmem)
xmalloc_failed (size);
return (newmem);
xmalloc_failed finishes with
xexit (1);
so xmalloc should never return NULL.
--
- Geoffrey Keating <geoffk@geoffk.org>
next reply other threads:[~2003-04-08 7:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-08 7:52 Thomas,Stephen [this message]
2003-04-08 13:10 ` Richard Earnshaw
2003-04-08 13:26 ` Daniel Jacobowitz
2003-04-08 16:40 ` Richard Earnshaw
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=9FF3133289A7A84E81E2ED8F5E56B379604386@sh-uk-ex01.uk.w2k.superh.com \
--to=stephen.thomas@superh.com \
--cc=bug-glibc@gnu.org \
--cc=gdb@sources.redhat.com \
--cc=geoffk@geoffk.org \
--cc=newlib@sources.redhat.com \
--cc=sean.mcgoogan@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