jvoisin / fortify-headers

Standalone portable header-based implementation of FORTIFY_SOURCE=3
BSD Zero Clause License
19 stars 3 forks source link

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

Open jvoisin opened 11 months ago

jvoisin commented 11 months ago

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 11 months ago

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

jvoisin commented 10 months ago

It needs to do something for C23 I think.