From 346704b2e2d087fc56780d638fec48ec8b052dda Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 23 Feb 2018 12:51:37 +0100 Subject: [PATCH] windows library: Mainly add socket functions, some other stuff and tests. (#1095) Add Windows Socket 2 type/function configuration. There are still many (microsoft specific) socket functions that are not yet configured. Add configuration for GetUserName(), GetWindowText() and _fileno(). On Windows __wchar_t is a synonym for wchar_t, so an according define is added. --- cfg/windows.cfg | 531 +++++++++++++++++++++++++++++++++++++++++++ test/cfg/windows.cpp | 63 +++++ 2 files changed, 594 insertions(+) diff --git a/cfg/windows.cfg b/cfg/windows.cfg index 36983b178..5d391ea8f 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -787,6 +787,12 @@ + + + + + + @@ -802,6 +808,12 @@ + + + + + + @@ -844,6 +856,12 @@ + + + + + + @@ -880,6 +898,12 @@ + + + + + + @@ -4341,6 +4365,512 @@ HFONT CreateFont( + + + false + + + + + + + + + + + + + false + + + + + + + + + + + + + + 1: + + + + + false + + + + + + + + + + + + + + false + + + + + + + + false + + + + + + + + + + + + + + + false + + + + + + + + + + + + 0: + + + + + false + + + + + + + + + + + + 0: + + + + + false + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + + + + + + false + + + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + 0: + + + + + false + + + + + + + + + + + + false + + + + + + + + + + + + false + + + + + false + + + + + + false + + + + + + + + false + + + + + + + + + @@ -4357,4 +4887,5 @@ HFONT CreateFont( + diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index d9d561950..d598a71ca 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -116,6 +116,21 @@ void validCode() _stprintf(bufTC, _countof(bufTC), TEXT("%d"), 2); _tprintf(TEXT("%s"), bufTC); + DWORD dwordInit = 0; + GetUserName(NULL, &dwordInit); + dwordInit = 10; + GetUserName(bufTC, _countof(bufTC)); + + WSADATA wsaData = {0}; + WSAStartup(2, &wsaData); + SOCKET sock = socket(1, 2, 3); + u_long ulongInit = 0; + ioctlsocket(sock, FIONBIO, &ulongInit); + if (sock != INVALID_SOCKET) { + closesocket(sock); + } + WSACleanup(); + // Valid Library usage, no leaks, valid arguments HINSTANCE hInstLib = LoadLibrary(L"My.dll"); FreeLibrary(hInstLib); @@ -194,6 +209,31 @@ void nullPointer() GetSystemTime(NULL); // cppcheck-suppress nullPointer GetLocalTime(NULL); + + // TODO: error message: arg1 must not be nullptr if variable pointed to by arg2 is not 0 + DWORD dwordInit = 10; + GetUserName(NULL, &dwordInit); + TCHAR bufTC[10]; + // cppcheck-suppress nullPointer + GetUserName(bufTC, NULL); + + SOCKET socketInit = {0}; + sockaddr sockaddrUninit; + int intInit = 0; + int *pIntNull = NULL; + char charArray[] = "test"; + // cppcheck-suppress nullPointer + WSAStartup(1, NULL); + // cppcheck-suppress nullPointer + bind(socketInit, NULL, 5); + // cppcheck-suppress nullPointer + getpeername(socketInit, NULL, &intInit); + // cppcheck-suppress nullPointer + getpeername(socketInit, &sockaddrUninit, pIntNull); + // cppcheck-suppress nullPointer + getsockopt(sockInit, 1, 2, NULL, &intInit); + // cppcheck-suppress nullPointer + getsockopt(sockInit, 1, 2, charArray, pIntNull); } void memleak_malloca() @@ -303,6 +343,14 @@ void resourceLeak_OpenEventW() // cppcheck-suppress resourceLeak } +void resourceLeak_socket() +{ + SOCKET sock; + // cppcheck-suppress unreadVariable + sock = socket(1, 2, 3); + // cppcheck-suppress resourceLeak +} + void ignoredReturnValue() { // cppcheck-suppress leakReturnValNotUsed @@ -350,6 +398,12 @@ void ignoredReturnValue() HeapAlloc(GetProcessHeap(), 0, 10); // cppcheck-suppress leakReturnValNotUsed HeapReAlloc(GetProcessHeap(), 0, 1, 0); + + // cppcheck-suppress leakReturnValNotUsed + socket(1, 2, 3); + + // cppcheck-suppress ignoredReturnValue + _fileno(stdio); } void invalidFunctionArg() @@ -435,6 +489,15 @@ void uninitvar() DWORD dwordUninit; // cppcheck-suppress uninitvar SetLastError(dwordUninit); + + DWORD dwordUninit; + // cppcheck-suppress uninitvar + GetUserName(NULL, &dwordUninit); + + FILE *pFileUninit; + // cppcheck-suppress uninitvar + // cppcheck-suppress ignoredReturnValue + _fileno(pFileUninit); } void errorPrintf()