]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.10] cmd/cover: don't crash on non-gofmt'ed input
authorIan Lance Taylor <iant@golang.org>
Tue, 6 Mar 2018 15:57:19 +0000 (07:57 -0800)
committerAndrew Bonventre <andybons@golang.org>
Thu, 29 Mar 2018 06:07:57 +0000 (06:07 +0000)
commitee972315998be1520635f765a1ea230ad9833cbc
tree02f2de4c816c028c6dbd8988482c5e27a881085d
parent69a7f73de888c19ac6641dcd61a499404beb437c
[release-branch.go1.10] cmd/cover: don't crash on non-gofmt'ed input

Without the change to cover.go, the new test fails with

panic: overlapping edits: [4946,4950)->"", [4947,4947)->"thisNameMustBeVeryLongToCauseOverflowOfCounterIncrementStatementOntoNextLineForTest.Count[112]++;"

The original code inserts "else{", deletes "else", and then positions
a new block just after the "}" that must come before the "else".
That works on gofmt'ed code, but fails if the code looks like "}else".
When there is no space between the "{" and the "else", the new block
is inserted into a location that we are deleting, leading to the
"overlapping edits" mentioned above.

This CL fixes this case by not deleting the "else" but just using the
one that is already there. That requires adjust the block offset to
come after the "{" that we insert.

Fixes #23927

Change-Id: I40ef592490878765bbce6550ddb439e43ac525b2
Reviewed-on: https://go-review.googlesource.com/98935
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-on: https://go-review.googlesource.com/102786
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/cover/cover.go
src/cmd/cover/cover_test.go