diff --git a/cover/profile.go b/cover/profile.go index 79009d0f70..0bb3541774 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 f312cf05fe..3cecdacd50 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 {