Fixed #350 (False positive: Array index out of bounds)
This commit is contained in:
parent
52a0da7335
commit
b4c637c58b
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue