Skip to content

printf: avoid overflow for minimum dynamic width - #13795

Open
subotac wants to merge 2 commits into
uutils:mainfrom
subotac:fix/printf-min-width-overflow
Open

printf: avoid overflow for minimum dynamic width#13795
subotac wants to merge 2 commits into
uutils:mainfrom
subotac:fix/printf-min-width-overflow

Conversation

@subotac

@subotac subotac commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #13766.

Resolving a negative dynamic width negated the signed argument directly, which overflows for i64::MIN. Use unsigned_abs() so the value reaches the existing width handling safely, and add a regression
test for the minimum signed value.

@codspeed-hq

codspeed-hq Bot commented Aug 7, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 4.54%

⚡ 4 improved benchmarks
✅ 103 untouched benchmarks
⏩ 286 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ls_recursive_deep_tree[(200, 2)] 3.6 ms 3.4 ms +5.13%
Simulation du_max_depth_balanced_tree[(6, 4, 10)] 63.2 ms 60.4 ms +4.56%
Simulation du_summarize_balanced_tree[(5, 4, 10)] 16.2 ms 15.6 ms +4.28%
Simulation du_wide_tree[(5000, 500)] 20.8 ms 20 ms +4.2%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing subotac:fix/printf-min-width-overflow (bdbb205) with main (9f29502)

Open in CodSpeed

Footnotes

  1. 286 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cut/mb-non-utf8 is no longer failing!
Congrats! The gnu test tests/mv/mv-exchange is no longer failing!
Congrats! The gnu test tests/od/od-j is no longer failing!
Congrats! The gnu test tests/dd/no-allocate is now passing!
Note: The gnu test tests/misc/write-errors was skipped on 'main' but is now failing.

@sylvestre

Copy link
Copy Markdown
Contributor

Please also add a test in test_printf.rs

@sylvestre sylvestre left a comment

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.

Cf my comment

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.

printf: arithmetic overflow (overflow-checks) on a %*d dynamic field width of i64::MIN

2 participants