added a strings.rs regression test case for potential future UB#1824
Merged
bors merged 1 commit intorust-lang:masterfrom Jun 3, 2021
Merged
added a strings.rs regression test case for potential future UB#1824bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Member
|
Looking good, thanks. :-) |
Contributor
|
📌 Commit 386863a has been approved by |
Contributor
Contributor
|
☀️ Test successful - checks-actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a regression test for the aliasing rules of a
Unique<T>pointer.At the time of writing this test case, Miri does not treat
Unique<T>pointers as a special case, these are treated like any other raw pointer.
However, there are existing Github issues which may lead to
Unique<T>becoming a special case through asserting unique ownership over the pointee:
- rust-lang/unsafe-code-guidelines#258
- rust-lang/unsafe-code-guidelines#262
In the new test case, the calls to
String::removeandString::insert[_str]followcode paths that would trigger undefined behavior in case
Unique<T>would ever assert semantic ownership over the pointee. Internally,
these methods call
self.vec.as_ptr()andself.vec.as_mut_ptr()onthe vector of bytes that are backing the
String. ThatVec<u8>holds aUnique<u8>internally. The second call toVec::as_mut_ptr(&mut self)would then invalidate the pointers derived from
Vec::as_ptr(&self).Note that as long as
Unique<T>is treated like any other raw pointer,this test case should pass. It is merely here as a canary test for
potential future undefined behavior.