About Xalloc()/Xfree() function used in liblbxutil library.
joerg at britannica.bec.de
Tue Sep 18 05:09:13 PDT 2007
On Mon, Sep 17, 2007 at 02:01:21PM +0900, Tadashi Koike wrote:
> On this research, I understood that Xalloc()/Xfree() are same as
> malloc()/free() except that an memory allocation size be specified
> as ZERO by caller. But sorry I couldn't understand a difference of
> behavior on failure.
malloc(0) can implement one of two behaviours according to POSIX:
(a) It can return NULL.
(b) It can return a unique pointer.
It is up to the implementation which one it does. A bunch of code in X11
depends on the second behaviour and the easiest way to force that is to
turn malloc(0) into malloc(1). That is precisely what this code does.
More information about the xorg