[PATCH] fix printf positional arguments for !_MB_CAPABLE case
Corinna Vinschen
vinschen@redhat.com
Tue Jan 9 08:52:00 GMT 2018
On Jan 9 14:50, Ivan Grokhotkov wrote:
> Hi,
> In newlib builds with multibyte support disabled and positional arguments support enabled, positional arguments sometimes are not printed correctly. For example,
>
> printf(“%1$f”, 1.0);
>
> may print garbage value on a 32-bit platform.
>
> This issue happens because the code path in get_arg, which looks for ‘%’ character, does not work correctly for the ! _MB_CAPABLE case. In _MB_CAPABLE case, fmt pointer is advanced to the next character, and then the check for ‘%’ is performed. In !_MB_CAPABLE case, the check is performed before advancing ‘fmt’ pointer. Net result is that in !_MB_CAPABLE case fmt still points to ‘%’ character, which causes the subsequent state machine to go from START to DONE state immediately. ‘spec_type’ defaults to INT, so arguments which are longer than int (for example, double) are not fetched correctly using va_arg.
>
> Patch is attached.
>
> Thanks,
> Ivan
Pushed.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20180109/9fe02ed9/attachment.sig>
More information about the Newlib
mailing list