-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Description
In the following, the deriving
does the wrong thing: it shallow copies the pointer when the semantics mean it should be making a new allocation and copying the data; there's no indication of this until runtime double-frees/segfaults.
/// Wrapper around an owned allocation
#[deriving(Clone)]
struct Struct {
owned: *mut int
}
impl Struct {
fn new(x: int) { Struct { owned: unsafe {cast::transmute(~x)} } }
}
impl Drop for Struct {
fn drop(&mut self) {
let _: ~int = unsafe {cast::transmute(self.owned)};
}
}
Some possible resolutions:
- do nothing: unsafe code is unsafe
- have lints for
deriving
+ unsafe pointers - have
deriving
completely disabled on unsafe pointers - remove the trait impls for raw pointers
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.