Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jvoisin opened this issue Dec 16, 2023 · 2 comments
Open

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

jvoisin opened this issue Dec 16, 2023 · 2 comments

Comments

@jvoisin
Copy link
Owner

jvoisin commented Dec 16, 2023

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
Copy link
Collaborator

q66 commented Dec 20, 2023

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

@jvoisin
Copy link
Owner Author

jvoisin commented Dec 28, 2023

It needs to do something for C23 I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants