Files
codeql/cpp/ql/src/Critical/LateNegativeTest.cpp
2018-08-02 17:53:23 +01:00

12 lines
264 B
C++

Record records[SIZE] = ...;
int f() {
int recordIdx = 0;
cin >> recordIdx;
printRecord(&(records[recordIdx])); //incorrect: recordIdx may be negative here
if (recordIdx >= 0) {
processRecord(&(records[recordIdx])); //correct: index checked before use
}
}