axw/gocov

nil pointer dereference when using -deps

Closed this issue · 3 comments

A nil pointer dereference occurs when gocov is run with the -deps option. Below shows the output from:

gocov test -deps > /dev/null

in code.google.com/p/biogo.step, but similar output occurs in any package I try.

Using -exclude='math/rand' prevents this panic which is due to calling (*Statement).At() on a nil receiver. gocov test math/rand gives essentially the same failure as expected.

This is presumably because math/rand depends on sync/atomic which is excluded from testing by gocov.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x18 pc=0x5a30b3]

goroutine 1 [running]:
sync/atomic.AddUint64(0x18, 0x1, 0x0, 0x0, 0x572b8d, ...)
/tmp/gocov810177481/src/pkg/sync/atomic/asm_amd64.s:58 +0xd
github.com/axw/gocov.(_Statement).At(0x0, 0xf84019b960)
/tmp/gocov810177481/src/pkg/github.com/axw/gocov/gocov.go:329 +0x33
math/rand.(_rngSource).Seed(0xf840154000, 0x1, 0xf8400f90a8, 0x4)
/tmp/gocov810177481/src/pkg/math/rand/rng.go:237 +0x28
math/rand.NewSource(0x1, 0x160e00001601, 0xf84021d720, 0x70e78c)
/tmp/gocov810177481/src/pkg/math/rand/rand.go:105 +0x68
math/rand.init()
/tmp/gocov810177481/src/pkg/math/rand/zipf.go:-390 +0x1f61
code.google.com/p/biogo%2estep.init()
/tmp/gocov810177481/src/pkg/code.google.com/p/biogo.step/step.go:14 +0x5b
main.init()
code.google.com/p/biogo.step/_test/_testmain.go:18 +0x3b

axw commented

Sounds like this bug I filed against gc a while ago: http://code.google.com/p/go/issues/detail?id=3824
I don't think the fix went into 1.0.3, so you'll probably have to go to tip or wait on 1.1.

The code Rémy posted on that bug works fine in the playground and the commit marked as fixing the issue went in on Jul30, but go1.0.3 was tagged Sep24, so I don't think they are the same bug. It's not a big issue though.

I'll try repeating it with tip... OK, that works without error.

axw commented

I think 1.0.3 was branched off an earlier revision, and fixed selectively back ported. I may be wrong though - and yeah I guess it doesn't really matter if it works now.

Thanks for verifying.