Skip to content

od: fix GNU od.pl#9334

Merged
cakebaker merged 23 commits into
uutils:mainfrom
mattsu2020:od_compatibility
Nov 28, 2025
Merged

od: fix GNU od.pl#9334
cakebaker merged 23 commits into
uutils:mainfrom
mattsu2020:od_compatibility

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

Enhanced compatibility with GNU coreutils

related
#9127

…rsing, including overflow detection and input validation.
…overflow error reporting with `libc::ERANGE`, and prevent final offset printing on input errors.
Replace repetitive assert_eq! calls with a new assert_alignment helper
to improve test readability and reduce code duplication. The helper
encapsulates alignment checks for OutputInfo::calculate_alignment,
making tests clearer and easier to maintain.
Added "ERANGE" to the dictionary to prevent spell checker flagging it as a misspelling, as it's a valid errno constant from C libraries.
Refactor width option parsing in OdOptions to use i18n-compatible error messages via translate! macro, consolidating redundant error branches for better maintainability. Enhance float formatting for f16 and bf16 by introducing format_binary16_like helper to properly display subnormal values with exponential notation, removing the obsolete format_float_simple function and adding subnormal detection functions for accurate representation in od's output.
Remove unnecessary `value` variable in `format_item_bf16` function, eliminating
a redundant cast and inline `f` directly for clarity and minor efficiency gain.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

Remove hardcoded "--" prefixes from localization strings in en-US.ftl and fr-FR.ftl, replacing with a computed display name that includes "--" and optionally the short form (e.g., "--option" or "--option, -s"). Update parse_bytes_option and read_bytes functions to pass an option_display_name, enabling consistent error message formatting across localizations. Add validation to reject zero width values as invalid arguments. Improves user experience by providing clearer, more consistent option references in error outputs.
Removed unnecessary line breaks in the format! expression, keeping the code more concise while maintaining functionality. This improves code style in the float printing module.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/od/od is no longer failing!

The MultifileReader now uses `fname.maybe_quote().external(true)` when displaying permission and I/O errors, ensuring filenames are properly quoted for user-facing output (e.g., handling special characters that might confuse shells). This prevents potential issues with filename display in error logs.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/od/od is no longer failing!

Comment thread src/uu/od/src/input_decoder.rs Outdated
Comment thread src/uu/od/src/od.rs Outdated
Renamed the function in input_decoder.rs from f128_to_f64 to u128_to_f64
to accurately reflect its purpose of converting u128 integer bits to f64,
improving code readability and reducing potential confusion over float types.
Use map_err and the try operator to replace a verbose match statement,
making the code more concise and idiomatic Rust. This improves readability
without altering functionality.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/od/od is no longer failing!

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/od/od is no longer failing!

Comment thread src/uu/od/src/od.rs Outdated
Comment thread src/uu/od/src/od.rs Outdated
Comment thread src/uu/od/src/od.rs Outdated
Comment thread src/uu/od/src/parse_inputs.rs Outdated
Comment thread src/uu/od/src/parse_inputs.rs Outdated
Comment thread src/uu/od/src/parse_inputs.rs Outdated
Comment thread src/uu/od/src/parse_inputs.rs Outdated
pub fn parse_offset_operand(s: &str) -> Result<u64, String> {
// Reject empty strings
if s.is_empty() {
return Err((*translate!("od-error-parse-failed").leak()).to_string());

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.

What's the reason for using leak() when returning an Err (here and in the other places of this function)? Why not use something like:

return Err(translate!("od-error-parse-failed"));

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.

Correct. Fix the code.

mattsu2020 and others added 7 commits November 28, 2025 08:33
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
…offset_operand

Eliminated use of `.leak()` and unnecessary `.to_string()` calls on translated error strings in the `parse_offset_operand` function. This simplifies error handling, improves memory safety by avoiding intentional leaks, and makes the code cleaner without functional changes.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/od/od is no longer failing!

@cakebaker cakebaker merged commit 43dd238 into uutils:main Nov 28, 2025
128 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Congrats! The gnu test tests/od/od is no longer failing!

Kudos, thanks!

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.

2 participants