Fix 10254: false positive: arrayIndexOutOfBounds in inline function (#3266)
This commit is contained in:
parent
22ae4543a6
commit
1e3ab460a3
|
@ -5609,11 +5609,11 @@ static void valueFlowLibraryFunction(Token *tok, const std::string &returnValue,
|
|||
|
||||
static void valueFlowSubFunction(TokenList* tokenlist, SymbolDatabase* symboldatabase, ErrorLogger* errorLogger, const Settings* settings)
|
||||
{
|
||||
int id = 0;
|
||||
for (const Scope* scope : symboldatabase->functionScopes) {
|
||||
const Function* function = scope->function;
|
||||
if (!function)
|
||||
continue;
|
||||
int id = 0;
|
||||
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
|
||||
if (!Token::Match(tok, "%name% ("))
|
||||
continue;
|
||||
|
@ -5670,7 +5670,7 @@ static void valueFlowSubFunction(TokenList* tokenlist, SymbolDatabase* symboldat
|
|||
argtok->expressionString() +
|
||||
"' value is " +
|
||||
v.infoString());
|
||||
v.path = 256 * v.path + id;
|
||||
v.path = 256 * v.path + id % 256;
|
||||
// Change scope of lifetime values
|
||||
if (v.isLifetimeValue())
|
||||
v.lifetimeScope = ValueFlow::Value::LifetimeScope::SubFunction;
|
||||
|
|
|
@ -132,6 +132,7 @@ private:
|
|||
TEST_CASE(array_index_52); // #7682
|
||||
TEST_CASE(array_index_53); // #4750
|
||||
TEST_CASE(array_index_54); // #10268
|
||||
TEST_CASE(array_index_55); // #10254
|
||||
TEST_CASE(array_index_multidim);
|
||||
TEST_CASE(array_index_switch_in_for);
|
||||
TEST_CASE(array_index_for_in_for); // FP: #2634
|
||||
|
@ -1567,6 +1568,23 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_55() {
|
||||
check("void make(const char* s, size_t len) {\n"
|
||||
" for (size_t i = 0; i < len; ++i)\n"
|
||||
" s[i];\n"
|
||||
"}\n"
|
||||
"void make(const char* s) {\n"
|
||||
" make(s, strlen(s));\n"
|
||||
"}\n"
|
||||
"void f() {\n"
|
||||
" make(\"my-utf8-payload\");\n"
|
||||
"}\n"
|
||||
"void f2() {\n"
|
||||
" make(\"false\");\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_multidim() {
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue