[Bug 1730] Change malloc(0) behavior to match FreeBSD and Linux

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Thu Jan 27 08:24:10 UTC 2011


https://www.rtems.org/bugzilla/show_bug.cgi?id=1730

Peer Stritzinger <peerst at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peerst at gmail.com

--- Comment #10 from Peer Stritzinger <peerst at gmail.com> 2011-01-27 02:24:08 CST ---
(In reply to comment #5)
> (In reply to comment #4)
> b) your sentence above is wrong.
> 
> malloc(0) returning 0 is the tradional unix behavior and is much older than
> Linux and POSIX. May be it's thanks to your age and due to your lack of
> experience with other OSes but Linux, you're not aware about this.

Testing on a few Unix variants derived from the traditional Unix:

FreeBSD 8.0:  returns non NULL
OpenBSD 4.2:  returns non NULL
BSD/OS 4.3 (quite old):  returns non NULL
MacOSX (PowerPC and Intel): returns non NULL

Too lazy do dig out my old UltraSparc but I'm pretty sure Solaris also returns
non NULL

I've worked on Unix Systems since System V 2.x and can't remember anytime
malloc(0) returning NULL.
Can't poof it since I don't have access to theses systems anymore.

Googling I found an exception AIX returned NULL ...

To follow the law of least surprise RTEMS should also return  a valid pointer,
and to be real traditional Unix alike it should return a unique pointer each
time it is called.

BTW: this is one useful way to use malloc(0) pointers: to get a unique pointer
value.   This usage isn't totally portable of course but  quite portable.

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list