Fixed #7209 (False positive: Array index used before limits check reported in sizeof)

This commit is contained in:
Daniel Marjamäki 2016-01-24 14:06:02 +01:00
parent 6faa637fc7
commit 659cd96b03
2 changed files with 10 additions and 0 deletions

View File

@ -1803,6 +1803,11 @@ void CheckBufferOverrun::arrayIndexThenCheck()
for (std::size_t i = 0; i < functions; ++i) {
const Scope * const scope = symbolDatabase->functionScopes[i];
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% ]")) {
tok = tok->tokAt(2);

View File

@ -3801,6 +3801,11 @@ private:
" }\n"
"}");
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() {