Buffer overrun: Fix false negative

This commit is contained in:
Daniel Marjamäki 2011-08-07 17:54:25 +02:00
parent a6a966e28e
commit 999b80bbb8
2 changed files with 20 additions and 0 deletions

View File

@ -1244,9 +1244,20 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
ArrayInfo arrayInfo(var, _tokenizer); ArrayInfo arrayInfo(var, _tokenizer);
const Token *tok = var->nameToken(); const Token *tok = var->nameToken();
while (tok && tok->str() != ";") while (tok && tok->str() != ";")
{
if (tok->str() == "{")
{
if (Token::simpleMatch(tok->previous(), "= {"))
tok = tok->link();
else
break;
}
tok = tok->next(); tok = tok->next();
}
if (!tok) if (!tok)
break; break;
if (tok->str() == "{")
tok = tok->next();
checkScope(tok, arrayInfo); checkScope(tok, arrayInfo);
} }
} }

View File

@ -442,6 +442,15 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{
check("void foo(int a[10]) {\n"
" for (int i=0;i<50;++i) {\n"
" a[i] = 0;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer access out-of-bounds: a\n", errout.str());
}
} }
void array_index_4() void array_index_4()