Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ThomasHabets opened this issue Mar 29, 2024 · 0 comments · Fixed by #215
Closed

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

ThomasHabets opened this issue Mar 29, 2024 · 0 comments · Fixed by #215

Comments

@ThomasHabets
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant