Experimental Physics and Industrial Control System
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
<2006>
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- 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
<2006>
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024