On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote: > commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed > behavior of printf with alt-form octal, zero precision, zero value, > at the same time broke alt-form octal with default precision, > e. g. printf("%#09o", 1). > --- > src/stdio/vfprintf.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c > index 2ecf769..ac2891c 100644 > --- a/src/stdio/vfprintf.c > +++ b/src/stdio/vfprintf.c > @@ -570,7 +570,14 @@ 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 + if (fl&ALT_FORM) { > + if (p >= 0 && p + p=z-a+1; > + } else if (arg.i) { > + prefix+=5; > + pl=1; > + } > + } > } if (0) { > case 'd': case 'i': > pl=1; I think the attached simpler patch should work just as well. Adjusting 'p' to implement '#' was probably a bad idea since it makes the later code paths think an explicit precision was specified when it was not. "Add a prefix of '0' when p is too short to have a leading '0' already" seems like safer logic. I'm also attaching some test cases I ran. Rich