Skip to content

Commit a4d2178

Browse files
committed
Fix ctuuninitvar false positive for struct that is partly initialized
1 parent 322a1a5 commit a4d2178

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/ctu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
402402
argtok = addr ? addr : isReferenceArg(argtok);
403403
if (!argtok || argtok->values().size() != 1U)
404404
continue;
405+
if (argtok->variable() && argtok->variable()->isClass())
406+
continue;
405407

406408
const ValueFlow::Value &v = argtok->values().front();
407409
if (v.valueType == ValueFlow::Value::ValueType::UNINIT && !v.isInconclusive()) {

test/testuninitvar.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6597,6 +6597,17 @@ class TestUninitVar : public TestFixture {
65976597
" return n;\n"
65986598
"}\n");
65996599
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Using argument i that points at uninitialized variable n\n", errout.str());
6600+
6601+
ctu("typedef struct { int type; int id; } Stem;\n"
6602+
"void lookupStem(recodeCtx h, Stem *stem) {\n"
6603+
" i = stem->type & STEM_VERT;\n"
6604+
"}\n"
6605+
"void foo() {\n"
6606+
" Stem stem;\n"
6607+
" stem.type = 0;\n"
6608+
" lookupStem(h, &stem);\n"
6609+
"}\n");
6610+
ASSERT_EQUALS("", errout.str());
66006611
}
66016612
};
66026613

0 commit comments

Comments
 (0)