Fix #11459 uninitvar false positive (#5011)

* Fix #11459 uninitvar false positive

* Format
This commit is contained in:
chrchr-github 2023-04-25 21:01:44 +02:00 committed by GitHub
parent 9ea223b367
commit 023e79b6c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -4959,6 +4959,11 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
if (varTok && varTok->variable() && varTok->variable()->type() && varTok->variable()->type()->classScope)
scope = varTok->variable()->type()->classScope;
}
else if (Token::simpleMatch(tok->astParent(), "[")) {
const Token* varTok = tok->astParent()->previous();
if (varTok && varTok->variable() && varTok->variable()->scope() && Token::simpleMatch(tok->astParent()->astOperand1(), "::"))
scope = varTok->variable()->scope();
}
for (std::vector<Scope *>::const_iterator s = scope->nestedList.cbegin(); s != scope->nestedList.cend(); ++s) {
enumerator = (*s)->findEnumerator(tokStr);

View File

@ -5998,6 +5998,21 @@ private:
" if ((cp = getenv(envar)) != NULL) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #11459
valueFlowUninit("struct S {\n"
" enum E { N = 3 };\n"
" static const int A[N];\n"
" static void f();\n"
"};\n"
"const int S::A[N] = { 0, 1, 2 };\n"
"void S::f() {\n"
" int tmp[N];\n"
" for (int i = 0; i < N; i++)\n"
" tmp[i] = 0;\n"
" if (tmp[0]) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value