From: Geoff Keating <geoffk@geoffk.org>
To: "Thomas,Stephen" <stephen.thomas@superh.com>
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: Mon, 07 Apr 2003 17:18:00 -0000 [thread overview]
Message-ID: <jmy92mgrbh.fsf@desire.geoffk.org> (raw)
In-Reply-To: <9FF3133289A7A84E81E2ED8F5E56B379604384@sh-uk-ex01.uk.w2k.superh.com>
"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 prev parent reply other threads:[~2003-04-07 17:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-07 9:22 Thomas,Stephen
2003-04-07 13:07 ` Daniel Jacobowitz
2003-04-07 17:18 ` Geoff Keating [this message]
-- strict thread matches above, loose matches on Subject: below --
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
2003-04-08 20:51 ` Andrew Cagney
2003-04-08 17:57 ` Richard Earnshaw
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=jmy92mgrbh.fsf@desire.geoffk.org \
--to=geoffk@geoffk.org \
--cc=bug-glibc@gnu.org \
--cc=gdb@sources.redhat.com \
--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