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:
Slava Semushin 2009-09-27 22:07:54 +07:00
parent fdde2182b9
commit 661ce78b69
2 changed files with 20 additions and 0 deletions

View File

@ -282,6 +282,10 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con
if (num > value) if (num > value)
condition_out_of_bounds = false; 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)" .. // Goto the end paranthesis of the for-statement: "for (x; y; z)" ..
tok2 = tok->next()->link(); tok2 = tok->next()->link();

View File

@ -96,6 +96,7 @@ private:
TEST_CASE(buffer_overrun_6); TEST_CASE(buffer_overrun_6);
TEST_CASE(buffer_overrun_7); TEST_CASE(buffer_overrun_7);
TEST_CASE(buffer_overrun_8); TEST_CASE(buffer_overrun_8);
TEST_CASE(buffer_overrun_9);
TEST_CASE(sprintf1); TEST_CASE(sprintf1);
TEST_CASE(sprintf2); TEST_CASE(sprintf2);
@ -629,6 +630,21 @@ private:
ASSERT_EQUALS("", errout.str()); 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() void sprintf1()
{ {