Skip to content

printf: use non-zero indexes #7855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged

printf: use non-zero indexes #7855

merged 1 commit into from
Apr 30, 2025

Conversation

jtracey
Copy link
Contributor

@jtracey jtracey commented Apr 28, 2025

#7837 added support for indexing in format strings, but allowed for an index of 0, treating it as equivalent to an index of 1. GNU rejects 0 indexes, which makes sense, as all the other indexes are 1-indexed, which means a user could encounter difficult to debug off-by-one errors if printf didn't return an error (e.g., if looping indexes from 0..$n).

This commit forbids 0 indexes, expressed at the type level with std::num::NonZero. Doing so also cuts the aligned size of ArgumentLocation in half, from two pointer widths to one, which is the sort of thing that could help some optimizations (I didn't run any benchmarks, the benefit is likely pretty tiny).

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

@RenjiSann
Copy link
Collaborator

Great, Thanks !

@RenjiSann RenjiSann merged commit 279629f into uutils:main Apr 30, 2025
107 of 109 checks passed
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