Skip to content

Update git_array allocator to obey strict aliasing rules#6814

Merged
ethomson merged 1 commit into
mainfrom
ethomson/alloc
May 13, 2024
Merged

Update git_array allocator to obey strict aliasing rules#6814
ethomson merged 1 commit into
mainfrom
ethomson/alloc

Conversation

@ethomson
Copy link
Copy Markdown
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 *`.
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