Fixed recently introduced FP in checkuninitvar.cpp if address of variable is passed to a function
This commit is contained in:
parent
4c76f71499
commit
da5a04f071
|
@ -1745,12 +1745,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
|||
|
||||
// is this a function call?
|
||||
if (start && Token::Match(start->previous(), "%var% (")) {
|
||||
const bool address(vartok->previous()->str() == "&");
|
||||
// check how function handle uninitialized data arguments..
|
||||
const Function *func = start->previous()->function();
|
||||
if (func) {
|
||||
const Variable *arg = func->getArgumentVar(argumentNumber);
|
||||
if (arg) {
|
||||
const bool address(vartok->previous()->str() == "&");
|
||||
const Token *argStart = arg->typeStartToken();
|
||||
if (!address && Token::Match(argStart, "struct| %type% [,)]"))
|
||||
return true;
|
||||
|
@ -1776,7 +1776,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
|||
bool isuninitbad = _settings->library.isuninitargbad(start->previous(), argumentNumber + 1);
|
||||
if (alloc)
|
||||
return isnullbad && isuninitbad;
|
||||
return isuninitbad;
|
||||
return isuninitbad && (!address || isnullbad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2884,6 +2884,24 @@ private:
|
|||
" return abc.a;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVarB("void write_packet() {\n"
|
||||
" time_t now0;\n"
|
||||
" time(&now0);\n"
|
||||
"}", "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVarB("void write_packet() {\n"
|
||||
" time_t* now0;\n"
|
||||
" time(now0);\n"
|
||||
"}", "test.c");
|
||||
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: now0\n", errout.str());
|
||||
|
||||
checkUninitVarB("void write_packet() {\n"
|
||||
" char now0;\n"
|
||||
" strcmp(&now0, sth);\n"
|
||||
"}", "test.c");
|
||||
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: now0\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar2_value() {
|
||||
|
|
Loading…
Reference in New Issue