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

Failure to cast back to &str from &[u8] #241

Closed
avanhatt opened this issue Jun 22, 2021 · 3 comments · Fixed by #1717
Closed

Failure to cast back to &str from &[u8] #241

avanhatt opened this issue Jun 22, 2021 · 3 comments · Fixed by #1717
Assignees
Labels
[C] Bug This is a bug. Something isn't working.

Comments

@avanhatt
Copy link
Contributor

#235 adds the test src/test/cbmc/Strings/copy_empty_string_by_intrinsic_fixme.rs, which has this chunk:

        let dest_slice : &[u8] = from_raw_parts(dest, l);
        let dest_as_str : &str= str::from_utf8(dest_slice).unwrap();
        assert!(dest_as_str.len() == l);

With failures verification with:

[...copy_empty_string_by_intrinsic.assertion.2] line 1035 unreachable code: FAILURE
[...copy_empty_string_by_intrinsic.assertion.1] line 1037 a panicking function std::result::unwrap_failed is invoked: FAILURE
[...copy_string.assertion.2] line 28 assertion failed: dest_as_str.len() == l: FAILURE
@avanhatt avanhatt added the [C] Bug This is a bug. Something isn't working. label Jun 22, 2021
@danielsn
Copy link
Contributor

You might want to use https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.html
https://doc.rust-lang.org/std/str/fn.from_utf8.html - the conversion we are using is expected to fail if the bytes are not valid unicode.

@zhassan-aws
Copy link
Contributor

@jaisnan Please check if this one is still reproducible.

@celinval celinval removed the T-Good First Issue Good for newcomers label Mar 23, 2022
@zhassan-aws
Copy link
Contributor

This is still reproducible and is due to a missing std function. See this comment for how we plan on addressing this issue: #576 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Bug This is a bug. Something isn't working.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

6 participants