Fix #12012 (FP: uninitvar, address of variable is casted to uintptr_t that is passed to function) (#5494)

This commit is contained in:
Daniel Marjamäki 2023-09-28 13:47:11 +02:00 committed by GitHub
parent db5f75f741
commit c4fe5ac8b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -2470,6 +2470,16 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
if (!arg->isConst() && arg->isReference())
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) {
*inconclusive = true;
}

View File

@ -5590,6 +5590,16 @@ private:
values = tokenValues(code, "& y :", ValueFlow::Value::ValueType::UNINIT);
ASSERT_EQUALS(1, values.size());
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() {