Skip to content

Commit

Permalink
head: use OsStringExt::from_vec instead of std::from_utf8_unchecked
Browse files Browse the repository at this point in the history
This no longer triggers the `invalid_from_utf8_unchecked` lint. It
is also a bit cleaner and no longer requires `unsafe` because
OsString is not guaranteed to be valid UTF-8.
  • Loading branch information
tertsdiepraam authored and sylvestre committed May 31, 2023
1 parent 701f30a commit 77e1839
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,10 @@ mod tests {
#[test]
#[cfg(target_os = "linux")]
fn test_arg_iterate_bad_encoding() {
#[allow(clippy::invalid_utf8_in_unchecked)]
let invalid = unsafe { std::str::from_utf8_unchecked(b"\x80\x81") };
use std::os::unix::ffi::OsStringExt;
let invalid = OsString::from_vec(vec![b'\x80', b'\x81']);
// this arises from a conversion from OsString to &str
assert!(
arg_iterate(vec![OsString::from("head"), OsString::from(invalid)].into_iter()).is_err()
);
assert!(arg_iterate(vec![OsString::from("head"), invalid].into_iter()).is_err());
}
#[test]
fn read_early_exit() {
Expand Down

0 comments on commit 77e1839

Please sign in to comment.