Fix ticket #243 (boundary checking)
http://apps.sourceforge.net/trac/cppcheck/ticket/243
This commit is contained in:
parent
07af9cf7c8
commit
11858129d0
|
@ -206,11 +206,11 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
||||||
const Token *tok2 = tok->tokAt(2);
|
const Token *tok2 = tok->tokAt(2);
|
||||||
|
|
||||||
// for - setup..
|
// for - setup..
|
||||||
if (Token::Match(tok2, "%var% = 0 ;"))
|
if (Token::Match(tok2, "%var% = %any% ;"))
|
||||||
tok2 = tok2->tokAt(4);
|
tok2 = tok2->tokAt(4);
|
||||||
else if (Token::Match(tok2, "%type% %var% = 0 ;"))
|
else if (Token::Match(tok2, "%type% %var% = %any% ;"))
|
||||||
tok2 = tok2->tokAt(5);
|
tok2 = tok2->tokAt(5);
|
||||||
else if (Token::Match(tok2, "%type% %type% %var% = 0 ;"))
|
else if (Token::Match(tok2, "%type% %type% %var% = %any% ;"))
|
||||||
tok2 = tok2->tokAt(6);
|
tok2 = tok2->tokAt(6);
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -230,13 +230,36 @@ private:
|
||||||
|
|
||||||
void array_index_3()
|
void array_index_3()
|
||||||
{
|
{
|
||||||
check("void f()\n"
|
{
|
||||||
"{\n"
|
check("void f()\n"
|
||||||
" int val[50];\n"
|
"{\n"
|
||||||
" for (i = 0; i < 100; i++)\n"
|
" int val[50];\n"
|
||||||
" sum += val[i];\n"
|
" for (i = 0; i < 100; i++)\n"
|
||||||
"}\n");
|
" sum += val[i];\n"
|
||||||
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Buffer overrun\n"), errout.str());
|
"}\n");
|
||||||
|
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Buffer overrun\n"), errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" int val[50];\n"
|
||||||
|
" for (i = 1; i < 100; i++)\n"
|
||||||
|
" sum += val[i];\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Buffer overrun\n"), errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
check("void f(int a)\n"
|
||||||
|
"{\n"
|
||||||
|
" int val[50];\n"
|
||||||
|
" for (i = a; i < 100; i++)\n"
|
||||||
|
" sum += val[i];\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Buffer overrun\n"), errout.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -385,10 +408,6 @@ private:
|
||||||
ASSERT_EQUALS(std::string("[test.cpp:10]: (all) Array index out of bounds\n"), err);
|
ASSERT_EQUALS(std::string("[test.cpp:10]: (all) Array index out of bounds\n"), err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void buffer_overrun_1()
|
void buffer_overrun_1()
|
||||||
{
|
{
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
|
Loading…
Reference in New Issue