Conversation
…eneral float formatting.
…rsing, including overflow detection and input validation.
…overflow error reporting with `libc::ERANGE`, and prevent final offset printing on input errors.
… range and exponential otherwise.
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.
|
GNU testsuite comparison: |
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.
|
GNU testsuite comparison: |
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.
|
GNU testsuite comparison: |
cakebaker
reviewed
Nov 27, 2025
cakebaker
reviewed
Nov 27, 2025
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.
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
cakebaker
reviewed
Nov 27, 2025
cakebaker
reviewed
Nov 27, 2025
cakebaker
reviewed
Nov 27, 2025
cakebaker
reviewed
Nov 27, 2025
cakebaker
reviewed
Nov 27, 2025
cakebaker
reviewed
Nov 27, 2025
cakebaker
reviewed
Nov 27, 2025
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()); |
Contributor
There was a problem hiding this comment.
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"));
Contributor
Author
There was a problem hiding this comment.
Correct. Fix the code.
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.
|
GNU testsuite comparison: |
Contributor
Kudos, thanks! |
RenjiSann
pushed a commit
to RenjiSann/coreutils
that referenced
this pull request
Nov 28, 2025
* feat: Add support for long double floating-point numbers and refine general float formatting. * feat: Enhance `od` error reporting for file I/O, width, and offset parsing, including overflow detection and input validation. * feat: Improve long double parsing by converting f128 to f64, enhance overflow error reporting with `libc::ERANGE`, and prevent final offset printing on input errors. * style: Apply minor formatting adjustments across the `od` module. * refactor: simplify float formatting logic and update string handling syntax * fix: Correct float formatting logic to use decimal for numbers within range and exponential otherwise. * refactor(test): use helper function in test_calculate_alignment 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. * feat(cspell): add ERANGE to jargon wordlist Added "ERANGE" to the dictionary to prevent spell checker flagging it as a misspelling, as it's a valid errno constant from C libraries. * feat(od): improve width error handling and subnormal float output 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. * refactor(od): simplify format_item_bf16 by removing redundant variable Remove unnecessary `value` variable in `format_item_bf16` function, eliminating a redundant cast and inline `f` directly for clarity and minor efficiency gain. * fix(od): standardize option names in error messages 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. * refactor: condense format! macro in format_item_bf16 for readability 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. * fix(od): add external quoting for filenames in error messages 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. * refactor(od): Rename f128_to_f64 to u128_to_f64 for clarity 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. * refactor(od): simplify error handling in OdOptions using combinators 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. * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * refactor(od): remove leaking from translated error messages in parse_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. --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
martinkunkel2
pushed a commit
to martinkunkel2/coreutils
that referenced
this pull request
Nov 30, 2025
* feat: Add support for long double floating-point numbers and refine general float formatting. * feat: Enhance `od` error reporting for file I/O, width, and offset parsing, including overflow detection and input validation. * feat: Improve long double parsing by converting f128 to f64, enhance overflow error reporting with `libc::ERANGE`, and prevent final offset printing on input errors. * style: Apply minor formatting adjustments across the `od` module. * refactor: simplify float formatting logic and update string handling syntax * fix: Correct float formatting logic to use decimal for numbers within range and exponential otherwise. * refactor(test): use helper function in test_calculate_alignment 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. * feat(cspell): add ERANGE to jargon wordlist Added "ERANGE" to the dictionary to prevent spell checker flagging it as a misspelling, as it's a valid errno constant from C libraries. * feat(od): improve width error handling and subnormal float output 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. * refactor(od): simplify format_item_bf16 by removing redundant variable Remove unnecessary `value` variable in `format_item_bf16` function, eliminating a redundant cast and inline `f` directly for clarity and minor efficiency gain. * fix(od): standardize option names in error messages 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. * refactor: condense format! macro in format_item_bf16 for readability 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. * fix(od): add external quoting for filenames in error messages 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. * refactor(od): Rename f128_to_f64 to u128_to_f64 for clarity 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. * refactor(od): simplify error handling in OdOptions using combinators 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. * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * refactor(od): remove leaking from translated error messages in parse_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. --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
martinkunkel2
pushed a commit
to martinkunkel2/coreutils
that referenced
this pull request
Nov 30, 2025
* feat: Add support for long double floating-point numbers and refine general float formatting. * feat: Enhance `od` error reporting for file I/O, width, and offset parsing, including overflow detection and input validation. * feat: Improve long double parsing by converting f128 to f64, enhance overflow error reporting with `libc::ERANGE`, and prevent final offset printing on input errors. * style: Apply minor formatting adjustments across the `od` module. * refactor: simplify float formatting logic and update string handling syntax * fix: Correct float formatting logic to use decimal for numbers within range and exponential otherwise. * refactor(test): use helper function in test_calculate_alignment 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. * feat(cspell): add ERANGE to jargon wordlist Added "ERANGE" to the dictionary to prevent spell checker flagging it as a misspelling, as it's a valid errno constant from C libraries. * feat(od): improve width error handling and subnormal float output 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. * refactor(od): simplify format_item_bf16 by removing redundant variable Remove unnecessary `value` variable in `format_item_bf16` function, eliminating a redundant cast and inline `f` directly for clarity and minor efficiency gain. * fix(od): standardize option names in error messages 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. * refactor: condense format! macro in format_item_bf16 for readability 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. * fix(od): add external quoting for filenames in error messages 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. * refactor(od): Rename f128_to_f64 to u128_to_f64 for clarity 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. * refactor(od): simplify error handling in OdOptions using combinators 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. * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/od.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * Update src/uu/od/src/parse_inputs.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * refactor(od): remove leaking from translated error messages in parse_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. --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhanced compatibility with GNU coreutils
related
#9127