Skip to content

Instantly share code, notes, and snippets.

@krdln
Forked from anonymous/playground.rs
Last active August 29, 2015 14:25
Show Gist options
  • Save krdln/f0c1584de3d2146e91be to your computer and use it in GitHub Desktop.
Save krdln/f0c1584de3d2146e91be to your computer and use it in GitHub Desktop.
Shared via Rust Playground
...
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