Bug hunting; Improved uninit checking for function calls with constant parameter
This commit is contained in:
parent
d303510c78
commit
e19ef6ac62
|
@ -173,8 +173,17 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!value.isUninit() && uninitStructMember.empty())
|
bool uninitData = false;
|
||||||
|
if (!value.isUninit() && uninitStructMember.empty()) {
|
||||||
|
if (Token::Match(tok->astParent(), "[(,]")) {
|
||||||
|
if (const auto* arrayValue = dynamic_cast<const ExprEngine::ArrayValue*>(&value)) {
|
||||||
|
uninitData = arrayValue->data.size() >= 1 && arrayValue->data[0].value->isUninit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!uninitData)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// lhs in assignment
|
// lhs in assignment
|
||||||
if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1())
|
if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1())
|
||||||
|
@ -239,8 +248,11 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
|
||||||
const Variable *argvar = parent->astOperand1()->function()->getArgumentVar(count);
|
const Variable *argvar = parent->astOperand1()->function()->getArgumentVar(count);
|
||||||
if (argvar && argvar->isReference() && !argvar->isConst())
|
if (argvar && argvar->isReference() && !argvar->isConst())
|
||||||
return;
|
return;
|
||||||
|
if (uninitData && argvar && !argvar->isConst())
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else if (uninitData)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid FP for array declaration
|
// Avoid FP for array declaration
|
||||||
|
|
|
@ -69,7 +69,7 @@ private:
|
||||||
|
|
||||||
check("char foo(const char id[]);\n"
|
check("char foo(const char id[]);\n"
|
||||||
"void bar() { char data[10]; foo(data); }");
|
"void bar() { char data[10]; foo(data); }");
|
||||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Cannot determine that 'data' is initialized\n", errout.str());
|
||||||
|
|
||||||
check("char foo(char id[]);\n"
|
check("char foo(char id[]);\n"
|
||||||
"void bar() { char data[10]; foo(data); }");
|
"void bar() { char data[10]; foo(data); }");
|
||||||
|
|
Loading…
Reference in New Issue