Fixed #7209 (False positive: Array index used before limits check reported in sizeof)
This commit is contained in:
parent
6faa637fc7
commit
659cd96b03
|
@ -1803,6 +1803,11 @@ void CheckBufferOverrun::arrayIndexThenCheck()
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (std::size_t i = 0; i < functions; ++i) {
|
||||||
const Scope * const scope = symbolDatabase->functionScopes[i];
|
const Scope * const scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||||
|
if (Token::simpleMatch(tok, "sizeof (")) {
|
||||||
|
tok = tok->linkAt(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "%name% [ %var% ]")) {
|
if (Token::Match(tok, "%name% [ %var% ]")) {
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
|
|
||||||
|
|
|
@ -3801,6 +3801,11 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", "", errout.str());
|
||||||
|
|
||||||
|
check("void f(int i) {\n" // sizeof
|
||||||
|
" sizeof(a)/sizeof(a[i]) && i < 10;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void bufferNotZeroTerminated() {
|
void bufferNotZeroTerminated() {
|
||||||
|
|
Loading…
Reference in New Issue