Files
codeql/go/ql/test/query-tests/InconsistentCode/LengthComparisonOffByOne/LengthComparisonOffByOne.go
2026-06-11 07:15:54 +02:00

16 lines
351 B
Go

package main
import "strings"
func containsBad(searchName string, names string) bool {
values := strings.Split(names, ",")
// BAD: index could be equal to length
for i := 0; i <= len(values); i++ { // $ Alert
// When i = length, this access will be out of bounds
if values[i] == searchName { // $ Source
return true
}
}
return false
}