Fixed #1087 (uninitialized data not detected 'char z = *str')

This commit is contained in:
Daniel Marjamäki 2009-12-30 20:37:11 +01:00
parent 461d826eff
commit ae3ff7d376
2 changed files with 16 additions and 1 deletions

View File

@ -1722,7 +1722,7 @@ private:
if (Token::Match(tok.tokAt(-2), "[,(=] *"))
{
use(foundError, checks, &tok);
use_pointer(foundError, checks, &tok);
return &tok;
}
}
@ -1744,6 +1744,12 @@ private:
use_array(foundError, checks, *it);
}
else if (Token::Match(&tok, "! %var% )"))
{
use(foundError, checks, &tok);
return false;
}
return ExecutionPath::parseCondition(tok, checks);
}
};

View File

@ -1403,6 +1403,15 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char *s = malloc(100);\n"
" if (!s)\n"
" return;\n"
" char c = *s;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Data is allocated but not initialized: s\n", errout.str());
// struct..
checkUninitVar("void f()\n"
"{\n"