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: Re: mallocMustSucceed( 0 ) non-portable
From: Michael Abbott <michael.abbott@diamond.ac.uk>
To: EPICS Tech-Talk <tech-talk@aps.anl.gov>
Date: Tue, 31 Jan 2006 19:17:49 +0000 (GMT)
Of course this means that callocMustSucceed and mallocMustSucceed can return a NULL pointer, which they currently never do.....

That's the dilemma. I thought about that but I believe requesting zero-sized memory and subsequent de-referencing the return value can be considered a programming error. Otherwise, I can't see how to avoid a memory leak.

Makes sense to me. After all, what can you legally do with char * x = malloc(0); ?

1.  Dereference by an offset with non-negative value strictly less than 0
or
2.  Pass it to free().

Both of these operations are completely safe with x==NULL and have the desired effect.

After all, there is a shortage of integers i satisfying the precondition
0 <= i && i < 0
and these are the only ones it's legal to use in the expression
*(x+i)
so it's completely safe to put x equal to NULL. (Unless the code's seriously broken already.)

Replies:
Re: mallocMustSucceed( 0 ) non-portable Andrew Johnson
References:
mallocMustSucceed( 0 ) non-portable Till Straumann
Re: mallocMustSucceed( 0 ) non-portable Eric Norum
Re: mallocMustSucceed( 0 ) non-portable Till Straumann

Navigate by Date:
Prev: Re: mallocMustSucceed( 0 ) non-portable Till Straumann
Next: Re: mallocMustSucceed( 0 ) non-portable Andrew Johnson
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: mallocMustSucceed( 0 ) non-portable Till Straumann
Next: Re: mallocMustSucceed( 0 ) non-portable Andrew Johnson
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 ·