diff options
author | Robert Griesemer <gri@golang.org> | 2020-11-25 13:47:42 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2020-11-26 05:00:21 +0000 |
commit | f0ff6d4a67ec9a956aa655d487543da034cf576b (patch) | |
tree | 0aa5dd4ce08ed9e4740eb20865c01597076fcf27 /src/reflect | |
parent | 4481ad6eb6c2b4ee52d949289da82cc00cc829fa (diff) | |
download | go-f0ff6d4a67ec9a956aa655d487543da034cf576b.tar.gz go-f0ff6d4a67ec9a956aa655d487543da034cf576b.zip |
reflect: fix Value.Convert for int-to-string conversions (regression)
The bug was introduced by https://golang.org/cl/220844.
Updates #42792.
Fixes #42835.
Change-Id: I03065c7526488aded35ef2f800b7162e1606877a
Reviewed-on: https://go-review.googlesource.com/c/go/+/273326
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/all_test.go | 3 | ||||
-rw-r--r-- | src/reflect/value.go | 12 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index a12712d254..b01158635f 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -4007,9 +4007,12 @@ var convertTests = []struct { {V(int16(-3)), V(string("\uFFFD"))}, {V(int32(-4)), V(string("\uFFFD"))}, {V(int64(-5)), V(string("\uFFFD"))}, + {V(int64(-1 << 32)), V(string("\uFFFD"))}, + {V(int64(1 << 32)), V(string("\uFFFD"))}, {V(uint(0x110001)), V(string("\uFFFD"))}, {V(uint32(0x110002)), V(string("\uFFFD"))}, {V(uint64(0x110003)), V(string("\uFFFD"))}, + {V(uint64(1 << 32)), V(string("\uFFFD"))}, {V(uintptr(0x110004)), V(string("\uFFFD"))}, // named string diff --git a/src/reflect/value.go b/src/reflect/value.go index bf926a7453..1f185b52e4 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -2681,12 +2681,20 @@ func cvtComplex(v Value, t Type) Value { // convertOp: intXX -> string func cvtIntString(v Value, t Type) Value { - return makeString(v.flag.ro(), string(rune(v.Int())), t) + s := "\uFFFD" + if x := v.Int(); int64(rune(x)) == x { + s = string(rune(x)) + } + return makeString(v.flag.ro(), s, t) } // convertOp: uintXX -> string func cvtUintString(v Value, t Type) Value { - return makeString(v.flag.ro(), string(rune(v.Uint())), t) + s := "\uFFFD" + if x := v.Uint(); uint64(rune(x)) == x { + s = string(rune(x)) + } + return makeString(v.flag.ro(), s, t) } // convertOp: []byte -> string |