]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: fix padding for 0 precision 0 integer value formatting
authorMartin Möhrmann <martisch@uos.de>
Sun, 20 Mar 2016 17:12:32 +0000 (18:12 +0100)
committerRob Pike <r@golang.org>
Wed, 30 Mar 2016 00:44:01 +0000 (00:44 +0000)
Fixes #14924

Change-Id: I098ef973e2cad76a121704492758c2971a9b55f3
Reviewed-on: https://go-review.googlesource.com/20920
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/fmt/fmt_test.go
src/fmt/format.go

index ff975b0aace38a454e75b47fa1d2a31e8bb6ca91..3c5142c0f8602b9160c68bad8b64f040f1d8d032 100644 (file)
@@ -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"},
index 6539c0b1c12adecade188eb8b8c56328d780a819..b7e4f5163968248ad03d1d78ffc64d84561d1409 100644 (file)
@@ -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
        }