Skip to content

cmd/go: Tests failing when init accesses a byte slice larger than 65536 with go test -cover #73495

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

Open
maxkidd opened this issue Apr 24, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@maxkidd
Copy link

maxkidd commented Apr 24, 2025

Go version

go version go1.24.2 windows/amd64

Output of go env in your module/workspace:

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\maxki\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\maxki\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\maxki\AppData\Local\Temp\go-build2150697774=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=C:\Users\maxki\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\maxki\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\maxki\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.2
set GOWORK=
set PKG_CONFIG=pkg-config

What did you do?

Write a file with a global byte slice larger than 1<16. Access it in the init() func. Also add a test file (can be empty). call 'go test -cover'

package testbed

var (
	indexes [65537]byte
)

func init() {
	indexes[0] = 0x00
}

What did you see happen?

PS C:\Users\maxki\go\src\nbio\testbed> go test -cover
testing: warning: no tests to run
PASS
panic: runtime error: slice bounds out of range [:16777222] with capacity 7

goroutine 1 [running]:
internal/coverage/cfile.(*emitState).VisitFuncs(0xc00006a8c0, 0xc000008330)
        C:/Program Files/Go/src/internal/coverage/cfile/emit.go:478 +0xdb0
internal/coverage/encodecounter.(*CoverageDataWriter).writeCounters(0xc00009a0f0, {0x109ddc0, 0xc00006a8c0}, 0xc00005a700)
        C:/Program Files/Go/src/internal/coverage/encodecounter/encode.go:278 +0x10b
internal/coverage/encodecounter.(*CoverageDataWriter).AppendSegment(0xc00009a0f0, 0xc00001ef30, {0x109ddc0, 0xc00006a8c0})
        C:/Program Files/Go/src/internal/coverage/encodecounter/encode.go:178 +0x4b2
internal/coverage/encodecounter.(*CoverageDataWriter).Write(0xc00009a0f0, {0xca, 0xc4, 0x3b, 0x46, 0xbb, 0xcb, 0xf6, 0x57, 0xfa, ...}, ...)
        C:/Program Files/Go/src/internal/coverage/encodecounter/encode.go:70 +0x54
internal/coverage/cfile.(*emitState).emitCounterDataFile(0xc00006a8c0, {0xca, 0xc4, 0x3b, 0x46, 0xbb, 0xcb, 0xf6, 0x57, 0xfa, ...}, ...)
        C:/Program Files/Go/src/internal/coverage/cfile/emit.go:566 +0x4e
internal/coverage/cfile.emitCounterDataToDirectory({0xc0000180d1, 0x44})
        C:/Program Files/Go/src/internal/coverage/cfile/emit.go:318 +0x165
internal/coverage/cfile.ProcessCoverTestDir({0xc0000180d1, 0x44}, {0x0, 0x0}, {0x1057f03?, 0x0?}, {0x0, 0x0}, {0x109dcb8, 0xc000056070}, ...)
        C:/Program Files/Go/src/internal/coverage/cfile/testsupport.go:46 +0x17e
testing/internal/testdeps.coverTearDown({0x0, 0x0}, {0xc0000180d1?, 0x0?})
        C:/Program Files/Go/src/testing/internal/testdeps/deps.go:236 +0x159
testing.coverReport2()
        C:/Program Files/Go/src/testing/newcover.go:43 +0x3a
testing.coverReport(...)
        C:/Program Files/Go/src/testing/cover.go:86
testing.(*M).writeProfiles(0xc00006a6e0)
        C:/Program Files/Go/src/testing/testing.go:2433 +0x72b
testing.(*M).after.func1()
        C:/Program Files/Go/src/testing/testing.go:2367 +0x17
sync.(*Once).doSlow(0xc00000c3c0?, 0x5?)
        C:/Program Files/Go/src/sync/once.go:78 +0xab
sync.(*Once).Do(...)
        C:/Program Files/Go/src/sync/once.go:69
testing.(*M).after(0xc00006a6e0)
        C:/Program Files/Go/src/testing/testing.go:2366 +0x3b
testing.(*M).Run(0xc00006a6e0)
        C:/Program Files/Go/src/testing/testing.go:2185 +0xb8b
main.main()
        _testmain.go:53 +0x9b
exit status 2

What did you expect to see?

Pass with a coverage percent

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Apr 24, 2025
@JunyangShao
Copy link
Contributor

@matloob

@JunyangShao JunyangShao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants