Skip to content

Commit 0110d43

Browse files
bremlbradfitz
authored andcommitted
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: 07470fb GitHub-Pull-Request: golang#195 Reviewed-on: https://go-review.googlesource.com/c/tools/+/213357 Reviewed-by: Katharine Berry <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent f04f2c8 commit 0110d43

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cover/profile.go

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ func seekBack(l string, sep byte, end int, what string) (value int, nextSep int,
168168
if err != nil {
169169
return 0, 0, fmt.Errorf("couldn't parse %q: %v", what, err)
170170
}
171+
if i < 0 {
172+
return 0, 0, fmt.Errorf("negative values are not allowed for %s, found %d", what, i)
173+
}
171174
return i, start, nil
172175
}
173176
}

cover/profile_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ some/fancy/path:42.69,44.16 2`,
198198
:42.69,44.16 2 3`,
199199
expectErr: true,
200200
},
201+
{
202+
name: "a negative count is an error",
203+
input: `mode: count
204+
some/fancy/path:42.69,44.16 2 -1`,
205+
expectErr: true,
206+
},
201207
}
202208

203209
for _, tc := range tests {

0 commit comments

Comments
 (0)