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

slice: negative indexing doesn't panics #29629

Closed
zeslava opened this issue Jan 9, 2019 · 7 comments
Closed

slice: negative indexing doesn't panics #29629

zeslava opened this issue Jan 9, 2019 · 7 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@zeslava
Copy link

zeslava commented Jan 9, 2019

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

$ go version
go version go1.11 linux/amd64

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="/home/slava/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/slava/go"
GOPROXY=""
GORACE=""
GOROOT="/home/slava/go1.11"
GOTMPDIR=""
GOTOOLDIR="/home/slava/go1.11/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build846395121=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I try to test some code like this

type stack []int

func (s *stack) last() int {
    return (*s)[len(*s)-1]
}

func Test_last(t *testing.T) {
    s := stack{}
    s.last() // should panics
}

What did you expect to see?

panic

What did you see instead?

no panic

@ianlancetaylor
Copy link
Member

Please show us a complete standalone example. If you are using go test, use go test -test.v to make sure that your test is being run. Note that a more typical name for a test function would be TestLast.

This Go program panics when I run it:

package main

type stack []int

func (s *stack) last() int {
    return (*s)[len(*s)-1]
}

func last() {
    s := stack{}
    s.last() // should panics
}

func main() {
	last()
}

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 9, 2019
@bcmills
Copy link
Contributor

bcmills commented Jan 9, 2019

Please also test against the most recent patch release: go1.11.4, not go1.11.

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 9, 2019
@mvdan
Copy link
Member

mvdan commented Jan 9, 2019

If this is fixed in 1.11.4 and tip, it's very likely just a duplicate of #27289, which was backported into 1.11.1.

@ianlancetaylor
Copy link
Member

If you are still having this problem, please show us a complete standalone example. Thanks.

@zeslava
Copy link
Author

zeslava commented Jan 9, 2019

With go 1.11.4 panic occurs

@ianlancetaylor
Copy link
Member

Thanks, so it sounds like this bug has been fixed.

@mvdan
Copy link
Member

mvdan commented Jan 9, 2019

Well, then it's clearly a duplicate. Thanks for the follow-up.

@golang golang locked and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants