Fixed #2976 (False positive: array out of bounds)

This commit is contained in:
Daniel Marjamäki 2011-08-08 18:22:15 +02:00
parent afe95be966
commit e2367b4149
2 changed files with 13 additions and 0 deletions

View File

@ -894,6 +894,12 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
break;
}
// reassign buffer => bailout
if (varid > 0 &&
Token::Match(tok, "[;{}] %varid% =", varid) &&
!Token::Match(tok->tokAt(3), "%varid%", varid))
break;
// Array index..
if (varid > 0)
{

View File

@ -2497,6 +2497,13 @@ private:
" s[10] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[1]' index 10 out of bounds\n", errout.str());
check("void foo() {\n"
" const char *s = \"\";\n"
" s = y();\n"
" s[10] = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// data is allocated with alloca