This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [PATCH RFA] utils.c: Fix xcalloc (0, 0) behavior
- To: Andrew Cagney <ac131313 at cygnus dot com>
- Subject: Re: [PATCH RFA] utils.c: Fix xcalloc (0, 0) behavior
- From: jtc at redback dot com (J.T. Conklin)
- Date: 05 Mar 2001 12:38:47 -0800
- Cc: Kevin Buettner <kevinb at cygnus dot com>,gdb-patches at sources dot redhat dot com
- References: <1010303075808.ZM24102@ocotillo.lan> <3AA3F64E.9F0302A5@cygnus.com>
- Reply-To: jtc at redback dot com
>>>>> "Andrew" == Andrew Cagney <ac131313@cygnus.com> 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