Fix ctuuninitvar false positive for struct that is partly initialized

This commit is contained in:
Daniel Marjamäki 2023-03-13 20:55:11 +01:00
parent 322a1a5e8c
commit a4d2178f3c
2 changed files with 13 additions and 0 deletions

View File

@ -402,6 +402,8 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
argtok = addr ? addr : isReferenceArg(argtok);
if (!argtok || argtok->values().size() != 1U)
continue;
if (argtok->variable() && argtok->variable()->isClass())
continue;
const ValueFlow::Value &v = argtok->values().front();
if (v.valueType == ValueFlow::Value::ValueType::UNINIT && !v.isInconclusive()) {

View File

@ -6597,6 +6597,17 @@ private:
" return n;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Using argument i that points at uninitialized variable n\n", errout.str());
ctu("typedef struct { int type; int id; } Stem;\n"
"void lookupStem(recodeCtx h, Stem *stem) {\n"
" i = stem->type & STEM_VERT;\n"
"}\n"
"void foo() {\n"
" Stem stem;\n"
" stem.type = 0;\n"
" lookupStem(h, &stem);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};