Skip to content

Commit

Permalink
9575: false positive in fclose
Browse files Browse the repository at this point in the history
Fix false positive introduced by
0b7649c

Only return the function token from checkTokenInsideExpression when it
might be one the argument (hence keeping a pointer to one of them).
Otherwise, we can directly skip to the token after the function call.
  • Loading branch information
Ken-Patrick Lehrmann committed Feb 17, 2020
1 parent 8e1dddf commit b65e3fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,11 @@ const Token * CheckLeakAutoVar::checkTokenInsideExpression(const Token * const t
if (alloc.type == 0)
alloc.status = VarInfo::NOALLOC;
functionCall(tok, openingPar, varInfo, alloc, nullptr);
return openingPar;
const std::string &returnValue = mSettings->library.returnValue(tok);
if (returnValue.compare(0, 3, "arg") == 0)
// the function returns one of its argument, we need to process a potential assignment
return openingPar;
return openingPar->link();
}

return nullptr;
Expand Down
7 changes: 7 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,7 @@ class TestLeakAutoVarStrcpy: public TestFixture {
LOAD_LIB_2(settings.library, "std.cfg");

TEST_CASE(returnedValue); // #9298
TEST_CASE(fclose_false_positive); // #9575
}

void returnedValue() { // #9298
Expand All @@ -2059,6 +2060,12 @@ class TestLeakAutoVarStrcpy: public TestFixture {
"}");
ASSERT_EQUALS("", errout.str());
}

void fclose_false_positive() { // #9575
check("int f(FILE *fp) { return fclose(fp); }");
ASSERT_EQUALS("", errout.str());
}

};

REGISTER_TEST(TestLeakAutoVarStrcpy)
Expand Down

0 comments on commit b65e3fc

Please sign in to comment.