Skip to content

od: print 6-digit hex offsets with -S, like the normal dump - #15625

Merged
sylvestre merged 1 commit into
uutils:mainfrom
ozenyunus35:od-strings-hex-offset-width
Oct 22, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
ozenyunus35:od-strings-hex-offset-width

Conversation

@ozenyunus35

Copy link
Copy Markdown
Contributor

Fixes #15592

With -S/--strings and -Ax, od zero-padded the offsets to 7 hex digits. GNU od uses 6, and so does uutils od's own normal dump with -Ax (InputOffset formats hex as {:06x}). Decimal and octal offsets stay at 7 digits, which already matches GNU.

printf 'a\0' | od -Ax -S1
# before: 0000000 a
# after:  000000 a   (same as GNU 9.12)

I added a -Ax -S3 case to test_od_strings_option. It fails without the change, and all test_od tests pass. I also compared -S output with GNU od on a 20 MB file of short NUL-separated ASCII strings, for -Ax, -Ad, -Ao and -An (with and without -j), so offsets past 6 hex digits are covered too. The output is identical.

I used an AI assistant to help draft parts of the code and tests; I reviewed the changes and ran the tests myself.

Comment thread src/uu/od/src/od.rs
Radix::NoPrefix => writeln!(writer, "{string_content}"),
Radix::Decimal => writeln!(writer, "{offset:07} {string_content}"),
Radix::Hexadecimal => writeln!(writer, "{offset:07x} {string_content}"),
Radix::Hexadecimal => writeln!(writer, "{offset:06x} {string_content}"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this reuse InputOffset::format_byte_offset instead? it would avoid the two copies drifting again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sylvestre Good idea. I did that in a follow-up PR: #15648

@sylvestre
sylvestre merged commit ea26dbb into uutils:main Oct 22, 2026
140 of 141 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

sylvestre pushed a commit that referenced this pull request Oct 24, 2026
Follow-up to #15625: the strings mode had its own copy of the offset
formats. InputOffset now implements Display, format_byte_offset uses
it, and -S writes the offset through it without an extra allocation.
hubot pushed a commit to coreutils/coreutils that referenced this pull request Oct 24, 2026
* tests/od/od.pl (@tests): Add test cases for -S with -Ax, -Ad and -Ao,
ensuring hexadecimal offsets use 6 digits as in the normal dump.
uutils/coreutils#15625

Link: #393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

od: -S with -Ax prints 7-digit hex offsets instead of 6

2 participants