jvoisin/fortify-headers

Decide what we want to do for realloc(a, 0)

Opened this issue · 2 comments

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.

q66 commented

why does fortify-headers need to do anything here? it's up to the implementation to decide what should happen

It needs to do something for C23 I think.