diff options
author | Lucas Bremgartner <lucas@bremis.ch> | 2020-01-05 20:11:17 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2020-01-15 21:23:19 +0000 |
commit | 0110d43865d98cb11ba50e117b110055486c7612 (patch) | |
tree | d36323345caccd15426f932b3d2c7b1088e61734 /cover | |
parent | f04f2c82d09b716585c8205f5cd482d1eca2aa3d (diff) | |
download | golang-x-tools-0110d43865d98cb11ba50e117b110055486c7612.tar.gz |
cover: error on negative numbers in profiles
CL 179377 introduced an optimized parser for coverage profiles.
The parser replaces the following regex:
^(.+):([0-9]+)\.([0-9]+),([0-9]+)\.([0-9]+) ([0-9]+) ([0-9]+)$
With this regex, negative numbers in the coverage profiles resulted
in parsing errors. With the new parser in place, this is no longer
the case. This commit restores the old behavior.
Change-Id: Iaa72035f1f587ed186eaf5a84b209df88e67fb57
GitHub-Last-Rev: 07470fba9d587e6d3f383409fc8cf52bb882a984
GitHub-Pull-Request: golang/tools#195
Reviewed-on: https://go-review.googlesource.com/c/tools/+/213357
Reviewed-by: Katharine Berry <ktbry@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'cover')
-rw-r--r-- | cover/profile.go | 3 | ||||
-rw-r--r-- | cover/profile_test.go | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/cover/profile.go b/cover/profile.go index 79009d0f7..0bb354177 100644 --- a/cover/profile.go +++ b/cover/profile.go @@ -168,6 +168,9 @@ func seekBack(l string, sep byte, end int, what string) (value int, nextSep int, if err != nil { return 0, 0, fmt.Errorf("couldn't parse %q: %v", what, err) } + if i < 0 { + return 0, 0, fmt.Errorf("negative values are not allowed for %s, found %d", what, i) + } return i, start, nil } } diff --git a/cover/profile_test.go b/cover/profile_test.go index f312cf05f..3cecdacd5 100644 --- a/cover/profile_test.go +++ b/cover/profile_test.go @@ -198,6 +198,12 @@ some/fancy/path:42.69,44.16 2`, :42.69,44.16 2 3`, expectErr: true, }, + { + name: "a negative count is an error", + input: `mode: count +some/fancy/path:42.69,44.16 2 -1`, + expectErr: true, + }, } for _, tc := range tests { |