Panic trying to set content to a string with a null byte
ThomasHabets opened this issue · 0 comments
ThomasHabets commented
Yes, that null byte should not be there. But panic/unwrap()
is not the best solution.
Basically, libraries should never call .unwrap()
. It took me forever to track this down, since it was a string provided to me, and various libraries swallowed the original error. But the root cause is this:
impl <'a>ToCStr for &'a str {
fn to_c_str(&self) -> CString {
CString::new(*self).unwrap()
}
}
Please either transparently remove null bytes, or (better yet) have the trait and implementation pass the error back to the caller.