Skip to content

printf * precision spec issue with positional arguments #4636

Description

@akrieger

I understand the printf api is not recommended for new usage. I'm migrating an older codebase from a custom formatting utility over printf to using fmtlib for binary size wins. There is one test case which correctly identifies a failing case in fmtlib which I am reporting in case it is interesting or useful.

fmt::printf("%6$-*5$.*4$f%3$s%2$s%1$s", "", "", "", 7, 4, 100.44); returns width is not integer.
::printf("%6$-*5$.*4$f%3$s%2$s%1$s", "", "", "", 7, 4, 100.44) prints 100.4400000.

This appears to be because when fmt handles the '*5%' specifier it does not recognize the positional argument and so tries to fetch the -1st arg, which is out of bounds and causes a wild read.

https://godbolt.org/z/YYj7WTqb5

Activity

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

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