Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfg/selinux.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
<noreturn>false</noreturn>
<use-retval/>
<leak-ignore/>
<arg nr="1" direction="inout">
<arg nr="1" direction="inout" indirect="1">
<not-uninit/>
<not-null/>
</arg>
Expand Down
6 changes: 3 additions & 3 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@
<returnValue type="int"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="inout">
<arg nr="1" direction="inout" indirect="1">
<not-null/>
<not-uninit/>
</arg>
Expand Down Expand Up @@ -1929,7 +1929,7 @@
<returnValue type="int"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="inout">
<arg nr="1" direction="inout" indirect="1">
<not-null/>
<not-uninit/>
</arg>
Expand Down Expand Up @@ -2255,7 +2255,7 @@
<returnValue type="int"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="inout">
<arg nr="1" direction="inout" indirect="1">
<not-null/>
<not-uninit/>
</arg>
Expand Down
6 changes: 3 additions & 3 deletions cfg/windows.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5595,7 +5595,7 @@ HFONT CreateFont(
<function name="strlwr">
<returnValue type="char *">arg1</returnValue>
<noreturn>false</noreturn>
<arg nr="1" direction="inout">
<arg nr="1" direction="inout" indirect="1">
<not-null/>
<not-uninit/>
<strz/>
Expand Down Expand Up @@ -5963,7 +5963,7 @@ HFONT CreateFont(
<arg nr="2" direction="out">
<not-null/>
</arg>
<arg nr="3" direction="inout">
<arg nr="3" direction="inout" indirect="1">
<not-null/>
<not-uninit/>
</arg>
Expand Down Expand Up @@ -6009,7 +6009,7 @@ HFONT CreateFont(
<arg nr="4" direction="out">
<not-null/>
</arg>
<arg nr="5" direction="inout">
<arg nr="5" direction="inout" indirect="1">
<not-null/>
<not-uninit/>
</arg>
Expand Down
21 changes: 1 addition & 20 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/checkvaarg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& 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() {
Expand Down
Loading