operator-dot.go: fixed the index range checking
This commit is contained in:
+3
-2
@@ -22,10 +22,11 @@ func verifyIndex(ctx ExprContext, indexTerm *term, maxValue int) (index int, err
|
||||
var indexValue any
|
||||
if indexValue, err = indexTerm.compute(ctx); err == nil {
|
||||
if v, err = indexTerm.toInt(indexValue, "index expression value must be integer"); err == nil {
|
||||
if v < 0 && v >= -maxValue {
|
||||
v = maxValue + v
|
||||
}
|
||||
if v >= 0 && v < maxValue {
|
||||
index = v
|
||||
} else if index >= -maxValue {
|
||||
index = maxValue + v
|
||||
} else {
|
||||
err = indexTerm.Errorf("index %d out of bounds", v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user