Skip to content

`repocutter reduce`: Fix panic and stack overflow

fel9e requested to merge fel9e/reposurgeon:repocutter-reduce-fix-panic into master

The first commit 04c953f9 fixes the "panic: runtime error: index out of range" reported in issue #135 (closed). When searching for the value of n, the function doreduce mistakes the slice value i for a slice index and wrongly compares n == v[i] instead of n == i.

However, with that fix applied, I get another error:

$ ./repoctter reduce dummyrep.svn >dummyrep-out.svn
Topologically reduce a dump....runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x5263a9, 0xe)
        /usr/lib/golang/src/runtime/panic.go:608 +0x72
runtime.newstack()
        /usr/lib/golang/src/runtime/stack.go:1008 +0x729
runtime.morestack()
        /usr/lib/golang/src/runtime/asm_amd64.s:429 +0x8f

goroutine 1 [running]:
bufio.(*Reader).Read(0xc0000763c0, 0xc0000ce000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
        /usr/lib/golang/src/bufio/bufio.go:190 +0x3ec fp=0xc0200ee330 sp=0xc0200ee328 pc=0x4661cc
bufio.(*Reader).Read(0xc0000763c0, 0xc0000ce000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
        /usr/lib/golang/src/bufio/bufio.go:202 +0x127 fp=0xc0200ee388 sp=0xc0200ee330 pc=0x465f07
bufio.(*Reader).Read(0xc0000763c0, 0xc0000ce000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
        /usr/lib/golang/src/bufio/bufio.go:202 +0x127 fp=0xc0200ee3e0 sp=0xc0200ee388 pc=0x465f07
bufio.(*Reader).Read(0xc0000763c0, 0xc0000ce000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
        /usr/lib/golang/src/bufio/bufio.go:202 +0x127 fp=0xc0200ee438 sp=0xc0200ee3e0 pc=0x465f07
[...]

That's what the second commit 738b1045 is for. Line 244 calls bufio.NewReader(source). The same parameter is expected in the call to Reset(), if I got it right.

For me these two changes work, but I am not an expert for Go. So, feel free to discard them, if they go into the wrong direction.

Merge request reports