This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +11
-23
lines changed Expand file tree Collapse file tree 5 files changed +11
-23
lines changed Original file line number Diff line number Diff line change 1
- 41419e70366962c9a878bfe673ef4df38db6f7f1
1
+ 35a061724802377a21fc6dac1ebcbb9b8d1f558a
Original file line number Diff line number Diff line change 1
1
// Some optimizations remove ZST accesses, thus masking this UB.
2
2
//@compile-flags: -Zmir-opt-level=0
3
- //@error-pattern: memory access failed: null pointer is a dangling pointer
4
3
5
4
#[ allow( deref_nullptr) ]
6
5
fn main ( ) {
7
6
// Not using the () type here, as writes of that type do not even have MIR generated.
8
7
// Also not assigning directly as that's array initialization, not assignment.
9
8
let zst_val = [ 1u8 ; 0 ] ;
10
9
unsafe { std:: ptr:: null_mut :: < [ u8 ; 0 ] > ( ) . write ( zst_val) } ;
10
+ //~^ERROR: memory access failed: null pointer is a dangling pointer
11
11
}
Original file line number Diff line number Diff line change 1
1
error: Undefined Behavior: memory access failed: null pointer is a dangling pointer (it has no provenance)
2
- --> RUSTLIB/core/src/ptr/mod .rs:LL:CC
2
+ --> $DIR/null_pointer_write_zst .rs:LL:CC
3
3
|
4
- LL | copy_nonoverlapping(&src as *const T, dst, 1) ;
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is a dangling pointer (it has no provenance)
4
+ LL | unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) } ;
5
+ | ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is a dangling pointer (it has no provenance)
6
6
|
7
7
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
8
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9
9
= note: backtrace:
10
- = note: inside `std::ptr::write::<[u8; 0]>` at RUSTLIB/core/src/ptr/mod.rs:LL:CC
11
- = note: inside `std::ptr::mut_ptr::<impl *mut [u8; 0]>::write` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
12
- note: inside `main` at $DIR/null_pointer_write_zst.rs:LL:CC
13
- --> $DIR/null_pointer_write_zst.rs:LL:CC
14
- |
15
- LL | unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) };
16
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10
+ = note: inside `main` at $DIR/null_pointer_write_zst.rs:LL:CC
17
11
18
12
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
19
13
Original file line number Diff line number Diff line change 1
- //@error-pattern: overflow computing total size of `write_bytes`
2
1
use std:: mem;
3
2
4
3
fn main ( ) {
5
4
let mut y = 0 ;
6
5
unsafe {
7
6
( & mut y as * mut i32 ) . write_bytes ( 0u8 , 1usize << ( mem:: size_of :: < usize > ( ) * 8 - 1 ) ) ;
7
+ //~^ ERROR: overflow computing total size of `write_bytes`
8
8
}
9
9
}
Original file line number Diff line number Diff line change 1
1
error: Undefined Behavior: overflow computing total size of `write_bytes`
2
- --> RUSTLIB/core/src/intrinsics .rs:LL:CC
2
+ --> $DIR/write_bytes_overflow .rs:LL:CC
3
3
|
4
- LL | write_bytes(dst, val, count)
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `write_bytes`
4
+ LL | (&mut y as *mut i32). write_bytes(0u8, 1usize << (mem::size_of::<usize>() * 8 - 1));
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `write_bytes`
6
6
|
7
7
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
8
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9
9
= note: backtrace:
10
- = note: inside `std::intrinsics::write_bytes::<i32>` at RUSTLIB/core/src/intrinsics.rs:LL:CC
11
- = note: inside `std::ptr::mut_ptr::<impl *mut i32>::write_bytes` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
12
- note: inside `main` at $DIR/write_bytes_overflow.rs:LL:CC
13
- --> $DIR/write_bytes_overflow.rs:LL:CC
14
- |
15
- LL | (&mut y as *mut i32).write_bytes(0u8, 1usize << (mem::size_of::<usize>() * 8 - 1));
16
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10
+ = note: inside `main` at $DIR/write_bytes_overflow.rs:LL:CC
17
11
18
12
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
19
13
You can’t perform that action at this time.
0 commit comments