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

David Taylor taylor@cygnus.com
Mon Mar 5 07:52:00 GMT 2001


    Date: Sat, 3 Mar 2001 00:58:08 -0700
    From: Kevin Buettner <kevinb@cygnus.com>

    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.

    Unfortunately, our implementation of xcalloc() and xmrealloc() choose
    to treat the NULL return value as an error condition and call nomem()
    as a result.

    The patch below corrects this oversight.

    Okay to apply?

	    * utils.c (xmrealloc): Don't call nomem() when return value
	    is NULL _and_ request size is 0.
	    (xcalloc): Likewise.

Yes.  Approved.

    Index: utils.c
    ===================================================================
    RCS file: /cvs/src/src/gdb/utils.c,v
    retrieving revision 1.31
    diff -u -p -r1.31 utils.c
    --- utils.c     2001/02/25 04:45:11     1.31
    +++ utils.c     2001/03/03 07:47:54
    @@ -1050,7 +1050,7 @@ xmrealloc (PTR md, PTR ptr, long size)
	 {
	   val = mmalloc (md, size);
	 }
    -  if (val == NULL)
    +  if (val == NULL && size != 0)
	 {
	   nomem (size);
	 }
    @@ -1072,7 +1072,7 @@ PTR
     xcalloc (size_t number, size_t size)
     {
       void *mem = mcalloc (NULL, number, size);
    -  if (mem == NULL)
    +  if (mem == NULL && number != 0 && size != 0)
	 nomem (number * size);
       return mem;
     }



More information about the Gdb-patches mailing list