This is the mail archive of the gdb-patches@sources.redhat.com 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]

Re: [PATCH RFA] utils.c: Fix xcalloc (0, 0) behavior


>>>>> "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


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