Skip to content

Commit 300e138

Browse files
committed
Remove CString drop test.
The test relies on the undefined behavior, and so may fail in some circumstances. This can be worked around by stubbing a memory allocator in the test, but it is a bit of work, and LLVM could still theoretically eliminate the write of the zero byte in release mode (which is intended). So let's just remove the test and mark the function as inline. It shouldn't be optimized away when inlined into the debug build of user's code.
1 parent b786976 commit 300e138

File tree

2 files changed

+3
-50
lines changed

2 files changed

+3
-50
lines changed

src/libstd/ffi/c_str.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,11 @@ impl CString {
314314
}
315315

316316
// Turns this `CString` into an empty string to prevent
317-
// memory unsafe code from working by accident.
317+
// memory unsafe code from working by accident. Inline
318+
// to prevent LLVM from optimizing it away in debug builds.
318319
#[stable(feature = "cstring_drop", since = "1.13.0")]
319320
impl Drop for CString {
321+
#[inline]
320322
fn drop(&mut self) {
321323
unsafe { *self.inner.get_unchecked_mut(0) = 0; }
322324
}

src/test/run-pass/cstring-drop.rs

-49
This file was deleted.

0 commit comments

Comments
 (0)