Skip to content

Commit 9d10a78

Browse files
authored
Merge pull request #914 from cgwalters/disallow-strlen
clippy: Deny `str::len`
2 parents 0ff93f8 + dfa2c79 commit 9d10a78

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ missing_debug_implementations = "deny"
6868
dead_code = "deny"
6969

7070
[workspace.lints.clippy]
71+
disallowed_methods = "deny"
7172
# These should only be in local code
7273
dbg_macro = "deny"
7374
todo = "deny"

clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
disallowed-methods = [
2+
# https://github.com/rust-lang/rust-clippy/issues/13434#issuecomment-2484292914
3+
{ path = "str::len", reason = "use <str>.as_bytes().len() instead" }
4+
]

ostree-ext/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ async fn container_store(
900900
}
901901

902902
fn print_column(s: &str, clen: u16, remaining: &mut terminal_size::Width) {
903-
let l: u16 = s.len().try_into().unwrap();
903+
let l: u16 = s.chars().count().try_into().unwrap();
904904
let l = l.min(remaining.0);
905905
print!("{}", &s[0..l as usize]);
906906
if clen > 0 {

ostree-ext/src/tar/import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn parse_object_entry_path(path: &Utf8Path) -> Result<(&str, &Utf8Path, &str)> {
125125
.parent()
126126
.and_then(|p| p.file_name())
127127
.ok_or_else(|| anyhow!("Invalid path (no parent) {}", path))?;
128-
if parentname.len() != 2 {
128+
if !(parentname.is_ascii() && parentname.as_bytes().len() == 2) {
129129
return Err(anyhow!("Invalid checksum parent {}", parentname));
130130
}
131131
let name = path
@@ -146,7 +146,7 @@ fn parse_checksum(parent: &str, name: &Utf8Path) -> Result<String> {
146146
// Also take care of the double extension on `.file.xattrs`.
147147
let checksum_rest = checksum_rest.trim_end_matches(".file");
148148

149-
if checksum_rest.len() != 62 {
149+
if !(checksum_rest.is_ascii() && checksum_rest.as_bytes().len() == 62) {
150150
return Err(anyhow!("Invalid checksum part {}", checksum_rest));
151151
}
152152
let reassembled = format!("{}{}", parent, checksum_rest);

0 commit comments

Comments
 (0)