diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index f4390b481..4cc2a53ae 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1020,8 +1020,7 @@ void CheckBufferOverrun::objectIndex() return false; return vidx.path == v.path || vidx.path == 0; }); - if (idxValues.empty() || - std::any_of(idxValues.begin(), idxValues.end(), [&](const ValueFlow::Value& vidx) { + if (std::any_of(idxValues.begin(), idxValues.end(), [&](const ValueFlow::Value& vidx) { if (vidx.isImpossible()) return (vidx.intvalue == 0); else diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index d3355d648..1a1e8aaf0 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -4689,7 +4689,10 @@ private: " for(int i=0;i [test.cpp:4] -> [test.cpp:9]: (warning) The address of local variable 'test' might be accessed at non-zero index.\n", errout.str()); + TODO_ASSERT_EQUALS( + "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:9]: (warning) The address of local variable 'test' might be accessed at non-zero index.\n", + "", + errout.str()); check("void Bar(uint8_t data);\n" "void Foo(const uint8_t * const data, const uint8_t length) {\n" @@ -4701,6 +4704,18 @@ private: " Foo(&data,1U);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("int foo(int n, int* p) {\n" + " int res = 0;\n" + " for(int i = 0; i < n; i++ )\n" + " res += p[i];\n" + " return res;\n" + "}\n" + "int bar() {\n" + " int single_value = 0;\n" + " return foo(1, &single_value);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };