Fixed #6070 (false positive: Array 'array[8192]' accessed at index 8192, which is out of bounds)

This commit is contained in:
Daniel Marjamäki 2014-08-19 07:03:00 +02:00
parent eac2d58c9e
commit b6355b991f
2 changed files with 16 additions and 0 deletions

View File

@ -698,6 +698,18 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
void CheckBufferOverrun::valueFlowCheckArrayIndex(const Token * const tok, const ArrayInfo &arrayInfo)
{
// Declaration in global scope?
if (tok->scope()->type == Scope::eGlobal)
return;
/*
{
const Token *parent = tok->astParent();
while (Token::Match(parent, "%var%|::|*|&"))
parent = parent->astParent();
if (parent && !Token::simpleMatch(parent, "="))
return;
}
*/
// Taking address?
bool addressOf = false;
{

View File

@ -2121,6 +2121,10 @@ private:
" do_something(&str[0][5]);\n"
"}", false, "test.cpp", false);
ASSERT_EQUALS("", errout.str());
check("class X { static const int x[100]; };\n" // #6070
"const int X::x[100] = {0};", false, "test.cpp", false);
ASSERT_EQUALS("", errout.str());
}
void buffer_overrun_1_posix_functions() {