Skip to content

[Demangling] Avoid UB call to memcpy(). #68187

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
Aug 30, 2023

Conversation

al45tair
Copy link
Contributor

When appending to an empty CharVector, we were inadvertently relying on memcpy(NewObjects, NULL, 0) being a no-op, whereas in practice the C standard says it's UB because of the NULL pointer.

Fix by only calling memcpy() if we actually have bytes to copy.

rdar://114447171

When appending to an empty `CharVector`, we were inadvertently relying
on `memcpy(NewObjects, NULL, 0)` being a no-op, whereas in practice
the C standard says it's UB because of the `NULL` pointer.

Fix by only calling `memcpy()` if we actually have bytes to copy.

rdar://114447171
@al45tair al45tair requested a review from mikeash August 29, 2023 16:20
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's entertaining.

@al45tair al45tair merged commit 52c32c5 into swiftlang:main Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants