diff options
authorRich Felker <>2014-11-15 12:16:19 -0500
committerRich Felker <>2015-03-30 01:41:32 -0400
commit395e409cc0b89faeaae8d701a18105d020f7aade (patch)
parent8c245bf2725f3171ee8f58dab7169e5d682de026 (diff)
fix behavior of printf with alt-form octal, zero precision, zero value
in this case there are two conflicting rules in play: that an explicit precision of zero with the value zero produces no output, and that the '#' modifier for octal increases the precision sufficiently to yield a leading zero. ISO C ( paragraph 6 in C99+TC3) includes a parenthetical remark to clarify that the precision-increasing behavior takes precedence, but the corresponding text in POSIX off of which I based the implementation is missing this remark. this issue was covered in WG14 DR#151. (cherry picked from commit b91cdbe2bc8b626aa04dc6e3e84345accf34e4b1)
1 files changed, 1 insertions, 1 deletions
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index f6e7f38d..9f02f743 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -572,7 +572,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) && arg.i) prefix+=5, pl=1;
+ if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
} if (0) {
case 'd': case 'i':