Skip to content

Commit 169b136

Browse files
committed
Fix #12612 FP uninitvar with pointer alias in subfunction
1 parent 741fb09 commit 169b136

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/vf_analyzers.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ struct ValueFlowAnalyzer : Analyzer {
586586
} else if (ref->isUnaryOp("*") && !match(ref->astOperand1())) {
587587
const Token* lifeTok = nullptr;
588588
for (const ValueFlow::Value& v:ref->astOperand1()->values()) {
589-
if (!v.isLocalLifetimeValue())
589+
if (!v.isLocalLifetimeValue() && !v.isSubFunctionLifetimeValue())
590590
continue;
591591
if (lifeTok)
592592
return Action::None;
@@ -1046,7 +1046,12 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
10461046
}
10471047

10481048
bool match(const Token* tok) const override {
1049-
return values.count(tok->varId()) > 0;
1049+
if (tok->varId() == 0)
1050+
return false;
1051+
return values.count(tok->varId()) > 0 ||
1052+
std::any_of(values.begin(), values.end(), [&](const std::pair<nonneg int, ValueFlow::Value>& p) {
1053+
return p.second.isUninitValue() && p.second.tokvalue->varId() == tok->varId();
1054+
});
10501055
}
10511056

10521057
ProgramState getProgramState() const override {

test/testuninitvar.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -4387,6 +4387,17 @@ class TestUninitVar : public TestFixture {
43874387
" return f(i, 0);\n"
43884388
"}");
43894389
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str());
4390+
4391+
valueFlowUninit("char *f (char *b) {\n" // #12612
4392+
" char* p = b;\n"
4393+
" *p = '\\0';\n"
4394+
" return b;\n"
4395+
"}\n"
4396+
"void g() {\n"
4397+
" char a[24];\n"
4398+
" f(a);\n"
4399+
"}\n");
4400+
ASSERT_EQUALS("", errout_str());
43904401
}
43914402

43924403
void uninitStructMember() { // struct members

0 commit comments

Comments
 (0)