4 ms·
#[no_mangle] pub extern fn string_array() -> *const *const u8 { let v = vec![ "Hello\0".as_ptr(), "World\0".as_ptr()
by Veedrac 9y ago
#[no_mangle]
pub extern fn string_array() -> *const *const u8 {
let v = vec![
"Hello\0".as_ptr(),
"World\0".as_ptr()
];
v.as_ptr()
}
This has exactly the same problem as with `CString`; the `Vec` is deallocated at function exit.
- huydotnet 9y agoYou're right. I just ran the code again, it produces something funny: [ '��\u0002\u0002', '8+���~', buffer: <Buffer > ] I will update the post. Thanks for pointing it out! :D