-
-
Save krdln/f0c1584de3d2146e91be to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or 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
... | |
macro_rules! nada { | |
() => { unsafe { std::mem::uninitialized() } } | |
} | |
#[derive(Debug)] | |
struct Konnection { | |
hp : String, | |
cred : String, | |
sock : TcpStream, | |
} | |
fn konnect( hostport : &str, name : &str, passwd : &str ) -> Konnection { | |
let mut k : Konnection = nada!(); | |
let mut cred = name.to_string(); | |
cred.push( ':' ); | |
cred.push_str( passwd ); | |
// here k.cred contains some garbage (including a pointer containg random bits) | |
k.cred = cred; | |
// reassignment destroys old value, and tries calls free() on that random pointer! | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment