Skip to content
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

Get rid of some UB #412

Closed
wants to merge 1 commit into from

Conversation

umanwizard
Copy link
Contributor

Constructing a reference to an invalid value is always UB, according to this documentation.

In addition, even just the set_len call can cause UB if we panic immediately after it (and thus try to drop the invalid value).

The new implementation is taken from Vec::push. Hat tip to @guswynn , @doy-materialize, and @petrosagg for talking me through why it was indeed UB, and the latter for also suggesting the Vec::push implementation.

@frankmcsherry
Copy link
Member

Discussed offline, but we merged instead #413 which simply removes the unsafe at the cost of some bounds checks. But I do appreciate the attention to sloppiness on my part, and ways to correct it!

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