aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2010-07-01 14:44:21 -0700
committerRob Pike <r@golang.org>2010-07-01 14:44:21 -0700
commitdc6a95e9798216b803145eb9e998304fda7126a4 (patch)
treef016a8c438ed7c5494b4912629eaa552b4c7286e
parent38f1231f3ed39b03758a7508eb1b2951ba5ef0a8 (diff)
downloadgo-dc6a95e9798216b803145eb9e998304fda7126a4.tar.gz
go-dc6a95e9798216b803145eb9e998304fda7126a4.zip
strconv.Uitob64: allow conversion of 64-bit binaries (buffer was too small).
panic if base is invalid. R=rsc CC=golang-dev https://golang.org/cl/1702050
-rw-r--r--src/pkg/strconv/itoa.go5
-rw-r--r--src/pkg/strconv/itoa_test.go2
2 files changed, 6 insertions, 1 deletions
diff --git a/src/pkg/strconv/itoa.go b/src/pkg/strconv/itoa.go
index a633560537..a0a7496641 100644
--- a/src/pkg/strconv/itoa.go
+++ b/src/pkg/strconv/itoa.go
@@ -6,12 +6,15 @@ package strconv
// Uitob64 returns the string representation of i in the given base.
func Uitob64(u uint64, base uint) string {
+ if base < 2 || 36 < base {
+ panic("invalid base " + Uitoa(base))
+ }
if u == 0 {
return "0"
}
// Assemble decimal in reverse order.
- var buf [32]byte
+ var buf [64]byte
j := len(buf)
b := uint64(base)
for u > 0 {
diff --git a/src/pkg/strconv/itoa_test.go b/src/pkg/strconv/itoa_test.go
index e0624b547c..039ef44468 100644
--- a/src/pkg/strconv/itoa_test.go
+++ b/src/pkg/strconv/itoa_test.go
@@ -50,6 +50,7 @@ var itob64tests = []itob64Test{
itob64Test{16, 16, "10"},
itob64Test{-0x123456789abcdef, 16, "-123456789abcdef"},
itob64Test{1<<63 - 1, 16, "7fffffffffffffff"},
+ itob64Test{1<<63 - 1, 2, "111111111111111111111111111111111111111111111111111111111111111"},
itob64Test{16, 17, "g"},
itob64Test{25, 25, "10"},
@@ -135,6 +136,7 @@ var uitob64tests = []uitob64Test{
uitob64Test{1<<63 + 1, 10, "9223372036854775809"},
uitob64Test{1<<64 - 2, 10, "18446744073709551614"},
uitob64Test{1<<64 - 1, 10, "18446744073709551615"},
+ uitob64Test{1<<64 - 1, 2, "1111111111111111111111111111111111111111111111111111111111111111"},
}
func TestUitoa(t *testing.T) {