Fix #12012 (FP: uninitvar, address of variable is casted to uintptr_t that is passed to function) (#5494)
This commit is contained in:
parent
db5f75f741
commit
c4fe5ac8b7
|
@ -2470,6 +2470,16 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
|
||||||
if (!arg->isConst() && arg->isReference())
|
if (!arg->isConst() && arg->isReference())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (addressOf && tok1->astParent()->isUnaryOp("&")) {
|
||||||
|
const Token* castToken = tok1->astParent();
|
||||||
|
while (castToken->astParent()->isCast())
|
||||||
|
castToken = castToken->astParent();
|
||||||
|
if (Token::Match(castToken->astParent(), ",|(") &&
|
||||||
|
castToken->valueType() &&
|
||||||
|
castToken->valueType()->isIntegral() &&
|
||||||
|
castToken->valueType()->pointer == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!conclusive && inconclusive) {
|
if (!conclusive && inconclusive) {
|
||||||
*inconclusive = true;
|
*inconclusive = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5590,6 +5590,16 @@ private:
|
||||||
values = tokenValues(code, "& y :", ValueFlow::Value::ValueType::UNINIT);
|
values = tokenValues(code, "& y :", ValueFlow::Value::ValueType::UNINIT);
|
||||||
ASSERT_EQUALS(1, values.size());
|
ASSERT_EQUALS(1, values.size());
|
||||||
ASSERT_EQUALS(true, values.front().isUninitValue());
|
ASSERT_EQUALS(true, values.front().isUninitValue());
|
||||||
|
|
||||||
|
// #12012 - function init variable
|
||||||
|
code = "void init(uintptr_t p);\n"
|
||||||
|
"void fp() {\n"
|
||||||
|
" int x;\n"
|
||||||
|
" init((uintptr_t)&x);\n"
|
||||||
|
" if (x > 0) {}\n"
|
||||||
|
"}\n";
|
||||||
|
values = tokenValues(code, "x >", ValueFlow::Value::ValueType::UNINIT);
|
||||||
|
ASSERT_EQUALS(0, values.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowConditionExpressions() {
|
void valueFlowConditionExpressions() {
|
||||||
|
|
Loading…
Reference in New Issue