Skip to content

Update git_array allocator to obey strict aliasing rules #6814

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

Merged
merged 1 commit into from
May 13, 2024

Conversation

ethomson
Copy link
Member

Avoid sloppy aliasing in our (re-)allocation, which is undefined behavior. This has been problematic before and was helped by volatile (see b62a6a1) but that is not technically correct, and some compilers / architectures do not understand that ptr is changing due to its aliasing.

Just make git_array_alloc behave like realloc, taking a void * and returning a void *.

Avoid sloppy aliasing in our (re-)allocation, which is undefined
behavior. This has been problematic before and was helped by `volatile`
(see b62a6a1) but that is not
technically correct, and some compilers / architectures do not
understand that `ptr` is changing due to its aliasing.

Just make `git_array_alloc` behave like `realloc`, taking a `void *` and
returning a `void *`.
@ethomson ethomson merged commit f5c6b6a into main May 13, 2024
19 checks passed
@ethomson ethomson deleted the ethomson/alloc branch May 13, 2024 10:29
@ethomson ethomson added the bug label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant