Experimental Physics and Industrial Control System
Subject: |
Re: mallocMustSucceed( 0 ) non-portable |
From: |
Michael Abbott <[email protected]> |
To: |
EPICS Tech-Talk <[email protected]> |
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
<2006>
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- 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
<2006>
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024