Skip to content

Commit a99057c

Browse files
authored
Add sampleCount zero checking in NewLeapArray func (#420)
1 parent d022a91 commit a99057c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

core/stat/base/leap_array.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ type LeapArray struct {
159159
}
160160

161161
func NewLeapArray(sampleCount uint32, intervalInMs uint32, generator BucketGenerator) (*LeapArray, error) {
162-
if intervalInMs%sampleCount != 0 {
162+
if sampleCount == 0 || intervalInMs%sampleCount != 0 {
163163
return nil, errors.Errorf("Invalid parameters, intervalInMs is %d, sampleCount is %d", intervalInMs, sampleCount)
164164
}
165165
if generator == nil {

core/stat/base/leap_array_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,9 @@ func TestNewLeapArray(t *testing.T) {
297297
assert.Nil(t, leapArray)
298298
assert.Error(t, err, "Invalid parameters, intervalInMs is 10000, sampleCount is 30")
299299
})
300+
t.Run("TestNewLeapArray_Invalid_Parameters_sampleCount0", func(t *testing.T) {
301+
leapArray, err := NewLeapArray(0, IntervalInMs, nil)
302+
assert.Nil(t, leapArray)
303+
assert.Error(t, err, "Invalid parameters, intervalInMs is 10000, sampleCount is 0")
304+
})
300305
}

0 commit comments

Comments
 (0)