From: Martin Möhrmann Date: Sun, 20 Mar 2016 17:12:32 +0000 (+0100) Subject: fmt: fix padding for 0 precision 0 integer value formatting X-Git-Tag: go1.7beta1~1030 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=aec8e14589edecfd9752255e742b88e15ee651f2;p=gostls13.git fmt: fix padding for 0 precision 0 integer value formatting Fixes #14924 Change-Id: I098ef973e2cad76a121704492758c2971a9b55f3 Reviewed-on: https://go-review.googlesource.com/20920 Run-TryBot: Rob Pike TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index ff975b0aac..3c5142c0f8 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -345,6 +345,7 @@ var fmtTests = []struct { {"%x", ^uint32(0), "ffffffff"}, {"%X", ^uint64(0), "FFFFFFFFFFFFFFFF"}, {"%.20b", 7, "00000000000000000111"}, + {"%6.0d", 0, " "}, {"%10d", 12345, " 12345"}, {"%10d", -12345, " -12345"}, {"%+10d", 12345, " +12345"}, diff --git a/src/fmt/format.go b/src/fmt/format.go index 6539c0b1c1..b7e4f51639 100644 --- a/src/fmt/format.go +++ b/src/fmt/format.go @@ -192,8 +192,11 @@ func (f *fmt) fmt_unicode(u uint64) { // fmt_integer formats signed and unsigned integers. func (f *fmt) fmt_integer(u uint64, base int, isSigned bool, digits string) { - // precision of 0 and value of 0 means "print nothing" + // Precision of 0 and value of 0 means "print nothing" but padding. if f.precPresent && f.prec == 0 && u == 0 { + if f.widPresent { + f.writePadding(f.wid) + } return }