From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 863 invoked by alias); 8 Apr 2003 07:52:35 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 843 invoked from network); 8 Apr 2003 07:52:33 -0000 Received: from unknown (HELO ns2.uk.superh.com) (193.128.105.170) by sources.redhat.com with SMTP; 8 Apr 2003 07:52:33 -0000 Received: from sh-uk-ex01.uk.w2k.superh.com (sh-uk-ex01 [192.168.16.17]) by ns2.uk.superh.com (8.11.6+Sun/8.11.6) with ESMTP id h387WQx20402; Tue, 8 Apr 2003 08:32:26 +0100 (BST) content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3 Subject: RE: memset (0, 0, 0); Date: Tue, 08 Apr 2003 07:52:00 -0000 Message-ID: <9FF3133289A7A84E81E2ED8F5E56B379604386@sh-uk-ex01.uk.w2k.superh.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: From: "Thomas,Stephen" To: "Geoff Keating" Cc: , , , "McGoogan,Sean" X-SW-Source: 2003-04/txt/msg00067.txt.bz2 Hi Geoff, Which xmalloc are you referring to? The xmalloc in this case is a gdb inter= nal 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 =3D=3D 0) { val =3D NULL; } else { val =3D mmalloc (md, size); if (val =3D=3D NULL) nomem (size); } return (val); } So size=3D0 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]=20 Sent: 07 April 2003 18:18 To: Thomas,Stephen Cc: gdb@sources.redhat.com; newlib@sources.redhat.com; bug-glibc@gnu.org; M= cGoogan,Sean Subject: Re: memset (0, 0, 0); "Thomas,Stephen" writes: > Hi, >=20 > gdb appears to call memset(0,0,0) from build_regcache() in=20 > gdb/regcache.c. I can't really claim to understand how this works, but=20 > this function appears to get called 3 times during gdb initialization: >=20 > static void build_regcache (void) > { > ... > int sizeof_register_valid; > ... > sizeof_register_valid =3D ((NUM_REGS + NUM_PSEUDO_REGS) * sizeof (*re= gister_valid)); > register_valid =3D xmalloc (sizeof_register_valid); > memset (register_valid, 0, sizeof_register_valid); > } >=20 > On the 1st time of calling, none of the gdbarch stuff is set up, so=20 > NUM_REGS =3D NUM_PSEUDO_REGS =3D 0. So xmalloc gets called with size=3D0.= =20 > That returns 0 as the 'address', which gets passed to memset. I guess=20 > this just works OK on other architectures (it does on x86 anyway). >=20 > 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 =3D=3D 0) size =3D 1; newmem =3D malloc (size); if (!newmem) xmalloc_failed (size); return (newmem); xmalloc_failed finishes with xexit (1); so xmalloc should never return NULL. --=20 - Geoffrey Keating