[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

malloc question


A trivial question, but interesting. A few comment lines from 2.2.14
include file /usr/include/stdlib.h (i think this hack is there since 2.0.x
days)... lines 349-

/* Some ill behaved applications don't expect malloc (0) returns
 * NULL. We put this hack here for them. For good behaved
 * applications, we should define __MALLOC_0_RETURNS_NULL.

/* For backward compatibilities and X11R5 */
#if (defined(MALLOC_0_RETURNS_NULL) || defined(NO_FIX_MALLOC)) \
    && !defined(__MALLOC_0_RETURNS_NULL)

/* We have changed malloc () to take malloc (0). */

If applications are ill behaved, do we need to change the kernel sources,
or is it better to fix the applications?

Normally, if i do a malloc(0), it does not return a NULL, so for the
'desired' behavior, i need to define the macro MALLOC_0_RETURNS_NULL in my
application. Isn't it odd? Or am i missing something?