diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index f328e5dcc..678015c33 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -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(); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 9b8c44d11..6f460866c 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -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() {