Fixed #5863 (False positive: array index is used before limits check)
This commit is contained in:
parent
bb8973aac7
commit
effa38c322
|
@ -2102,7 +2102,7 @@ void CheckBufferOverrun::arrayIndexThenCheck()
|
||||||
// statement can be closed in parentheses, so "(| " is using
|
// statement can be closed in parentheses, so "(| " is using
|
||||||
if (Token::Match(tok, "&& (| %varid% <|<=", indexID))
|
if (Token::Match(tok, "&& (| %varid% <|<=", indexID))
|
||||||
arrayIndexThenCheckError(tok, indexName);
|
arrayIndexThenCheckError(tok, indexName);
|
||||||
else if (Token::Match(tok, "&& (| %any% >|>= %varid%", indexID))
|
else if (Token::Match(tok, "&& (| %any% >|>= %varid% !!+", indexID))
|
||||||
arrayIndexThenCheckError(tok, indexName);
|
arrayIndexThenCheckError(tok, indexName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3976,6 +3976,12 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
|
||||||
|
|
||||||
|
check("void f(char* e, int y) {\n"
|
||||||
|
" if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this one doesn't work for now, hopefully in the future
|
// this one doesn't work for now, hopefully in the future
|
||||||
check("void f(const int a[], unsigned i) {\n"
|
check("void f(const int a[], unsigned i) {\n"
|
||||||
" if(a[i] < func(i) && i <= 42) {\n"
|
" if(a[i] < func(i) && i <= 42) {\n"
|
||||||
|
|
Loading…
Reference in New Issue