Fixed #738 (False Buffer overrun with -a when i is increased by more than 1 inside loop body)
http://sourceforge.net/apps/trac/cppcheck/ticket/738
This commit is contained in:
parent
fdde2182b9
commit
661ce78b69
|
@ -282,6 +282,10 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con
|
|||
if (num > value)
|
||||
condition_out_of_bounds = false;
|
||||
}
|
||||
else if (! Token::Match(tok3, "++| %varid% ++| )", counter_varid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Goto the end paranthesis of the for-statement: "for (x; y; z)" ..
|
||||
tok2 = tok->next()->link();
|
||||
|
|
|
@ -96,6 +96,7 @@ private:
|
|||
TEST_CASE(buffer_overrun_6);
|
||||
TEST_CASE(buffer_overrun_7);
|
||||
TEST_CASE(buffer_overrun_8);
|
||||
TEST_CASE(buffer_overrun_9);
|
||||
|
||||
TEST_CASE(sprintf1);
|
||||
TEST_CASE(sprintf2);
|
||||
|
@ -629,6 +630,21 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_9()
|
||||
{
|
||||
// ticket #738
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" char a[5];\n"
|
||||
" for (int i = 0; i < 20; )\n"
|
||||
" {\n"
|
||||
" a[i] = 0;\n"
|
||||
" i += 100;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void sprintf1()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue