-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lint casting integers to dangling pointers
- Loading branch information
1 parent
cf58e1c
commit ec69a57
Showing
3 changed files
with
56 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(dangling_ptr)] | ||
|
||
#[allow(unused_variables)] | ||
fn main() { | ||
let x = 1 as *const usize; | ||
let y = 1 as *mut f64; | ||
|
||
let z = 1; | ||
let z = z as *const usize; // this is currently not caught | ||
} |
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,14 @@ | ||
error: `1 as *const _` detected. Consider using `ptr::dangling()` | ||
--> $DIR/dangling_ptr.rs:5:13 | ||
| | ||
5 | let x = 1 as *const usize; | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D dangling-ptr` implied by `-D warnings` | ||
|
||
error: `1 as *mut _` detected. Consider using `ptr::dangling_mut()` | ||
--> $DIR/dangling_ptr.rs:6:13 | ||
| | ||
6 | let y = 1 as *mut f64; | ||
| ^^^^^^^^^^^^^ | ||
|