operator-index.go: ConstLastIndex is checked

This commit is contained in:
Celestino Amoroso 2024-06-19 09:24:19 +02:00
parent d63b18fd76
commit ff9cf80c66

View File

@ -40,11 +40,14 @@ func verifyRange(indexTerm *term, indexList *ListType, maxValue int) (startIndex
v, _ := ((*indexList)[0]).(*intPair) v, _ := ((*indexList)[0]).(*intPair)
startIndex = v.a startIndex = v.a
endIndex = v.b endIndex = v.b
if endIndex == ConstLastIndex {
endIndex = maxValue
}
if startIndex < 0 && startIndex >= -maxValue { if startIndex < 0 && startIndex >= -maxValue {
startIndex = maxValue + startIndex startIndex = maxValue + startIndex
} }
if endIndex < 0 && endIndex >= -maxValue { if endIndex < 0 && endIndex >= -maxValue {
endIndex = maxValue + endIndex + 1 endIndex = maxValue + endIndex
} }
if startIndex < 0 || startIndex > maxValue { if startIndex < 0 || startIndex > maxValue {
err = indexTerm.Errorf("range start-index %d is out of bounds", startIndex) err = indexTerm.Errorf("range start-index %d is out of bounds", startIndex)