Uninitialized variables; Fix FP when assigning struct members

This commit is contained in:
Daniel Marjamäki 2021-05-25 16:13:32 +02:00
parent 8d97cce81b
commit 7d84b8f1bc
2 changed files with 13 additions and 0 deletions

View File

@ -1218,6 +1218,10 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
// * Passing address in RHS to pointer variable
{
const Token *tok = derefValue ? derefValue : valueExpr;
if (alloc == NO_ALLOC) {
while (tok->valueType() && tok->valueType()->pointer == 0 && Token::simpleMatch(tok->astParent(), "."))
tok = tok->astParent();
}
if (Token::simpleMatch(tok->astParent(), "=")) {
if (astIsLhs(tok))
return nullptr;

View File

@ -3516,6 +3516,15 @@ private:
"}\n", "test.c");
ASSERT_EQUALS("", errout.str());
checkUninitVar("struct Cstring { char *text; int size, alloc; };\n"
"int maybe();\n"
"void f() {\n"
" Cstring res;\n"
" if ( ! maybe() ) return;\n" // <- fp goes away if this is removed
" ( ((res).text = (void*)0), ((res).size = (res).alloc = 0) );\n" // <- fp goes away if parentheses are removed
"}");
ASSERT_EQUALS("", errout.str());
{
const char argDirectionsTestXmlData[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"