From c4dcfc1bda72883aa20eba627af840d1a4256c7b Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 8 Feb 2016 13:33:17 +0100 Subject: [PATCH] printf(3): Handle multibyte decimal point in field size computation This patch fixes the problem reported in https://cygwin.com/ml/cygwin/2016-02/msg00014.html The 2009 changes to handle multibyte decimal point and thousands separator missed to take the length of a multibyte decimal point into account when computing the field size. Signed-off-by: Corinna Vinschen --- newlib/libc/stdio/vfprintf.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index 5e6c61ca4..6430edf2c 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -1332,7 +1332,7 @@ reswitch: switch (ch) { expsize = exponent (expstr, expt, ch); size = expsize + ndig; if (ndig > 1 || flags & ALT) - ++size; + size += decp_len; # ifdef _WANT_IO_C99_FORMATS flags &= ~GROUPING; # endif @@ -1341,18 +1341,20 @@ reswitch: switch (ch) { if (expt > 0) { size = expt; if (prec || flags & ALT) - size += prec + 1; + size += prec + decp_len; } else /* "0.X" */ size = (prec || flags & ALT) - ? prec + 2 + ? prec + 1 + decp_len : 1; } else if (expt >= ndig) { /* fixed g fmt */ size = expt; if (flags & ALT) - ++size; - } else - size = ndig + (expt > 0 ? - 1 : 2 - expt); + size += decp_len; + } else { + size = ndig + decp_len; + if (expt <= 0) + size += 1 - expt; + } # ifdef _WANT_IO_C99_FORMATS if ((flags & GROUPING) && expt > 0) { /* space for thousands' grouping */