Fixed #2097 (false positive: buffer access out of bounds)

This commit is contained in:
Daniel Marjamäki 2010-10-14 20:00:32 +02:00
parent e11d9f1628
commit ba2b986ece
2 changed files with 18 additions and 0 deletions

View File

@ -589,6 +589,10 @@ void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, c
if (ftok->varId() == parameterVarId)
{
if (Token::Match(ftok->previous(), "-- %var%") ||
Token::Match(ftok, "%var% --"))
break;
if (Token::Match(ftok->previous(), "[=+-*/;{}] %var% [ %num% ]"))
{
long index = MathLib::toLongNumber(ftok->strAt(2));

View File

@ -550,6 +550,20 @@ private:
" memclr( str, 5 ); // ERROR\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #2097..
check("void foo(int *p)\n"
"{\n"
" --p;\n"
" p[2] = 0;\n"
"}\n"
"\n"
"void bar()\n"
"{\n"
" int p[3];\n"
" foo(p+1);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}