Fixed #4907 (False positive "uninitStructMember" on structs with unions)
This commit is contained in:
parent
64454068ec
commit
ee14ea4fc2
|
@ -1101,11 +1101,22 @@ void CheckUninitVar::checkScope(const Scope* scope)
|
||||||
for (std::size_t j = 0U; j < symbolDatabase->classAndStructScopes.size(); ++j) {
|
for (std::size_t j = 0U; j < symbolDatabase->classAndStructScopes.size(); ++j) {
|
||||||
const Scope *scope2 = symbolDatabase->classAndStructScopes[j];
|
const Scope *scope2 = symbolDatabase->classAndStructScopes[j];
|
||||||
if (scope2->className == structname && scope2->numConstructors == 0U) {
|
if (scope2->className == structname && scope2->numConstructors == 0U) {
|
||||||
|
bool hasUnion = false;
|
||||||
|
for (std::list<Scope*>::const_iterator childscope = scope2->nestedList.begin();
|
||||||
|
childscope != scope2->nestedList.end();
|
||||||
|
++childscope) {
|
||||||
|
if ((*childscope)->type == Scope::eUnion)
|
||||||
|
hasUnion = true;
|
||||||
|
}
|
||||||
|
if (hasUnion)
|
||||||
|
break;
|
||||||
|
|
||||||
for (std::list<Variable>::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it) {
|
for (std::list<Variable>::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it) {
|
||||||
const Variable &var = *it;
|
const Variable &var = *it;
|
||||||
if (!var.isArray())
|
if (!var.isArray())
|
||||||
checkScopeForVariable(scope, tok, *i, NULL, NULL, var.name());
|
checkScopeForVariable(scope, tok, *i, NULL, NULL, var.name());
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2788,6 +2788,20 @@ private:
|
||||||
"}\n", "test.c");
|
"}\n", "test.c");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("struct PIXEL {\n" // union in struct #4970
|
||||||
|
" union {\n"
|
||||||
|
" struct { unsigned char red,green,blue,alpha; };\n"
|
||||||
|
" unsigned int color;\n"
|
||||||
|
" };\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"unsigned char f() {\n"
|
||||||
|
" struct PIXEL p1;\n"
|
||||||
|
" p1.color = 255;\n"
|
||||||
|
" return p1.red;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// return
|
// return
|
||||||
checkUninitVar2("struct AB { int a; int b; };\n"
|
checkUninitVar2("struct AB { int a; int b; };\n"
|
||||||
"void f(void) {\n"
|
"void f(void) {\n"
|
||||||
|
|
Loading…
Reference in New Issue