diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-02-24 18:35:17 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-02-26 04:38:19 +0000 |
commit | 6052838bc325049505aba9c3b87256161f9e05e8 (patch) | |
tree | 5d566da7ff0796abd2eb08c168ac2547948fac67 /src/fmt | |
parent | c46ffdd2eca339918ed30b6ba9d4715ba769d35d (diff) | |
download | go-6052838bc325049505aba9c3b87256161f9e05e8.tar.gz go-6052838bc325049505aba9c3b87256161f9e05e8.zip |
all: avoid string(i) where i has type int
Instead use string(r) where r has type rune.
This is in preparation for a vet warning for string(i).
Updates #32479
Change-Id: Ic205269bba1bd41723950219ecfb67ce17a7aa79
Reviewed-on: https://go-review.googlesource.com/c/go/+/220844
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Akhil Indurti <aindurti@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Toshihiro Shiino <shiino.toshihiro@gmail.com>
Diffstat (limited to 'src/fmt')
-rw-r--r-- | src/fmt/fmt_test.go | 10 | ||||
-rw-r--r-- | src/fmt/scan.go | 8 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index bbaf40a619..072fc6bf3b 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -236,10 +236,10 @@ var fmtTests = []struct { {"%#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"}, @@ -1457,7 +1457,7 @@ func (flagPrinter) Format(f State, c rune) { 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/src/fmt/scan.go b/src/fmt/scan.go index 8cab0180ee..381577049c 100644 --- a/src/fmt/scan.go +++ b/src/fmt/scan.go @@ -600,13 +600,13 @@ func (s *ss) scanNumber(digits string, haveDigits bool) string { // 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 base prefix |