Revert "UninitVar: Better checking in whole program analysis"

This reverts commit b2bdc2687b.
This commit is contained in:
Daniel Marjamäki 2018-01-25 17:05:57 +01:00
parent b2bdc2687b
commit f73da16e94
3 changed files with 10 additions and 8 deletions

View File

@ -937,10 +937,10 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
}
if (Token::Match(vartok->previous(), "++|--|%cop%")) {
if ((!_tokenizer || _tokenizer->isCPP()) && alloc == ARRAY && Token::Match(vartok->tokAt(-4), "& %var% =|( *"))
if (_tokenizer->isCPP() && alloc == ARRAY && Token::Match(vartok->tokAt(-4), "& %var% =|( *"))
return false;
if (_tokenizer && _tokenizer->isCPP() && Token::Match(vartok->previous(), ">>|<<")) {
if (_tokenizer->isCPP() && Token::Match(vartok->previous(), ">>|<<")) {
const Token* tok2 = vartok->previous();
if (Token::simpleMatch(tok2->astOperand1(), ">>"))
return false; // Looks like stream operator, initializes the variable
@ -1012,7 +1012,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
return true;
}
if (_tokenizer && _tokenizer->isCPP() && Token::Match(vartok->next(), "<<|>>")) {
if (_tokenizer->isCPP() && Token::Match(vartok->next(), "<<|>>")) {
// Is this calculation done in rhs?
const Token *tok = vartok;
while (Token::Match(tok, "%name%|.|::"))
@ -1320,7 +1320,7 @@ CheckUninitVar::MyFileInfo::FunctionArg::FunctionArg(const Tokenizer *tokenizer,
location.linenr = tok->linenr();
}
bool CheckUninitVar::isUnsafeFunction(const Scope *scope, int argnr, const Token **tok) const
static bool isUnsafeFunction(const Scope *scope, int argnr, const Token **tok)
{
const Variable * const argvar = scope->function->getArgumentVar(argnr);
if (!argvar->isPointer())
@ -1328,7 +1328,11 @@ bool CheckUninitVar::isUnsafeFunction(const Scope *scope, int argnr, const Token
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
if (tok2->variable() != argvar)
continue;
if (!isVariableUsage(tok2, true, Alloc::ARRAY))
if (!Token::Match(tok2->astParent(), "*|["))
return false;
while (Token::Match(tok2->astParent(), "*|["))
tok2 = tok2->astParent();
if (!Token::Match(tok2->astParent(),"%cop%"))
return false;
*tok = tok2;
return true;

View File

@ -155,8 +155,6 @@ public:
void uninitStructMemberError(const Token *tok, const std::string &membername);
private:
bool isUnsafeFunction(const Scope *scope, int argnr, const Token **tok) const;
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckUninitVar c(nullptr, settings, errorLogger);

View File

@ -3996,7 +3996,7 @@ private:
void ctu() {
ctu("void f(int *p) {\n"
" a = *p;\n"
" a = *p + 3;\n"
"}\n"
"int main() {\n"
" int x;\n"