Fixed false positive in CheckUninitVar and internal message
This commit is contained in:
parent
94c3c45350
commit
c3e47f7eaa
|
@ -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.
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1706,6 +1706,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
||||||
assignment = true;
|
assignment = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (alloc && parent->str() == "(") {
|
||||||
|
if (_settings->library.functionpure.find(parent->strAt(-1)) == _settings->library.functionpure.end()) {
|
||||||
|
assignment = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
parent = parent->astParent();
|
parent = parent->astParent();
|
||||||
}
|
}
|
||||||
if (!assignment)
|
if (!assignment)
|
||||||
|
|
|
@ -1470,7 +1470,7 @@ private:
|
||||||
" Fred *fred = malloc(sizeof(Fred));\n"
|
" Fred *fred = malloc(sizeof(Fred));\n"
|
||||||
" x(fred->f);\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"
|
checkUninitVarB("void foo(char *s)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue