Fixed #350 (False positive: Array index out of bounds)

This commit is contained in:
Daniel Marjamäki 2009-06-02 18:56:53 +02:00
parent 52a0da7335
commit b4c637c58b
2 changed files with 13 additions and 0 deletions

View File

@ -451,6 +451,10 @@ void CheckBufferOverrunClass::CheckBufferOverrun_GlobalAndLocalVariable()
unsigned int varid = 0;
int nextTok = 0;
// if the previous token exists, it must be either a variable name or "[;{}]"
if (tok->previous() && (!tok->previous()->isName() && !Token::Match(tok->previous(), "[;{}]")))
continue;
if (Token::Match(tok, "%type% *| %var% [ %num% ] [;=]"))
{
unsigned int varpos = 1;

View File

@ -460,6 +460,15 @@ private:
" p[i] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (all) Buffer overrun\n", errout.str());
// No false positive
check("void foo(int x, int y)\n"
"{\n"
" const char *p[2];\n"
" x = y * p[1];\n"
" p[1] = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}