From c86617888ddbd16abfd56bf1f76016d9f67c2c21 Mon Sep 17 00:00:00 2001 From: Christoph Strehle Date: Fri, 7 Jun 2024 07:30:28 +0200 Subject: [PATCH 1/4] Fix defines for boost test macros The _MESSAGE macros were causing an unusedScopedObject warning because the created string was not used. Casting the message to void fixed the warnings. Add missing `BOOST_AUTO_TEST_CASE_TEMPLATE` macro accidentally removed with d1b3670017e101a89c7eb11198d741c5199d42d4 --- cfg/boost.cfg | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cfg/boost.cfg b/cfg/boost.cfg index fc6836da757..3a09f2a778d 100644 --- a/cfg/boost.cfg +++ b/cfg/boost.cfg @@ -35,7 +35,7 @@ - + @@ -43,7 +43,7 @@ - + @@ -51,7 +51,7 @@ - + @@ -84,6 +84,7 @@ + From ea62369f142bc5374b769b06ca85620311569cc5 Mon Sep 17 00:00:00 2001 From: Christoph Strehle Date: Fri, 7 Jun 2024 07:33:24 +0200 Subject: [PATCH 2/4] Fix wrong defined in windows.cfg INVALID_HANDLE_VALUE is defined as `-1` in the windows sdk INVALID_SOCKET is defined as `~0` in the windwos sdk Add missing generic rights --- cfg/windows.cfg | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cfg/windows.cfg b/cfg/windows.cfg index 26448004810..b3cbe7c3a41 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -7119,8 +7119,8 @@ HFONT CreateFont( - - + + @@ -14178,6 +14178,10 @@ HFONT CreateFont( + + + + From 7e5027157ba2058c7aa773ba531a069ff46f3579 Mon Sep 17 00:00:00 2001 From: Christoph Strehle Date: Fri, 7 Jun 2024 15:04:00 +0200 Subject: [PATCH 3/4] Add tests for boost config Add one test for the `BOOST__MESSAGE` macros Add one test for the `BOOST_AUTO_TEST_CASE_TEMPLATE` --- test/cfg/boost.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/cfg/boost.cpp b/test/cfg/boost.cpp index eb4e742227a..52d2e1be80b 100644 --- a/test/cfg/boost.cpp +++ b/test/cfg/boost.cpp @@ -17,6 +17,7 @@ #include #include #include +#include BOOST_FORCEINLINE void boost_forceinline_test() {} @@ -104,4 +105,25 @@ void lock_guard_finiteLifetime(boost::mutex& m) { // cppcheck-suppress unusedScopedObject boost::lock_guard{ m }; -} \ No newline at end of file +} + +BOOST_AUTO_TEST_SUITE(my_auto_test_suite) + +BOOST_AUTO_TEST_CASE(test_message_macros) +{ + bool my_bool = false; + BOOST_WARN_MESSAGE(my_bool, "warn"); + BOOST_CHECK_MESSAGE(my_bool, "check"); + BOOST_REQUIRE_MESSAGE(my_bool, "require"); + + BOOST_WARN_MESSAGE(my_bool, "my_bool was: " << my_bool); +} + +using test_types_w_tuples = std::tuple; +BOOST_AUTO_TEST_CASE_TEMPLATE(my_tuple_test, T, test_types_w_tuples) +{ + // cppcheck-suppress valueFlowBailoutIncompleteVar + BOOST_TEST(sizeof(T) == 4U); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From abd8b11258e1f7118b9c256b2e4dcebfd36fdea1 Mon Sep 17 00:00:00 2001 From: Christoph Strehle Date: Fri, 7 Jun 2024 15:08:01 +0200 Subject: [PATCH 4/4] Add tests for windows config There should be no Cppcheck warning when checking for 0 and `INVALID_HANDLE_VALUE` or `INVALID_SOCKET` --- test/cfg/windows.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 5f2e6555ead..1ff314028fc 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -22,6 +22,26 @@ #include #include +void invalidHandle_CreateFile(LPCWSTR lpFileName) +{ + HANDLE file = CreateFile(lpFileName, GENERIC_READ, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + + // INVALID_HANDLE_VALUE is not the same as 0 + if (file != INVALID_HANDLE_VALUE && file) {} + + // cppcheck-suppress resourceLeak +} + +void invalid_socket() +{ + SOCKET sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP); + + // INVALID_SOCKET is not the same as 0 + if (sock != INVALID_SOCKET && sock) {} + + // cppcheck-suppress resourceLeak +} + void resourceLeak_OpenThread(const DWORD dwDesiredAccess, const BOOL bInheritHandle, const DWORD dwThreadId) { HANDLE proc = OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId);