diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index a16bed5c2..b29ae887a 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 95f568c93..6f07ae542 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3175,6 +3175,36 @@ private: "}\n", "test.c"); ASSERT_EQUALS("", errout.str()); + { + const char argDirectionsTestXmlData[] = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; + + 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"