[PATCH v2 3/4] Say malloc (0) != NULL is now common; resection

DJ Delorie dj@redhat.com
Thu Feb 12 20:45:39 GMT 2026


Paul Eggert <eggert@cs.ucla.edu> writes:
> Not sure what is meant here by the distinction between "ported" and 
> "portable", given that there are only two possible behaviors.

One behavior leads to possible undefined behavior, though.

The wording is something I picked up long ago.  There's a difference
between "I made it work on all the platforms I tried it on" (porting)
and "I made it work by reading the spec and following it" (portable).
When you say which platforms do what, you're encouraging the former (not
that I'm opposed to giving them this information, just saying).

>> To fully avoid undefined or implementation-defined behavior, a
>> portable program should avoid this completely by never passing zero
>> to malloc.
>
> Typically, the manual shouldn't advise people to avoid all 
> implementation-defined behavior.

True, but the manual *is* giving more guidance than just "read the
spec".  If this is a problem area, describing the problem and offering
workarounds is reasonable.  One workaround here is to just not pass
zero.



More information about the Libc-alpha mailing list