Uninitialized variables: Fixed false positive when taking address of uninitialized array that is a struct member

This commit is contained in:
Daniel Marjamäki 2013-03-20 16:59:45 +01:00
parent 1b9c1c03fa
commit a79354d51c
2 changed files with 13 additions and 2 deletions

View File

@ -1092,8 +1092,11 @@ void CheckUninitVar::checkScope(const Scope* scope)
for (std::size_t j = 0U; j < symbolDatabase->classAndStructScopes.size(); ++j) {
const Scope *scope2 = symbolDatabase->classAndStructScopes[j];
if (scope2->className == structname && scope2->numConstructors == 0U) {
for (std::list<Variable>::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it)
checkScopeForVariable(scope, tok, *i, NULL, NULL, it->name());
for (std::list<Variable>::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it) {
const Variable &var = *it;
if (!var.isArray())
checkScopeForVariable(scope, tok, *i, NULL, NULL, var.name());
}
}
}
}

View File

@ -2708,6 +2708,14 @@ private:
" if (foo(&s_d.type)){}\n"
"}");
ASSERT_EQUALS("", errout.str());
// address of member
checkUninitVar2("struct AB { int a[10]; int b; };\n"
"void f() {\n"
" struct AB ab;\n"
" int *p = ab.a;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void uninitvar2_while() {