From 790593a644113664ec82cd6c9c9d1f88757dda63 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 2 Sep 2022 18:35:27 +0200 Subject: [PATCH 01/10] Fix #9653 FP leakReturnValNotUsed although (void) is specified --- lib/checkmemoryleak.cpp | 14 +++++++++++++- test/testmemleak.cpp | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index be1c508e226..5df5e5e1380 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1056,7 +1056,7 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) // get ast parent, skip casts const Token *parent = isNew ? tok->astParent() : tok->next()->astParent(); - while (parent && parent->str() == "(" && !parent->astOperand2()) + while (parent && parent->isCast()) parent = parent->astParent(); bool warn = true; @@ -1065,11 +1065,23 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) warn = typeTok && (typeTok->isStandardType() || mSettings->library.detectContainer(typeTok)); } + auto isCastToVoid = [](const Token* parTok) -> bool { + if (parTok->astParent() && parTok->astParent()->isCast()) { + if (parTok->astParent()->astOperand2()) { + return Token::simpleMatch(parTok->astParent()->astOperand1(), "static_cast < void >"); + } + return parTok->astParent()->astOperand1() && Token::simpleMatch(parTok->astParent(), "( void )"); + } + return false; + }; + if (!parent && warn) { // Check if we are in a C++11 constructor const Token * closingBrace = Token::findmatch(tok, "}|;"); if (closingBrace->str() == "}" && Token::Match(closingBrace->link()->tokAt(-1), "%name%") && (!isNew && precedes(tok, closingBrace->link()))) continue; + if (isCastToVoid(tok->next())) + continue; returnValueNotUsedError(tok, tok->str()); } else if (Token::Match(parent, "%comp%|!|,|%oror%|&&|:")) { if (parent->astParent() && parent->str() == ",") diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 1dd2b8d22d6..c6ebdc2139a 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2312,6 +2312,7 @@ class TestMemleakNoVar : public TestFixture { TEST_CASE(getAllocationType); TEST_CASE(crash1); // #10729 + TEST_CASE(castToVoid); // #9653 } void functionParameter() { @@ -2842,6 +2843,15 @@ class TestMemleakNoVar : public TestFixture { "}"); ASSERT_EQUALS("", errout.str()); } + + void castToVoid() { + check("void f() {\n" // #9653 + " (void)open(devnull, O_RDONLY);\n" + " static_cast(open(devnull, O_WRONLY));\n" + " static_cast(open(devnull, O_WRONLY));\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Return value of allocation function 'open' is not stored.\n", errout.str()); + } }; REGISTER_TEST(TestMemleakNoVar) From de6bfc98f69c3490a2c56e5a536ff9d280bc3d42 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 2 Sep 2022 20:58:29 +0200 Subject: [PATCH 02/10] Remove casts --- test/cfg/windows.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 9c69787471d..74b46dc1b2f 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -960,27 +960,27 @@ HANDLE test_CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar - (void) CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, uninit_dwCreationFlags, lpThreadId); + CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, uninit_dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar - (void) CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, uninit_lpParameter, dwCreationFlags, lpThreadId); + CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, uninit_lpParameter, dwCreationFlags, lpThreadId); // @todo uninitvar shall be reported // cppcheck-suppress leakReturnValNotUsed - (void) CreateThread(lpThreadAttributes, dwStackSize, uninit_lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + CreateThread(lpThreadAttributes, dwStackSize, uninit_lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar - (void) CreateThread(lpThreadAttributes, uninit_dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + CreateThread(lpThreadAttributes, uninit_dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // @todo uninitvar shall be reported // cppcheck-suppress leakReturnValNotUsed - (void) CreateThread(uninit_lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + CreateThread(uninit_lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress nullPointer - (void) CreateThread(lpThreadAttributes, dwStackSize, 0, lpParameter, dwCreationFlags, lpThreadId); + CreateThread(lpThreadAttributes, dwStackSize, 0, lpParameter, dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress invalidFunctionArg - (void) CreateThread(lpThreadAttributes, -1, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + CreateThread(lpThreadAttributes, -1, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // no warning shall be shown for return CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); From abcc939909ef8fc7bb214321593f7bb03d97cfbe Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 2 Sep 2022 23:13:22 +0200 Subject: [PATCH 03/10] Avoid duplicate warnings --- lib/checkfunctions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 56476a442a7..bed206c7093 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -269,9 +269,9 @@ void CheckFunctions::checkIgnoredReturnValue() if ((!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) && !WRONG_DATA(!tok->next()->astOperand1(), tok)) { const Library::UseRetValType retvalTy = mSettings->library.getUseRetValType(tok); - if (mSettings->severity.isEnabled(Severity::warning) && - ((retvalTy == Library::UseRetValType::DEFAULT) || - (tok->function() && tok->function()->isAttributeNodiscard()))) + const bool warn = (tok->function() && tok->function()->isAttributeNodiscard()) || // avoid duplicate warnings for resource-allocating functions + (retvalTy == Library::UseRetValType::DEFAULT && mSettings->library.getReallocFuncInfo(tok) == nullptr); + if (mSettings->severity.isEnabled(Severity::warning) && warn) ignoredReturnValueError(tok, tok->next()->astOperand1()->expressionString()); else if (mSettings->severity.isEnabled(Severity::style) && retvalTy == Library::UseRetValType::ERROR_CODE) From 48653994b60e3a45864970d5dd3c937fcfbefd02 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 2 Sep 2022 23:42:12 +0200 Subject: [PATCH 04/10] Fix --- lib/checkfunctions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index bed206c7093..b84856e127e 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -270,7 +270,7 @@ void CheckFunctions::checkIgnoredReturnValue() !WRONG_DATA(!tok->next()->astOperand1(), tok)) { const Library::UseRetValType retvalTy = mSettings->library.getUseRetValType(tok); const bool warn = (tok->function() && tok->function()->isAttributeNodiscard()) || // avoid duplicate warnings for resource-allocating functions - (retvalTy == Library::UseRetValType::DEFAULT && mSettings->library.getReallocFuncInfo(tok) == nullptr); + (retvalTy == Library::UseRetValType::DEFAULT && mSettings->library.getAllocFuncInfo(tok) == nullptr); if (mSettings->severity.isEnabled(Severity::warning) && warn) ignoredReturnValueError(tok, tok->next()->astOperand1()->expressionString()); else if (mSettings->severity.isEnabled(Severity::style) && From 1d92ddbc959961eb72ff4b53214ea86ec7c1ed0e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 3 Sep 2022 00:15:43 +0200 Subject: [PATCH 05/10] Remove suppressions --- test/cfg/gtk.c | 9 --------- test/cfg/posix.c | 3 --- test/cfg/windows.cpp | 3 --- 3 files changed, 15 deletions(-) diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c index 0ca810479ce..47624972b8f 100644 --- a/test/cfg/gtk.c +++ b/test/cfg/gtk.c @@ -73,7 +73,6 @@ void validCode(int argInt, GHashTableIter * hash_table_iter, GHashTable * hash_t void g_malloc_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_malloc(8); @@ -86,7 +85,6 @@ void g_malloc_test() void g_malloc0_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_malloc0(8); @@ -99,7 +97,6 @@ void g_malloc0_test() void g_malloc_n_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_malloc_n(8, 1); @@ -112,7 +109,6 @@ void g_malloc_n_test() void g_malloc0_n_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_malloc0_n(8, 1); @@ -125,7 +121,6 @@ void g_malloc0_n_test() void g_try_malloc_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_try_malloc(8); @@ -138,7 +133,6 @@ void g_try_malloc_test() void g_try_malloc0_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_try_malloc0(8); @@ -151,7 +145,6 @@ void g_try_malloc0_test() void g_try_malloc_n_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_try_malloc_n(8, 1); @@ -164,7 +157,6 @@ void g_try_malloc_n_test() void g_try_malloc0_n_test() { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_try_malloc0_n(8, 1); @@ -374,7 +366,6 @@ void g_error_new_test() printf("%p", pNew1); g_error_free(pNew1); - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed g_error_new(1, -2, "a %d", 1); diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 195f86f8575..4c368931e9b 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -838,7 +838,6 @@ void nullPointer(char *p, int fd, pthread_mutex_t mutex) // cppcheck-suppress unreadVariable // cppcheck-suppress nullPointer int ret = access(NULL, 0); - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress nullPointer fdopen(fd, NULL); @@ -978,7 +977,6 @@ void noleak(int x, int y, int z) void ignoredReturnValue(void *addr, int fd) { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed mmap(addr, 255, PROT_NONE, MAP_PRIVATE, fd, 0); // cppcheck-suppress ignoredReturnValue @@ -1065,7 +1063,6 @@ void uninitvar(int fd) // cppcheck-suppress uninitvar int access_ret = access("file", x3); - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar fdopen(x4, "rw"); diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 74b46dc1b2f..26f4f979755 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -681,7 +681,6 @@ void ignoredReturnValue() // cppcheck-suppress leakReturnValNotUsed CreateEventEx(NULL, L"test", CREATE_EVENT_INITIAL_SET, EVENT_MODIFY_STATE); - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed _malloca(10); // cppcheck-suppress ignoredReturnValue @@ -693,10 +692,8 @@ void ignoredReturnValue() // cppcheck-suppress ignoredReturnValue GetProcessHeap(); - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed HeapAlloc(GetProcessHeap(), 0, 10); - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed HeapReAlloc(GetProcessHeap(), 0, 1, 0); From 8fe5cbfa513093af297270342112deedb7b7ed59 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 3 Sep 2022 00:37:24 +0200 Subject: [PATCH 06/10] Remove --- test/cfg/std.c | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cfg/std.c b/test/cfg/std.c index e60e9063704..cd4bfc977a6 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -287,7 +287,6 @@ void pointerLessThanZero_aligned_alloc(void) void unusedRetVal_aligned_alloc(void) { - // cppcheck-suppress ignoredReturnValue // cppcheck-suppress leakReturnValNotUsed aligned_alloc(8, 16); } From 81ce8b5db3c50cc200efbc20c02f9e29bf530e6e Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 20 Sep 2022 15:39:40 +0200 Subject: [PATCH 07/10] Check for open("/dev/null", ...) --- lib/checkmemoryleak.cpp | 24 ++++++++++++------------ lib/checkmemoryleak.h | 5 +++++ test/cfg/windows.cpp | 12 ++++++------ test/testmemleak.cpp | 11 +++++------ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 5df5e5e1380..19c7da7841e 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -274,6 +274,16 @@ bool CheckMemoryLeak::isReopenStandardStream(const Token *tok) const return false; } +bool CheckMemoryLeak::isOpenDevNull(const Token *tok) const +{ + if (mSettings_->posix() && tok->str() == "open" && numberOfArguments(tok) == 2) { + const Token* arg = getArguments(tok).at(0); + if (Token::Match(arg, "\"/dev/null\"")) + return true; + } + return false; +} + //-------------------------------------------------------------------------- @@ -1053,6 +1063,8 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) if (isReopenStandardStream(tok)) continue; + if (isOpenDevNull(tok)) + continue; // get ast parent, skip casts const Token *parent = isNew ? tok->astParent() : tok->next()->astParent(); @@ -1065,23 +1077,11 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) warn = typeTok && (typeTok->isStandardType() || mSettings->library.detectContainer(typeTok)); } - auto isCastToVoid = [](const Token* parTok) -> bool { - if (parTok->astParent() && parTok->astParent()->isCast()) { - if (parTok->astParent()->astOperand2()) { - return Token::simpleMatch(parTok->astParent()->astOperand1(), "static_cast < void >"); - } - return parTok->astParent()->astOperand1() && Token::simpleMatch(parTok->astParent(), "( void )"); - } - return false; - }; - if (!parent && warn) { // Check if we are in a C++11 constructor const Token * closingBrace = Token::findmatch(tok, "}|;"); if (closingBrace->str() == "}" && Token::Match(closingBrace->link()->tokAt(-1), "%name%") && (!isNew && precedes(tok, closingBrace->link()))) continue; - if (isCastToVoid(tok->next())) - continue; returnValueNotUsedError(tok, tok->str()); } else if (Token::Match(parent, "%comp%|!|,|%oror%|&&|:")) { if (parent->astParent() && parent->str() == ",") diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 3edfb4a39a3..5eae5509de6 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -118,6 +118,11 @@ class CPPCHECKLIB CheckMemoryLeak { * @param tok token to check */ bool isReopenStandardStream(const Token *tok) const; + /** + * Check if token opens /dev/null + * @param tok token to check + */ + bool isOpenDevNull(const Token *tok) const; /** * Report that there is a memory leak (new/malloc/etc) * @param tok token where memory is leaked diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 26f4f979755..e86cfd48a01 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -960,24 +960,24 @@ HANDLE test_CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, uninit_dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar - CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, uninit_lpParameter, dwCreationFlags, lpThreadId); + (void) CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, uninit_lpParameter, dwCreationFlags, lpThreadId); // @todo uninitvar shall be reported // cppcheck-suppress leakReturnValNotUsed - CreateThread(lpThreadAttributes, dwStackSize, uninit_lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + (void) CreateThread(lpThreadAttributes, dwStackSize, uninit_lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar - CreateThread(lpThreadAttributes, uninit_dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + (void) CreateThread(lpThreadAttributes, uninit_dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // @todo uninitvar shall be reported // cppcheck-suppress leakReturnValNotUsed - CreateThread(uninit_lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + (void) CreateThread(uninit_lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress nullPointer - CreateThread(lpThreadAttributes, dwStackSize, 0, lpParameter, dwCreationFlags, lpThreadId); + (void) CreateThread(lpThreadAttributes, dwStackSize, 0, lpParameter, dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress invalidFunctionArg - CreateThread(lpThreadAttributes, -1, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + (void) CreateThread(lpThreadAttributes, -1, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); // no warning shall be shown for return CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c6ebdc2139a..d44a8c81628 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2312,7 +2312,7 @@ class TestMemleakNoVar : public TestFixture { TEST_CASE(getAllocationType); TEST_CASE(crash1); // #10729 - TEST_CASE(castToVoid); // #9653 + TEST_CASE(openDevNull); // #9653 } void functionParameter() { @@ -2844,13 +2844,12 @@ class TestMemleakNoVar : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void castToVoid() { + void openDevNull() { check("void f() {\n" // #9653 - " (void)open(devnull, O_RDONLY);\n" - " static_cast(open(devnull, O_WRONLY));\n" - " static_cast(open(devnull, O_WRONLY));\n" + " (void)open(\"/dev/null\", O_RDONLY);\n" + " open(\"/dev/null\", O_WRONLY));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Return value of allocation function 'open' is not stored.\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } }; REGISTER_TEST(TestMemleakNoVar) From 89a93bded011763b055adb5ec3e0503907b86ba0 Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 20 Sep 2022 15:42:18 +0200 Subject: [PATCH 08/10] Undo --- test/cfg/windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index e86cfd48a01..ae52271c95c 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -957,7 +957,7 @@ HANDLE test_CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar - CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, uninit_dwCreationFlags, lpThreadId); + (void) CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, uninit_dwCreationFlags, lpThreadId); // cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress uninitvar (void) CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, uninit_lpParameter, dwCreationFlags, lpThreadId); From bf9e6b520bf136ed812290ce9587c8747e2d78ae Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 20 Sep 2022 16:14:27 +0200 Subject: [PATCH 09/10] Fix test --- test/testmemleak.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index d44a8c81628..a6aa5ae8840 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2847,7 +2847,7 @@ class TestMemleakNoVar : public TestFixture { void openDevNull() { check("void f() {\n" // #9653 " (void)open(\"/dev/null\", O_RDONLY);\n" - " open(\"/dev/null\", O_WRONLY));\n" + " open(\"/dev/null\", O_WRONLY);\n" "}\n"); ASSERT_EQUALS("", errout.str()); } From 672f8eb454b21a10ff01ebe4a1bc4dd62c4e9de5 Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 20 Sep 2022 16:54:35 +0200 Subject: [PATCH 10/10] simpleMatch --- lib/checkmemoryleak.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 19c7da7841e..402c7c252e2 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -278,7 +278,7 @@ bool CheckMemoryLeak::isOpenDevNull(const Token *tok) const { if (mSettings_->posix() && tok->str() == "open" && numberOfArguments(tok) == 2) { const Token* arg = getArguments(tok).at(0); - if (Token::Match(arg, "\"/dev/null\"")) + if (Token::simpleMatch(arg, "\"/dev/null\"")) return true; } return false;