This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: memset (0, 0, 0);


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?

Steve Thomas
SuperH (UK) Ltd.

-----Original Message-----
From: Andrew Cagney [mailto:ac131313 at redhat dot com] 
Sent: 04 April 2003 16:17
To: Rennecke,Joern
Cc: gdb at sources dot redhat dot com; newlib at sources dot redhat dot com; bug-glibc at gnu dot org; Thomas,Stephen; McGoogan,Sean
Subject: Re: memset (0, 0, 0);

> This conflicts with gdb usage of memset (0, 0, 0); in some places. 
> There are three practical questions here:
> - should gdb use this idiom?
> - should all target-specific variants of newlib's memset implement it?
> - should all target-specific variants of glibc's memset implement it?

I'm not sure why you're refering to GDB here.  GDB assumes ISO C and 
hence should never use memset in ways that violate the ISO C spec.  If 
it is, then someone gets to fix it.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]