fix printf regression with alt-form octal, zero flag, and field width
authorRich Felker <dalias@aerifal.cx>
Fri, 16 Sep 2016 21:40:08 +0000 (17:40 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 16 Sep 2016 21:40:08 +0000 (17:40 -0400)
commit b91cdbe2bc8b626aa04dc6e3e84345accf34e4b1, in fixing another
issue, changed the logic for how alt-form octal adds the leading zero
to adjust the precision rather than using a prefix character. this
wrongly suppressed the zero flag by mimicing an explicit precision
given by the format string. switch back to using a prefix character.

based on bug report and patch by Dmitry V. Levin, but simplified.

src/stdio/vfprintf.c

index 2ecf76925c97f3ee34faf03b3b23a6e5c1c2dc81..e439a07a195a69d06045cafde49fab3927045b0c 100644 (file)
@@ -570,7 +570,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
                        if (0) {
                case 'o':
                        a = fmt_o(arg.i, z);
-                       if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
+                       if ((fl&ALT_FORM) && p<z-a+1) prefix+=5, pl=1;
                        } if (0) {
                case 'd': case 'i':
                        pl=1;