]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] fmt: fix crash of %b on huge negative int64
authorRob Pike <r@golang.org>
Thu, 12 Apr 2012 23:28:37 +0000 (09:28 +1000)
committerRob Pike <r@golang.org>
Thu, 12 Apr 2012 23:28:37 +0000 (09:28 +1000)
««« backport 344d5c33331a
fmt: fix crash of %b on huge negative int64
The buffer had 64 bytes but needs one more for the sign.

Fixes #3510.

R=golang-dev, dave, dsymonds
CC=golang-dev
https://golang.org/cl/6011057
»»»

src/pkg/fmt/fmt_test.go
src/pkg/fmt/format.go

index 758fc50d08d3638602d8e5c8453333cafab3911b..de0342967cc36ae4e12c62d245526ad43105fc8f 100644 (file)
@@ -461,6 +461,9 @@ var fmttests = []struct {
        // zero reflect.Value, which formats as <nil>.
        // This test is just to check that it shows the two NaNs at all.
        {"%v", map[float64]int{math.NaN(): 1, math.NaN(): 2}, "map[NaN:<nil> NaN:<nil>]"},
+
+       // Used to crash because nByte didn't allow for a sign.
+       {"%b", int64(-1 << 63), "-1000000000000000000000000000000000000000000000000000000000000000"},
 }
 
 func TestSprintf(t *testing.T) {
index 2186f334b916217547cee6d94d45e9328e9204fd..caf900d5c3098caf3fcef0c5ef17c0f7a37b32d7 100644 (file)
@@ -10,7 +10,7 @@ import (
 )
 
 const (
-       nByte = 64
+       nByte = 65 // %b of an int64, plus a sign.
 
        ldigits = "0123456789abcdef"
        udigits = "0123456789ABCDEF"