Bug hunting; avoid false positives for structs/classes with constructors
This commit is contained in:
parent
7cb65b7f67
commit
e9281babc4
|
@ -2567,8 +2567,15 @@ static ExprEngine::ValuePtr createVariableValue(const Variable &var, Data &data)
|
||||||
data.addConstraints(value, var.nameToken());
|
data.addConstraints(value, var.nameToken());
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (valueType->type == ValueType::Type::RECORD)
|
if (valueType->type == ValueType::Type::RECORD) {
|
||||||
return createStructVal(valueType->typeScope, var.isLocal() && !var.isStatic(), data);
|
bool init = true;
|
||||||
|
if (var.isLocal() && !var.isStatic()) {
|
||||||
|
init = valueType->typeScope &&
|
||||||
|
valueType->typeScope->definedType &&
|
||||||
|
valueType->typeScope->definedType->needInitialization != Type::NeedInitialization::False;
|
||||||
|
}
|
||||||
|
return createStructVal(valueType->typeScope, init, 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);
|
||||||
auto size = std::make_shared<ExprEngine::IntRange>(data.getNewSymbolName(), 1, ~0UL);
|
auto size = std::make_shared<ExprEngine::IntRange>(data.getNewSymbolName(), 1, ~0UL);
|
||||||
|
|
|
@ -39,6 +39,7 @@ private:
|
||||||
TEST_CASE(uninit_array);
|
TEST_CASE(uninit_array);
|
||||||
TEST_CASE(uninit_function_par);
|
TEST_CASE(uninit_function_par);
|
||||||
TEST_CASE(uninit_malloc);
|
TEST_CASE(uninit_malloc);
|
||||||
|
TEST_CASE(uninit_struct);
|
||||||
TEST_CASE(ctu);
|
TEST_CASE(ctu);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -98,6 +99,17 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Cannot determine that '*p' is initialized\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Cannot determine that '*p' is initialized\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninit_struct() {
|
||||||
|
// Assume that constructors initialize all members
|
||||||
|
// TODO whole program analysis
|
||||||
|
check("struct Data { Data(); int x; }\n"
|
||||||
|
"void foo() {\n"
|
||||||
|
" Data data;\n"
|
||||||
|
" x = data.x;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void ctu() {
|
void ctu() {
|
||||||
check("void init(int &x) {\n"
|
check("void init(int &x) {\n"
|
||||||
" x = 1;\n"
|
" x = 1;\n"
|
||||||
|
|
Loading…
Reference in New Issue