ITADN

Panic trying to set content to a string with a null byte

#214ClosedThomasHabets 创建于 2024-03-29
T
ThomasHabetscommented
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](https://github.com/jeaye/ncurses-rs/blob/master/src/lib.rs#L65): ```rust 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.
关闭于 2024-03-29 0 条评论