mirror of git://git.musl-libc.org/musl
fix printf alt-form octal with value 0 and no explicit precision
commit78897b0dc0
wrongly simplified Dmitry Levin's original submitted patch fixing alt-form octal with the zero flag and field width present, omitting the special case where the value is zero. as a result, printf("%#o",0) wrongly prints "00" rather than "0". the logic prior to this commit was actually better, in that it was aligned with how the alt-form flag (#) for printf is specified ("it shall increase the precision"). at the time there was no good way to avoid the zero flag issue with the old logic, but commit167dfe9672
added tracking of whether an explicit precision was provided. revert commit78897b0dc0
and switch to using the explicit precision indicator for suppressing the zero flag.
This commit is contained in:
parent
32482f61da
commit
b64539ae06
|
@ -559,7 +559,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
|
||||||
if (0) {
|
if (0) {
|
||||||
case 'o':
|
case 'o':
|
||||||
a = fmt_o(arg.i, z);
|
a = fmt_o(arg.i, z);
|
||||||
if ((fl&ALT_FORM) && p<z-a+1) prefix+=5, pl=1;
|
if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
|
||||||
} if (0) {
|
} if (0) {
|
||||||
case 'd': case 'i':
|
case 'd': case 'i':
|
||||||
pl=1;
|
pl=1;
|
||||||
|
@ -574,7 +574,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
|
||||||
a = fmt_u(arg.i, z);
|
a = fmt_u(arg.i, z);
|
||||||
}
|
}
|
||||||
if (xp && p<0) goto overflow;
|
if (xp && p<0) goto overflow;
|
||||||
if (p>=0) fl &= ~ZERO_PAD;
|
if (xp) fl &= ~ZERO_PAD;
|
||||||
if (!arg.i && !p) {
|
if (!arg.i && !p) {
|
||||||
a=z;
|
a=z;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue