Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017 
<== Date ==> <== Thread ==>

Subject: mallocMustSucceed( 0 ) non-portable
From: Till Straumann <strauman@slac.stanford.edu>
To: EPICS Tech-Talk <tech-talk@aps.anl.gov>
Cc: Sheng Peng <pengs@slac.stanford.edu>
Date: Mon, 30 Jan 2006 15:58:03 -0800
Sheng Peng recently discovered that

callocMustSucceed(0, x)

(a request for zero amount of memory)
succeeds on linux but fails on RTEMS.

(This is because according to the ISO C and IEEE 1003.1 standard
(http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html)
the allocator may either return NULL [rtems] or a unique
pointer that is acceptable to free() [linux] in the case
of a zero 'size' argument)

IMO, the EPICS implementation needs to be fixed to
give consistent behavior and the API should define
whether it is legal to request zero memory (with
the side-effect of callocMustSucceed() returning
a bogus or NULL pointer which probably is against
its purpose) or not (with the possible side-effect
of breaking code).

My suggestion would be replacing the

if (mem==0)

tests by

if (mem==0 && size != 0)

thus legalizing mallocMustSucceed(0) on all platforms.

-- Till


Replies:
Re: mallocMustSucceed( 0 ) non-portable Eric Norum

Navigate by Date:
Prev: Re: enhanced seq record Brian McAllister
Next: Re: mallocMustSucceed( 0 ) non-portable Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017 
Navigate by Thread:
Prev: Re: Ansi compiler switch Emmanuel Mayssat
Next: Re: mallocMustSucceed( 0 ) non-portable Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·