Uninitialized variables; Fix FP when assigning struct members
This commit is contained in:
parent
8d97cce81b
commit
7d84b8f1bc
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue