Until C23, if new_size is zero, the behavior is implementation defined (null pointer may be returned (in which case the old memory block may or may not be freed), or some non-null pointer may be returned that may not be used to access storage). Such usage is deprecated (via C DR 400).(since C17)
Since C23, if new_size is zero, the behavior is undefined.
The conservative thing to do is to only catch new_size=0 when compiling with C23, but I'm wondering if we should always return NULL otherwise.
Until C23, if
new_size
is zero, the behavior is implementation defined (null pointer may be returned (in which case the old memory block may or may not be freed), or some non-null pointer may be returned that may not be used to access storage). Such usage is deprecated (via C DR 400).(since C17)Since C23, if
new_size
is zero, the behavior is undefined.The conservative thing to do is to only catch
new_size=0
when compiling with C23, but I'm wondering if we should always returnNULL
otherwise.