Created
July 24, 2013 06:46
-
-
Save anonymous/6068516 to your computer and use it in GitHub Desktop.
Minimal example for "Segmentation fault: 11" occurrence when passing around closures.
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
use std::vec; | |
fn encrypt_decrypt_consistent_key() -> (@fn(&[u8]) -> ~[u8], @fn(&[u8]) -> ~[u8]) { | |
let key = "random key".as_bytes().to_owned(); | |
(|bytes: &[u8]| { | |
vec::append(bytes.to_owned(), key) | |
}, |bytes: &[u8]| { | |
// segfault: 11 | |
vec::append(bytes.to_owned(), key) | |
}) | |
} | |
fn main() { | |
let (encrypt, decrypt) = encrypt_decrypt_consistent_key(); | |
let plaintext_bytes = "plaintext".as_bytes(); | |
let encrypted_bytes = encrypt(plaintext_bytes); | |
// segfault: 11 | |
let decrypted_bytes = decrypt(encrypted_bytes); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment