Bug hunting; Make bughuntingUninit check a bit less noisy about const parameters

This commit is contained in:
Daniel Marjamäki 2020-12-08 13:34:46 +01:00
parent 99cb65b4b2
commit 6d7ddde1b5
2 changed files with 16 additions and 5 deletions

View File

@ -2631,13 +2631,15 @@ static ExprEngine::ValuePtr createVariableValue(const Variable &var, Data &data)
return value; return value;
} }
if (valueType->type == ValueType::Type::RECORD) { if (valueType->type == ValueType::Type::RECORD) {
bool init = true; bool uninitData = true;
if (var.isLocal() && !var.isStatic()) { if (var.isLocal() && !var.isStatic()) {
init = valueType->typeScope && uninitData = !valueType->typeScope ||
valueType->typeScope->definedType && !valueType->typeScope->definedType ||
valueType->typeScope->definedType->needInitialization != Type::NeedInitialization::False; valueType->typeScope->definedType->needInitialization != Type::NeedInitialization::False;
} }
return createStructVal(valueType->typeScope, init, data); if (var.isArgument() && var.isConst())
uninitData = false;
return createStructVal(valueType->typeScope, uninitData, data);
} }
if (valueType->smartPointerType) { if (valueType->smartPointerType) {
auto structValue = createStructVal(valueType->smartPointerType->classScope, var.isLocal() && !var.isStatic(), data); auto structValue = createStructVal(valueType->smartPointerType->classScope, var.isLocal() && !var.isStatic(), data);

View File

@ -222,6 +222,15 @@ private:
check("void foo(int *p) { if (p) *p=0; }"); check("void foo(int *p) { if (p) *p=0; }");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("class C {\n"
"public:\n"
" C();\n"
" int x;\n"
"};\n"
"\n"
"void foo(const C &c) { int x = c.x; }");
ASSERT_EQUALS("", errout.str());
} }
void uninit_malloc() { void uninit_malloc() {