Skip to content

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

@jfinkels

Description

@jfinkels

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions