9575: false positive in fclose (#2540)

Fix false positive introduced by
0b7649ca9b

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.
This commit is contained in:
Ken-Patrick Lehrmann 2020-02-17 10:25:30 +01:00 committed by GitHub
parent 8e1dddf7e8
commit 7044c17599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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;

View File

@ -2048,6 +2048,7 @@ private:
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(returnedValue); // #9298
TEST_CASE(fclose_false_positive); // #9575
}
void returnedValue() { // #9298
@ -2059,6 +2060,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
}
void fclose_false_positive() { // #9575
check("int f(FILE *fp) { return fclose(fp); }");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestLeakAutoVarStrcpy)