bug with printf positional arguments?
Jon Turney
jon.turney@dronecode.org.uk
Wed Jun 28 13:28:41 GMT 2023
The following trivial program (extracted from a glib testcase)
> #include <stdio.h>
>
> int main()
> {
> printf ("%1$*2$.*3$s", "abc", 5, 2);
> }
does not produce the expected output of " ab", on 64-bit Cygwin.
From a bit of staring at and stepping through get_args() in
libc/stdio/vfprintf.c, it looks like the problem is (something like) we
don't have the knowledge that the first positional variadic argument
should be treated as a pointer, at the point that we store it's value,
so it gets treated as an integer (the default), which is going to lead
to truncation on LP64 platforms.
A straightforward way to fix this eludes me.
More information about the Newlib
mailing list