errors/fmt: avoid string(int)
Updates golang/go#32479
Change-Id: I23e48e5c91cdb7ffa7bb82ed0f94927c452e9975
Reviewed-on: https://go-review.googlesource.com/c/exp/+/233902
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/errors/fmt/fmt_test.go b/errors/fmt/fmt_test.go
index d19f93b..01e85b4 100644
--- a/errors/fmt/fmt_test.go
+++ b/errors/fmt/fmt_test.go
@@ -240,10 +240,10 @@
{"%#q", "\U0010ffff", "``"},
{"%#+q", "\U0010ffff", "``"},
// Runes that are not valid.
- {"%q", string(0x110000), `"�"`},
- {"%+q", string(0x110000), `"\ufffd"`},
- {"%#q", string(0x110000), "`�`"},
- {"%#+q", string(0x110000), "`�`"},
+ {"%q", string(rune(0x110000)), `"�"`},
+ {"%+q", string(rune(0x110000)), `"\ufffd"`},
+ {"%#q", string(rune(0x110000)), "`�`"},
+ {"%#+q", string(rune(0x110000)), "`�`"},
// characters
{"%c", uint('x'), "x"},
@@ -1407,7 +1407,7 @@
s := "%"
for i := 0; i < 128; i++ {
if f.Flag(i) {
- s += string(i)
+ s += string(rune(i))
}
}
if w, ok := f.Width(); ok {
diff --git a/errors/fmt/scan.go b/errors/fmt/scan.go
index ae79e39..f1c192a 100644
--- a/errors/fmt/scan.go
+++ b/errors/fmt/scan.go
@@ -600,13 +600,13 @@
// scanRune returns the next rune value in the input.
func (s *ss) scanRune(bitSize int) int64 {
s.notEOF()
- r := int64(s.getRune())
+ r := s.getRune()
n := uint(bitSize)
- x := (r << (64 - n)) >> (64 - n)
- if x != r {
+ x := (int64(r) << (64 - n)) >> (64 - n)
+ if x != int64(r) {
s.errorString("overflow on character value " + string(r))
}
- return r
+ return int64(r)
}
// scanBasePrefix reports whether the integer begins with a 0 or 0x,