Fixed false positive in CheckUninitVar and internal message

This commit is contained in:
PKEuS 2015-01-21 22:26:44 +01:00
parent 94c3c45350
commit c3e47f7eaa
2 changed files with 8 additions and 2 deletions

View File

@ -1438,7 +1438,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
}
// bailout on ternary operator. TODO: This can be solved much better. For example, if the variable is not accessed in the branches of the ternary operator, we could just continue.
if (Token::Match(tok, "?")) {
if (tok->str() == "?") {
return true;
}
@ -1706,6 +1706,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
assignment = true;
break;
}
if (alloc && parent->str() == "(") {
if (_settings->library.functionpure.find(parent->strAt(-1)) == _settings->library.functionpure.end()) {
assignment = true;
break;
}
}
parent = parent->astParent();
}
if (!assignment)

View File

@ -1470,7 +1470,7 @@ private:
" Fred *fred = malloc(sizeof(Fred));\n"
" x(fred->f);\n"
"};");
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Memory is allocated but not initialized: fred\n", errout.str());
ASSERT_EQUALS("", errout.str());
checkUninitVarB("void foo(char *s)\n"
"{\n"