Skip to content

Commit 491e643

Browse files
author
kgrygiel
committed
Panic if bucket index is out of range.
1 parent 61d2423 commit 491e643

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vertical-pod-autoscaler/recommender/util/histogram_options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package util
1818

1919
import (
2020
"errors"
21+
"fmt"
2122
"math"
2223
)
2324

@@ -94,6 +95,9 @@ func (o *linearHistogramOptions) FindBucket(value float64) int {
9495
}
9596

9697
func (o *linearHistogramOptions) GetBucketStart(bucket int) float64 {
98+
if bucket < 0 || bucket >= o.numBuckets {
99+
panic(fmt.Sprintf("index %d out of range [0..%d]", bucket, o.numBuckets-1))
100+
}
97101
return float64(bucket) * o.bucketSize
98102
}
99103

@@ -117,6 +121,9 @@ func (o *exponentialHistogramOptions) FindBucket(value float64) int {
117121
}
118122

119123
func (o *exponentialHistogramOptions) GetBucketStart(bucket int) float64 {
124+
if bucket < 0 || bucket >= o.numBuckets {
125+
panic(fmt.Sprintf("index %d out of range [0..%d]", bucket, o.numBuckets-1))
126+
}
120127
if bucket == 0 {
121128
return 0.0
122129
}

0 commit comments

Comments
 (0)