-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Remove unsafe code at creditcard.rs #109
Comments
We know that the contained values are valid UTF-8, so what does the additional check gain us? |
Hi llogiq, Thanks for replying. from_utf8() is another function that also converts a slice of bytes to a string slice, but it performs checks on the input to ensure that it is a valid UTF-8 sequence. If the input is not a valid UTF-8 sequence, from_utf8 returns an Err variant of the Result type, which can be handled by the caller. In general, it is recommended to use from_utf8 over from_utf8_unchecked because it can help catch errors and bugs in your code at runtime. However, if you are certain that the input slice is always going to be a valid UTF-8 sequence, you can use from_utf8_unchecked for a potential performance improvement. |
But we do know the string is always valid UTF-8, because it's just digits. |
Ok, thanks for confirming. I will close it now. |
Hi team,
From scanning the repo, I detected below unsafe code, and it can be convert to safe version:
unsafe { String::from_utf8_unchecked(bytes) }
fake-rs/fake/src/faker/impls/creditcard.rs
Line 43 in 5a26c9c
Safe version:
String::from_utf8(bytes).unwrap()
The text was updated successfully, but these errors were encountered: