checkuninitvar.cpp: Use argument direction "out" info from library cfg (#1730)
CheckUninitVar::isMemberVariableAssignment uses argument direction "out" now also to check for assignment when the member variable is handed over to a function by reference. testuninitvar.cpp: Improve tests, use a test library configuration.
This commit is contained in:
parent
17033976f5
commit
c8003d47e2
|
@ -1205,6 +1205,8 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
|
|||
const Library::ArgumentChecks::Direction argDirection = mSettings->library.getArgDirection(ftok, 1 + argumentNumber);
|
||||
if (argDirection == Library::ArgumentChecks::Direction::DIR_IN)
|
||||
return false;
|
||||
else if (argDirection == Library::ArgumentChecks::Direction::DIR_OUT)
|
||||
return true;
|
||||
}
|
||||
|
||||
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : nullptr;
|
||||
|
|
|
@ -3175,6 +3175,36 @@ private:
|
|||
"}\n", "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
{
|
||||
const char argDirectionsTestXmlData[] = "<?xml version=\"1.0\"?>\n"
|
||||
"<def>\n"
|
||||
" <function name=\"uninitvar_funcArgInTest\">\n"
|
||||
" <arg nr=\"1\" direction=\"in\"/>\n"
|
||||
" </function>\n"
|
||||
" <function name=\"uninitvar_funcArgOutTest\">\n"
|
||||
" <arg nr=\"1\" direction=\"out\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
|
||||
ASSERT_EQUALS(true, settings.library.loadxmldata(argDirectionsTestXmlData, sizeof(argDirectionsTestXmlData) / sizeof(argDirectionsTestXmlData[0])));
|
||||
|
||||
checkUninitVar("struct AB { int a; };\n"
|
||||
"void f(void) {\n"
|
||||
" struct AB ab;\n"
|
||||
" uninitvar_funcArgInTest(&ab);\n"
|
||||
" x = ab;\n"
|
||||
"}\n", "test.c");
|
||||
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.a\n", errout.str());
|
||||
|
||||
checkUninitVar("struct AB { int a; };\n"
|
||||
"void f(void) {\n"
|
||||
" struct AB ab;\n"
|
||||
" uninitvar_funcArgOutTest(&ab);\n"
|
||||
" x = ab;\n"
|
||||
"}\n", "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
checkUninitVar("struct AB { int a; int b; };\n"
|
||||
"void do_something(const struct AB ab);\n"
|
||||
"void f(void) {\n"
|
||||
|
|
Loading…
Reference in New Issue