diff --git a/cfg/selinux.cfg b/cfg/selinux.cfg index e2d7ac34dc3..31a48c6da5e 100644 --- a/cfg/selinux.cfg +++ b/cfg/selinux.cfg @@ -219,7 +219,7 @@ false - + diff --git a/cfg/std.cfg b/cfg/std.cfg index fd9f4cfb62b..e282dd99995 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1665,7 +1665,7 @@ false - + @@ -1929,7 +1929,7 @@ false - + @@ -2255,7 +2255,7 @@ false - + diff --git a/cfg/windows.cfg b/cfg/windows.cfg index 646b0c46f6f..6a0bd111afa 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -5595,7 +5595,7 @@ HFONT CreateFont( arg1 false - + @@ -5963,7 +5963,7 @@ HFONT CreateFont( - + @@ -6009,7 +6009,7 @@ HFONT CreateFont( - + diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 85d63d03dee..265ff2b8638 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2466,17 +2466,6 @@ static bool isTrivialConstructor(const Token* tok) return false; } -static bool isArray(const Token* tok) -{ - if (!tok) - return false; - if (tok->variable()) - return tok->variable()->isArray(); - if (Token::simpleMatch(tok, ".")) - return isArray(tok->astOperand2()); - return false; -} - bool isMutableExpression(const Token* tok) { if (!tok) @@ -2545,18 +2534,10 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti const Library::ArgumentChecks::Direction argDirection = settings.library.getArgDirection(tok, 1 + argnr, indirect); if (argDirection == Library::ArgumentChecks::Direction::DIR_IN) return false; - if (argDirection == Library::ArgumentChecks::Direction::DIR_OUT) + if (argDirection == Library::ArgumentChecks::Direction::DIR_OUT || argDirection == Library::ArgumentChecks::Direction::DIR_INOUT) return true; const bool requireNonNull = settings.library.isnullargbad(tok, 1 + argnr); - if (argDirection == Library::ArgumentChecks::Direction::DIR_INOUT) { - if (indirect == 0 && isArray(tok1)) - return true; - const bool requireInit = settings.library.isuninitargbad(tok, 1 + argnr); - // Assume that if the variable must be initialized then the indirection is 1 - if (indirect > 0 && requireInit && requireNonNull) - return true; - } if (Token::simpleMatch(tok->tokAt(-2), "std :: tie")) return true; // if the library says 0 is invalid diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 96c65ea41a2..8151957a7d7 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -73,7 +73,7 @@ void CheckVaarg::va_start_argument() if (var && var->index() + 2 < function->argCount() && printWarnings) { auto it = function->argumentList.end(); std::advance(it, -2); - wrongParameterTo_va_start_error(tok, var->name(), it->name()); // cppcheck-suppress derefInvalidIterator // FP due to isVariableChangedByFunctionCall() + wrongParameterTo_va_start_error(tok, var->name(), it->name()); } tok = tok->linkAt(1); } diff --git a/test/teststl.cpp b/test/teststl.cpp index 29cd85f5759..92933c37449 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -5339,6 +5339,13 @@ class TestStl : public TestFixture { " return it;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\n", errout_str()); + + check("int f(const std::vector& v) {\n" // #11895 + " auto it = v.end();\n" + " std::advance(it, -2);\n" + " return *it;\n" + "}\n", dinit(CheckOptions, $.inconclusive = true)); + ASSERT_EQUALS("", errout_str()); } void loopAlgoElementAssign() {