Skip to content

Commit abd8b11

Browse files
Add tests for windows config
There should be no Cppcheck warning when checking for 0 and `INVALID_HANDLE_VALUE` or `INVALID_SOCKET`
1 parent 7e50271 commit abd8b11

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: test/cfg/windows.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
#include <atlstr.h>
2323
#include <string>
2424

25+
void invalidHandle_CreateFile(LPCWSTR lpFileName)
26+
{
27+
HANDLE file = CreateFile(lpFileName, GENERIC_READ, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
28+
29+
// INVALID_HANDLE_VALUE is not the same as 0
30+
if (file != INVALID_HANDLE_VALUE && file) {}
31+
32+
// cppcheck-suppress resourceLeak
33+
}
34+
35+
void invalid_socket()
36+
{
37+
SOCKET sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
38+
39+
// INVALID_SOCKET is not the same as 0
40+
if (sock != INVALID_SOCKET && sock) {}
41+
42+
// cppcheck-suppress resourceLeak
43+
}
44+
2545
void resourceLeak_OpenThread(const DWORD dwDesiredAccess, const BOOL bInheritHandle, const DWORD dwThreadId)
2646
{
2747
HANDLE proc = OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId);

0 commit comments

Comments
 (0)