From mboxrd@z Thu Jan 1 00:00:00 1970 From: jtc@redback.com (J.T. Conklin) To: Andrew Cagney Cc: Kevin Buettner , gdb-patches@sources.redhat.com Subject: Re: [PATCH RFA] utils.c: Fix xcalloc (0, 0) behavior Date: Mon, 05 Mar 2001 12:39:00 -0000 Message-id: <5m1yscrlwo.fsf@jtc.redback.com> References: <1010303075808.ZM24102@ocotillo.lan> <3AA3F64E.9F0302A5@cygnus.com> X-SW-Source: 2001-03/msg00080.html >>>>> "Andrew" == Andrew Cagney writes: Andrew> Kevin Buettner wrote: >> >> According to section 16.1 in Harbison & Steele, it is permissible for >> calloc(0,0) to return either NULL or an implementation defined unique >> pointer. I've come across an implementation of calloc() which chooses >> to return NULL. Andrew> Does anyone know what the ISO-C standard has to say? I think it would Andrew> be helpful if xcalloc() not only followed ISO-C but also did it in a Andrew> consistent way across platforms. C9X, 7.20.3: If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object. To make it consistant between implementations, we'd want to check for zero size in xmalloc, xrealloc, and xcalloc() and return NULL before the underlying functions are called. --jtc -- J.T. Conklin RedBack Networks