From 1ad22ae23181479a136e04486fa3b0d0100a2aaa Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 31 Jan 2018 17:43:19 +0100 Subject: [PATCH] windows library: Add strlwr/strupr configuration, fixing tests (#1076) Add configuration for the deprecated strlwr/strupr functions with according warning. test/cfg/windows.cpp: Added tests for strlwr and strupr. Moved function call that does not return (FreeLibraryAndExitThread) to the end of the function to fix analysis that was silently aborted at that point (reported as issue #8378). --- cfg/windows.cfg | 22 ++++++++++++++++++++++ test/cfg/windows.cpp | 44 +++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/cfg/windows.cfg b/cfg/windows.cfg index 6675cc860..98a09c088 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -4166,6 +4166,28 @@ HFONT CreateFont( + + + arg1 + false + + + + + + + + + + arg1 + false + + + + + + + diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 71bcacd8a..25e204a0f 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -27,6 +27,11 @@ void validCode() // cppcheck-suppress lstrcatCalled lstrcat(buf, "test"); + // cppcheck-suppress strlwrCalled + strlwr(buf); + // cppcheck-suppress struprCalled + strupr(buf); + // Valid Mutex usage, no leaks, valid arguments HANDLE hMutex1; hMutex1 = CreateMutex(NULL, TRUE, NULL); @@ -41,17 +46,6 @@ void validCode() hMutex3 = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "sem"); CloseHandle(hMutex3); - // Valid Library usage, no leaks, valid arguments - HINSTANCE hInstLib = LoadLibrary(L"My.dll"); - FreeLibrary(hInstLib); - hInstLib = LoadLibraryA("My.dll"); - FreeLibrary(hInstLib); - hInstLib = LoadLibraryEx(L"My.dll", NULL, 0); - FreeLibrary(hInstLib); - hInstLib = LoadLibraryExW(L"My.dll", NULL, 0); - FreeLibrary(hInstLib); - hInstLib = ::LoadLibrary(L"My.dll"); - FreeLibraryAndExitThread(hInstLib, 0); // Valid Module usage, no leaks, valid arguments HMODULE hModule = GetModuleHandle(L"My.dll"); FreeLibrary(hModule); @@ -84,6 +78,18 @@ void validCode() // Memory from _alloca must not be freed void *pMem2 = _alloca(10); memset(pMem2, 0, 10); + + // Valid Library usage, no leaks, valid arguments + HINSTANCE hInstLib = LoadLibrary(L"My.dll"); + FreeLibrary(hInstLib); + hInstLib = LoadLibraryA("My.dll"); + FreeLibrary(hInstLib); + hInstLib = LoadLibraryEx(L"My.dll", NULL, 0); + FreeLibrary(hInstLib); + hInstLib = LoadLibraryExW(L"My.dll", NULL, 0); + FreeLibrary(hInstLib); + hInstLib = ::LoadLibrary(L"My.dll"); + FreeLibraryAndExitThread(hInstLib, 0); // Does not return! Must be at the end! } void bufferAccessOutOfBounds() @@ -138,6 +144,14 @@ void nullPointer() ResetEvent(hEvent); // cppcheck-suppress nullPointer SetEvent(hEvent); + + char *str = NULL; + // cppcheck-suppress strlwrCalled + // cppcheck-suppress nullPointer + strlwr(str); + // cppcheck-suppress struprCalled + // cppcheck-suppress nullPointer + strupr(str); } void memleak_malloca() @@ -339,6 +353,14 @@ void uninitvar() SetEvent(hEvent); // cppcheck-suppress uninitvar CloseHandle(hEvent); + + char buf_uninit[10]; + // cppcheck-suppress strlwrCalled + // cppcheck-suppress uninitvar + strlwr(buf_uninit); + // cppcheck-suppress struprCalled + // cppcheck-suppress uninitvar + strupr(buf_uninit); } void allocDealloc_GetModuleHandleEx()