lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


From: Björn De Meyer [mailto:bjorn.demeyer@pandora.be]

>So, the conclusion is that the Linux manpages for realloc() 
>are faulty. The ANSI C standard which Edgar quoted is clear 
>enough. Using realloc(x,0) causes undefined behaviour. 

No - realloc(x, 0) is well defined.  It's equivalent to free(x):

"when  size is zero and ptr is not a null pointer, the object
it pointed to has been freed."

and there's a similar passage in the Rationale:

"If the first argument is not null, and the second argument is 0,
then the call frees the memory pointed to by the first argument,
and a null argument may be returned"

The only undefined behavious is realloc(null, 0).

But still, that doesn't stop buggy (or conforming to an earlier
standard) libcs existing, and Lua still has to work with them.
So it still should be replaced with free().

John
-Virus scanned and cleared ok