Fix #11624 FP uninitvar with array passed to function (#4903)

This commit is contained in:
chrchr-github 2023-03-20 19:54:31 +01:00 committed by GitHub
parent 6316479782
commit 0d02c0a1a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -2412,7 +2412,7 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
// If const is applied to the pointer, then the value can still be modified
if (Token::simpleMatch(arg->typeEndToken(), "* const"))
return true;
if (!arg->isPointer() && (!arg->valueType() || arg->valueType()->type == ValueType::UNKNOWN_TYPE))
if (arg->isArray() || (!arg->isPointer() && (!arg->valueType() || arg->valueType()->type == ValueType::UNKNOWN_TYPE)))
return true;
}
if (!arg->isConst() && arg->isReference())

View File

@ -5416,6 +5416,19 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #11624
valueFlowUninit("const int N = 2;\n"
"void g(int a[N]) {\n"
" for (int i = 0; i < N; ++i)\n"
" a[i] = 1;\n"
"}\n"
"void f() {\n"
" int a[N];\n"
" g(a);\n"
" if (a[0]) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value