[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: memset (0, 0, 0);
From: |
Thomas,Stephen |
Subject: |
RE: memset (0, 0, 0); |
Date: |
Tue, 8 Apr 2003 08:52:39 +0100 |
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:address@hidden
Sent: 07 April 2003 18:18
To: Thomas,Stephen
Cc: address@hidden; address@hidden; address@hidden; McGoogan,Sean
Subject: Re: memset (0, 0, 0);
"Thomas,Stephen" <address@hidden> 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 <address@hidden>
- Re: memset (0, 0, 0);, (continued)
- Re: memset (0, 0, 0);, Andrew Cagney, 2003/04/04
- Re: memset (0, 0, 0);, Andreas Schwab, 2003/04/04
- Re: memset (0, 0, 0);, Petr Vandrovec, 2003/04/04
- RE: memset (0, 0, 0);, Thomas,Stephen, 2003/04/07
- Re: memset (0, 0, 0);, Wolfram Gloger, 2003/04/07
- Re: memset (0, 0, 0);, Daniel Jacobowitz, 2003/04/07
- Re: memset (0, 0, 0);, Geoff Keating, 2003/04/07
- RE: memset (0, 0, 0);, Thomas,Stephen, 2003/04/07
- RE: memset (0, 0, 0);,
Thomas,Stephen <=