Fix 10414: FP 'The address of local variable 'single_value' might be accessed at non-zero index.' (regression) (#3447)

This commit is contained in:
Paul Fultz II 2021-09-06 00:15:46 -05:00 committed by GitHub
parent 98e22f6162
commit d4174a31ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -4689,7 +4689,10 @@ private:
" for(int i=0;i<strlen(*test);i++)\n"
" printf(\"%c\",*test[i]);\n"
"}\n");
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());
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());
}
};