Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: and query for malloc(0).

On Saturday 2007-04-28 07:36 +1000, Peter Stephenson output:
:Playing with POSIX regexes, I found some errors coming from zsh's memory
:allocation with debugging on.  These turned out to resolve to some
:malloc()s and free()s for zero length and the following oddity in
:    /* some systems want malloc to return the highest valid address plus one
:       if it is called with an argument of zero */
:    if (!size)
:	return (MALLOC_RET_T) m_high;

This appeared in zsh 2.5.  I don't know the origin.

It's a bit weird as different systems will do conflicting things with it.

NetBSD returns NULL

An older Solaris man page says for malloc(): "a unique pointer to the arena
 is returned"; and for bsdmalloc(): "a non-NULL pointer. ... These pointers
 should not be dereferenced."

SUS says: "If size is 0, either a null pointer or a unique pointer that can
 be successfully passed to free() shall be returned."

Given the above, I guess the patch is a reasonable fix.

We are not actually calling malloc(0) in-house, are we?


Messages sorted by: Reverse Date, Date, Thread, Author