-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from jfrimmel/fix-panic
Accept more issue types (such as invalid reads)
- Loading branch information
Showing
9 changed files
with
176 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
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
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 @@ | ||
target/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
[package] | ||
name = "corpus" | ||
version = "0.0.0" | ||
publish = false | ||
|
||
[[bin]] | ||
name = "issue-74" | ||
path = "issue-74.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,69 @@ | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
fn ex1() { | ||
let mut num = 6; | ||
|
||
let r1 = &num as *const i32; | ||
let r2 = &mut num as *mut i32; | ||
unsafe { | ||
println!("r1: {:?}", *r1); | ||
println!("r2: {:?}", *r2); | ||
} | ||
} | ||
fn ex2() { | ||
let address = 0x_012345_usize; | ||
let r = address as *const i32; | ||
unsafe { | ||
// error? | ||
println!("r={}", *r); | ||
} | ||
} | ||
fn ex3() { | ||
unsafe fn dangerous() {} | ||
unsafe { dangerous() } | ||
} | ||
fn ex4() { | ||
let mut v: Vec<_> = (1..7).collect(); | ||
let r = &mut v[..]; | ||
let (a, b) | ||
= split_at_mut(r, 4); | ||
|
||
println!("a={a:?} (should be [1, 2, 3, 4]"); | ||
drop(a); | ||
println!("b={b:?} (should be [5, 6])"); | ||
// assert_eq!(a, &mut[1, 2, 3, 4]); | ||
// assert_eq!(b, &mut[5, 6]); | ||
} | ||
fn split_at_mut(values: &mut[i32], ind: usize) | ||
-> (&mut[i32], &mut[i32]) { | ||
|
||
use std::slice::from_raw_parts_mut as part; | ||
|
||
assert!(ind < values.len()); | ||
|
||
let len = values.len(); | ||
let ptr = values.as_mut_ptr(); | ||
|
||
unsafe {( | ||
part(ptr, ind), | ||
// bug! | ||
part(ptr.add(ind + 1), len - ind) | ||
)} | ||
} | ||
extern "C" { | ||
fn abs(input: i32) -> i32; | ||
} | ||
static mut COUNTER: u32 = 0; | ||
fn add_to_cound(inc: u32) { | ||
unsafe { COUNTER += inc } | ||
} | ||
fn ex5() { | ||
add_to_cound(3); | ||
unsafe { println!("{}", COUNTER) } | ||
} | ||
fn main() { | ||
ex4() | ||
} | ||
unsafe trait Doo {} | ||
unsafe impl Doo for i32 {} |
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,23 @@ | ||
use assert_cmd::Command; | ||
|
||
fn cargo_valgrind() -> Command { | ||
let mut cmd = Command::cargo_bin("cargo-valgrind").unwrap(); | ||
cmd.arg("valgrind"); | ||
cmd | ||
} | ||
|
||
const TARGET_CRATE: &[&str] = &["--manifest-path", "tests/corpus/Cargo.toml"]; | ||
|
||
#[test] | ||
fn issue74() { | ||
cargo_valgrind() | ||
.arg("run") | ||
.args(TARGET_CRATE) | ||
.arg("--bin=issue-74") | ||
.assert() | ||
.failure() | ||
.stderr(predicates::str::contains("Error Invalid read of size 4")) | ||
.stderr(predicates::str::contains( | ||
"Summary Leaked 0 B total (1 other errors)", | ||
)); | ||
} |