Skip to content

Commit d4174a3

Browse files
authored
Fix 10414: FP 'The address of local variable 'single_value' might be accessed at non-zero index.' (regression) (danmar#3447)
1 parent 98e22f6 commit d4174a3

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,7 @@ void CheckBufferOverrun::objectIndex()
10201020
return false;
10211021
return vidx.path == v.path || vidx.path == 0;
10221022
});
1023-
if (idxValues.empty() ||
1024-
std::any_of(idxValues.begin(), idxValues.end(), [&](const ValueFlow::Value& vidx) {
1023+
if (std::any_of(idxValues.begin(), idxValues.end(), [&](const ValueFlow::Value& vidx) {
10251024
if (vidx.isImpossible())
10261025
return (vidx.intvalue == 0);
10271026
else

test/testbufferoverrun.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4689,7 +4689,10 @@ class TestBufferOverrun : public TestFixture {
46894689
" for(int i=0;i<strlen(*test);i++)\n"
46904690
" printf(\"%c\",*test[i]);\n"
46914691
"}\n");
4692-
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());
4692+
TODO_ASSERT_EQUALS(
4693+
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:9]: (warning) The address of local variable 'test' might be accessed at non-zero index.\n",
4694+
"",
4695+
errout.str());
46934696

46944697
check("void Bar(uint8_t data);\n"
46954698
"void Foo(const uint8_t * const data, const uint8_t length) {\n"
@@ -4701,6 +4704,18 @@ class TestBufferOverrun : public TestFixture {
47014704
" Foo(&data,1U);\n"
47024705
"}\n");
47034706
ASSERT_EQUALS("", errout.str());
4707+
4708+
check("int foo(int n, int* p) {\n"
4709+
" int res = 0;\n"
4710+
" for(int i = 0; i < n; i++ )\n"
4711+
" res += p[i];\n"
4712+
" return res;\n"
4713+
"}\n"
4714+
"int bar() {\n"
4715+
" int single_value = 0;\n"
4716+
" return foo(1, &single_value);\n"
4717+
"}\n");
4718+
ASSERT_EQUALS("", errout.str());
47044719
}
47054720
};
47064721

0 commit comments

Comments
 (0)