malloc (0)

Petri Helenius pete at he.iki.fi
Sat Feb 21 11:35:19 PST 2004


Maxime Henrion wrote:

>In C99, malloc(0) is legal.  From n869.txt :
>
>%%
>If the size of the space requested is zero, the behavior is
>implementation-defined: either a  null pointer  is returned,
>or the behavior is as if the size were some nonzero value,
>except that the returned  pointer  shall not  be  used  to
>access an object.
>%%
>
>As a side note, free(NULL) is also legal in C99.
>
>  
>
I´m actually aware how the standard approaches the issue, but my 
question was more directed to how FreeBSD "code style" approaches the 
issue.
Personally I feel that debugging would be easier if mallocing 0 bytes 
and free and realloc of NULL pointers would not spread.

Pete



More information about the freebsd-net mailing list