Skip to content

Commit a76c85a

Browse files
committed
make sure we catch UB in match place even with _ pattern
1 parent 7577b35 commit a76c85a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Make sure we find these even with many checks disabled.
2+
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3+
4+
fn main() {
5+
let p = {
6+
let b = Box::new(42);
7+
&*b as *const i32 as *const (u8, u8, u8, u8)
8+
};
9+
unsafe {
10+
match (*p).1 {
11+
//~^ ERROR: out-of-bounds pointer arithmetic
12+
_ => {}
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling
2+
--> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC
3+
|
4+
LL | match (*p).1 {
5+
| ^^^^^^ out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
help: ALLOC was allocated here:
10+
--> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC
11+
|
12+
LL | let b = Box::new(42);
13+
| ^^^^^^^^^^^^
14+
help: ALLOC was deallocated here:
15+
--> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC
16+
|
17+
LL | };
18+
| ^
19+
= note: BACKTRACE (of the first span):
20+
= note: inside `main` at $DIR/dangling_pointer_project_underscore_match.rs:LL:CC
21+
22+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
23+
24+
error: aborting due to previous error
25+

0 commit comments

Comments
 (0)