Skip to content

Commit ec77e31

Browse files
Fix #14640 FP uninitvar (address in init list) (#8434)
1 parent 3417a0c commit ec77e31

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3418,7 +3418,7 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
34183418
// variable init/constructor call?
34193419
if (!func && ftok->variable() && ftok == ftok->variable()->nameToken()) {
34203420
// STL types or containers don't initialize external variables
3421-
if (ftok->variable()->isStlType() || (ftok->variable()->valueType() && ftok->variable()->valueType()->container))
3421+
if (indirect == 0 && (ftok->variable()->isStlType() || (ftok->variable()->valueType() && ftok->variable()->valueType()->container)))
34223422
return ExprUsage::Used;
34233423
// TODO: resolve multiple constructors
34243424
if (ftok->variable()->type() && ftok->variable()->type()->classScope) {

test/testuninitvar.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7784,6 +7784,13 @@ class TestUninitVar : public TestFixture {
77847784
" *s.p = 0;\n"
77857785
"}\n");
77867786
ASSERT_EQUALS("", errout_str());
7787+
7788+
valueFlowUninit("void f() {\n"
7789+
" int x;\n"
7790+
" std::vector<int*> v{ &x };\n"
7791+
" *v[0] = 0;\n"
7792+
"}\n");
7793+
ASSERT_EQUALS("", errout_str());
77877794
}
77887795

77897796
void valueFlowUninitForLoop()

0 commit comments

Comments
 (0)