diff options
Diffstat (limited to 'libgo/go/fmt/format.go')
-rw-r--r-- | libgo/go/fmt/format.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/libgo/go/fmt/format.go b/libgo/go/fmt/format.go index a54f12ee9f9..3835aa9823a 100644 --- a/libgo/go/fmt/format.go +++ b/libgo/go/fmt/format.go @@ -10,7 +10,9 @@ import ( ) const ( - nByte = 65 // %b of an int64, plus a sign. + // %b of an int64, plus a sign. + // Hex can add 0x and we handle it specially. + nByte = 65 ldigits = "0123456789abcdef" udigits = "0123456789ABCDEF" @@ -160,9 +162,16 @@ func (f *fmt) integer(a int64, base uint64, signedness bool, digits string) { } var buf []byte = f.intbuf[0:] - if f.widPresent && f.wid > nByte { - // We're going to need a bigger boat. - buf = make([]byte, f.wid) + if f.widPresent { + width := f.wid + if base == 16 && f.sharp { + // Also adds "0x". + width += 2 + } + if width > nByte { + // We're going to need a bigger boat. + buf = make([]byte, width) + } } negative := signedness == signed && a < 0 |