-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
The following sample correctly fails to build on stable channel, but erroneously passes on beta and nightly.
It's worth noting that with NLL turned on it also correctly fails to build.
enum Inner {
Stack {
data: [u8;23]
},
Heap {
capacity: usize,
data: *mut u8
}
}
struct SmallString {
len: usize,
inner: Inner
}
impl SmallString {
fn push_str(&mut self, item: &str) {
match (&mut self.inner, self.len + item.len()) {
(Inner::Heap { capacity, ref data }, x) => {
if x > *capacity {
self.grow();
// data is now null pointer
}
unsafe {
::std::ptr::copy_nonoverlapping(item.as_ptr(), data.add(self.len), item.len())
}
},
_ => ()
}
}
fn grow(&mut self){
// Invalidate borrowed Heap.data
self.inner = Inner::Stack { data: [0;23] };
}
}
scottmcm, jD91mZM2 and mmstick
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.