Skip to content
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

printf: fails to render %*s conversion with negative integer argument #7096

Open
jfinkels opened this issue Jan 8, 2025 · 0 comments
Open

Comments

@jfinkels
Copy link
Collaborator

jfinkels commented Jan 8, 2025

Steps to reproduce:

printf "a(%*s)b\n" -3

(the "a(" and ")b" are just there to make the whitespace in the output more readable, they are not critical to the example)

What happens now: uutils printf prints an error message and then renders the %*s with zero spaces:

./target/debug/printf: '-3': expected a numeric value
a()b

What I expected to happen: GNU printf succeeds with three spaces:

a(   )b

Notes: This is causing a failure in the GNU test file tests/printf/printf.sh.

According to the glibc Output Conversion Syntax documentation,

You can also specify a field width of ‘*’. This means that the next argument in the argument list (before the actual value to be printed) is used as the field width. The value must be an int. If the value is negative, this means to set the ‘-’ flag (see below) and to use the absolute value as the field width.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant