[PATCH] [analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).
anton.yartsev at gmail.com
Tue May 19 04:31:33 PDT 2015
Updated the patch. Left an old behavior for C89. Please review.
In http://reviews.llvm.org/D9040#173371, @joerg wrote:
> I don't believe we have to change anything here. The historic behavior of realloc(ptr, 0) is free(ptr) + returning NULL. That is also valid behavior under C11 where the behavior of malloc(0) is implemtation defined.
This behavior is not valid since C99. Under C99 and C11 the pure "If the size of the space requested is zero, the behavior is implementation-defined" (The C89 Draft) was restricted to "If the size of the space requested is zero, the ehavior 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." (C99 N1256 p.7.20.3; C11 N1570 p.7.22.3).
Another reason for tracking the return value from realloc(ptr, 0) is in ability to detect accesses to zero-allocated memory in realloc case which is currently missing. (http://reviews.llvm.org/D8273).
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 6989 bytes
Desc: not available
More information about the cfe-commits