Fix FP leakNoVarFunctionCall (#4243)

* Fix #10857 FN: leakNoVarFunctionCall

* Fix TODO

* Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) )

* #11155 FN: leakNoVarFunctionCall (ternary operator)

* Fix #11157 FN: leakNoVarFunctionCall (switch condition)

* Fix FN constStatement

* Fix FP leakNoVarFunctionCall

* Fix FP leakNoVarFunctionCall

* Format

* Fix FP leakNoVarFunctionCall with unknown function

* Fix FP leakNoVarFunctionCall
This commit is contained in:
chrchr-github 2022-06-30 13:05:28 +02:00 committed by GitHub
parent 06b408ea20
commit d8e64b4cbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -1011,6 +1011,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
functionName == "return") functionName == "return")
continue; continue;
if (Token::simpleMatch(tok->next()->astParent(), "(")) // passed to another function
continue;
if (!tok->isKeyword() && mSettings->library.isNotLibraryFunction(tok)) if (!tok->isKeyword() && mSettings->library.isNotLibraryFunction(tok))
continue; continue;
if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP())) if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP()))

View File

@ -2417,7 +2417,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct S {\n" check("struct S {\n"
" static void load(const QString & projPath) {\n" " static void load(const QString& projPath) {\n"
" if (proj_)\n" " if (proj_)\n"
" return;\n" " return;\n"
" proj_ = new ProjectT(projPath);\n" " proj_ = new ProjectT(projPath);\n"
@ -2427,6 +2427,12 @@ private:
" static Core::ProjectBase* proj_;\n" " static Core::ProjectBase* proj_;\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void f(const std::string& s, int n) {\n"
" std::unique_ptr<char[]> u;\n"
" u.reset(strcpy(new char[n], s.c_str()));\n"
"};\n");
ASSERT_EQUALS("", errout.str());
} }
void missingAssignment() { void missingAssignment() {