From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17050 invoked by alias); 7 Apr 2003 17:18:39 -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 17035 invoked from network); 7 Apr 2003 17:18:39 -0000 Received: from unknown (HELO desire.geoffk.org) (12.235.88.42) by sources.redhat.com with SMTP; 7 Apr 2003 17:18:39 -0000 Received: (from geoffk@localhost) by desire.geoffk.org (8.11.6/8.11.6) id h37HHdP17245; Mon, 7 Apr 2003 10:17:39 -0700 X-Authentication-Warning: desire.geoffk.org: geoffk set sender to geoffk@geoffk.org using -f To: "Thomas,Stephen" Cc: , , , "McGoogan,Sean" Subject: Re: memset (0, 0, 0); References: <9FF3133289A7A84E81E2ED8F5E56B379604384@sh-uk-ex01.uk.w2k.superh.com> From: Geoff Keating Date: Mon, 07 Apr 2003 17:18:00 -0000 In-Reply-To: <9FF3133289A7A84E81E2ED8F5E56B379604384@sh-uk-ex01.uk.w2k.superh.com> Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-04/txt/msg00064.txt.bz2 "Thomas,Stephen" 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