-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make sure we catch UB with _ pattern in various syntactic positions
- Loading branch information
Showing
7 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
...angling_pointer_project_underscore.stderr → ...ing_pointer_project_underscore_let.stderr
This file contains 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
12 changes: 12 additions & 0 deletions
12
tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Make sure we find these even with many checks disabled. | ||
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation | ||
|
||
fn main() { | ||
let p = { | ||
let b = Box::new(42); | ||
&*b as *const i32 as *const (u8, u8, u8, u8) | ||
}; | ||
unsafe { | ||
let _: u8 = (*p).1; //~ ERROR: out-of-bounds pointer arithmetic | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.stderr
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling | ||
--> $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC | ||
| | ||
LL | let _: u8 = (*p).1; | ||
| ^^^^^^ out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
help: ALLOC was allocated here: | ||
--> $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC | ||
| | ||
LL | let b = Box::new(42); | ||
| ^^^^^^^^^^^^ | ||
help: ALLOC was deallocated here: | ||
--> $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC | ||
| | ||
LL | }; | ||
| ^ | ||
= note: BACKTRACE (of the first span): | ||
= note: inside `main` at $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
15 changes: 15 additions & 0 deletions
15
tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Make sure we find these even with many checks disabled. | ||
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation | ||
|
||
fn main() { | ||
let p = { | ||
let b = Box::new(42); | ||
&*b as *const i32 as *const (u8, u8, u8, u8) | ||
}; | ||
unsafe { | ||
match (*p).1 { | ||
//~^ ERROR: out-of-bounds pointer arithmetic | ||
_ => {} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling | ||
--> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC | ||
| | ||
LL | match (*p).1 { | ||
| ^^^^^^ out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
help: ALLOC was allocated here: | ||
--> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC | ||
| | ||
LL | let b = Box::new(42); | ||
| ^^^^^^^^^^^^ | ||
help: ALLOC was deallocated here: | ||
--> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC | ||
| | ||
LL | }; | ||
| ^ | ||
= note: BACKTRACE (of the first span): | ||
= note: inside `main` at $DIR/dangling_pointer_project_underscore_match.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
This file contains 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