Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/uu/od/src/od.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ fn extract_strings_from_input(
};

let mut current_string = Vec::new();
let mut string_start_offset = 0u64;
let mut string_start_offset = skip_bytes;
let mut current_offset = skip_bytes;
let mut bytes_read = 0u64;
let mut buf = [0u8; 1];
Expand Down Expand Up @@ -665,7 +665,12 @@ fn extract_strings_from_input(
// Either null terminator or non-printable character
if byte == 0 && current_string.len() >= min_length {
// Null terminator found with valid string
print_string(string_start_offset, &current_string)?;
let offset = if current_string.is_empty() {
current_offset
} else {
string_start_offset
};
print_string(offset, &current_string)?;
}
current_string.clear();
}
Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_od.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,25 @@ fn test_od_strings_option() {
.succeeds()
.stdout_is("0000000 hello\n0000006 world\n");

// Test -S0 with empty strings and consecutive NUL bytes (issue #16134)
new_ucmd!()
.args(&["--strings=0", "-Ad"])
.pipe_in(b"abc\x00\x00def\x00")
.succeeds()
.stdout_is("0000000 abc\n0000004 \n0000005 def\n");

new_ucmd!()
.args(&["-S0", "-Ad"])
.pipe_in(b"\x00\x00")
.succeeds()
.stdout_is("0000000 \n0000001 \n");

new_ucmd!()
.args(&["--strings=0", "-Ad", "-j4"])
.pipe_in(b"abc\x00\x00def\x00")
.succeeds()
.stdout_is("0000004 \n0000005 def\n");

// Test -S0 with single character strings
new_ucmd!()
.arg("-S0")
Expand Down
Loading