Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: use slice expression a[x : x] where cap(a) is x should cause panic #31377

Closed
choleraehyq opened this issue Apr 10, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@choleraehyq
Copy link
Contributor

commented Apr 10, 2019

What version of Go are you using (go version)?

$ go version
1.12.3

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/cholerae/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/cholerae/Documents/gopath"
GOPROXY=""
GORACE=""
GOROOT="/Users/cholerae/Documents/gopath/go"
GOTMPDIR=""
GOTOOLDIR="/Users/cholerae/Documents/gopath/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/cholerae/Documents/gocode/ByteGraph/go.mod"
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/1q/bn5v_zpd5qzc4dlg3bbp2psm0000gn/T/go-build647264484=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://play.golang.org/p/XT4xCSpIylL

What did you expect to see?

Panic at line 9.

What did you see instead?

Panic at line 10.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Apr 10, 2019

Working as intended. If cap(x) is N, then the slice expression [0:N] gives the whole slice since the indexing is open on the right. [N:N] is just a special case that slices off the empty slice at the end.

@robpike robpike closed this Apr 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.