Skip to content

Commit 4241f8f

Browse files
jaredcurtismjuraga
authored andcommitted
BUG: Prevent a panic in the case when a map only has 1 entry
When a map only has a single entry `rand.Intn()` is supplied with `0` as as parameter which is invalid. In addition the previous code included a `+ 1` to the result of `rand.Intn()`. This is not needed, `rand.Intn()` provides results in the range of 0-(n-1) which will align with the array indexes.
1 parent 01b7b38 commit 4241f8f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

configure_data_plane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ func equalSomeFileAndRuntimeEntries(fEntries, rEntries models.MapEntries) bool {
795795

796796
for i := 0; i < 10; i++ {
797797
rand.Seed(time.Now().UTC().UnixNano())
798-
r := rand.Intn(max-1) + 1
798+
r := rand.Intn(max)
799799
if rEntries[r].Key != fEntries[r].Key || rEntries[r].Value != fEntries[r].Value {
800800
return false
801801
}

0 commit comments

Comments
 (0)