Skip to content

Commit f96db01

Browse files
committed
ensure index is not greater than capacity when selecting wrong answers
1 parent 010cb27 commit f96db01

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

quiz/types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package quiz
22

33
import (
44
logger "log"
5+
"math"
56
"math/rand"
67
"time"
78
)
@@ -222,7 +223,8 @@ func (q Question) ToRound() Round {
222223
q.Wrong[i], q.Wrong[j] = q.Wrong[j], q.Wrong[i]
223224
})
224225
}
225-
for _, a := range q.Wrong[:3] {
226+
num_wrong := int(math.Min(float64(cap(q.Wrong)), 3))
227+
for _, a := range q.Wrong[:num_wrong] {
226228
answers = append(answers, a.Text)
227229
}
228230

0 commit comments

Comments
 (0)