Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version:1.9.5
go version:1.10.2
Does this issue reproduce with the latest release?
yes ,it reproduce in 1.10.2 version
What operating system and processor architecture are you using (go env
)?
I have to two go version for use
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tbwisk/go"
GORACE=""
GOROOT="/usr/local/Cellar/go@1.9/1.9.5/libexec"
GOTOOLDIR="/usr/local/Cellar/go@1.9/1.9.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4b/mfftzbmx3t58tvq3t0_zq3100000gp/T/go-build136633725=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tbwisk/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tbwisk/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.2/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4b/mfftzbmx3t58tvq3t0_zq3100000gp/T/go-build563777223=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/NKAi82Azthk
my go code
package main
import "fmt"
func main() {
ra := "\xd5\xbc\xbd\xbe"
for idx := range ra {
fmt.Println(idx)
}
}
What did you expect to see?
0
1
2
3
What did you see instead?
0
2
3
Activity
dhowden commentedon May 9, 2018
It looks like that string it not valid UTF8, and so iterating over the UTF8 runes of the string won't work as expected:
https://play.golang.org/p/Xv9EqHQjTOC
This code shows the errors more clearly: https://play.golang.org/p/2d0_9LFo1L9
agnivade commentedon May 9, 2018
Even if it was a valid utf-8 string, one should not expect the indices to be serial. A range loop iterates over unicode code points rather than bytes. To iterate on bytes, use the regular for loop.
See https://blog.golang.org/strings (range loops section) for more detail.
Closing since this is not a bug.