From c8c131f3750441bc8dc259cc0c861043e67d2df1 Mon Sep 17 00:00:00 2001 From: Christoph Strehle Date: Fri, 7 Jun 2024 15:08:01 +0200 Subject: [PATCH] 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);