diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index e40770fc7..3dba65926 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -264,7 +264,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con // Get index variable and stopsize. const char *strindex = tok2->str().c_str(); bool condition_out_of_bounds = true; - if (value < size) + if (value <= size) condition_out_of_bounds = false; const Token *tok3 = tok2->tokAt(4); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 6f460866c..84c6544e4 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -97,6 +97,7 @@ private: TEST_CASE(buffer_overrun_7); TEST_CASE(buffer_overrun_8); TEST_CASE(buffer_overrun_9); + TEST_CASE(buffer_overrun_10); TEST_CASE(sprintf1); TEST_CASE(sprintf2); @@ -645,6 +646,20 @@ private: ASSERT_EQUALS("", errout.str()); } + void buffer_overrun_10() + { + // ticket #740 + check("void f()\n" + "{\n" + " char a[4];\n" + " for (int i = 0; i < 4; i++)\n" + " {\n" + " char b = a[i];\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void sprintf1() {