windows library: Add function configurations with tests (#1079)

Add function configurations with tests for:
GetLocalTime, GetSystemTime, GetLastError, SetLastError,
AllocateAndInitializeSid, FreeSid, HeapAlloc, HeapReAlloc, HeapFree,
HeapSize, HeapValidate and GetProcessHeap.
test/cfg/runtests.sh: Enable --inconclusive for the windows tests to
avoid some issues in the future.
This commit is contained in:
Sebastian 2018-02-02 11:28:54 +01:00 committed by GitHub
parent d9952dc6cf
commit c235930539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 214 additions and 3 deletions

View File

@ -1176,6 +1176,10 @@
<!-- Do not add _alloca here. It is automatically freed! -->
<dealloc>_freea</dealloc>
</memory>
<memory>
<alloc init="true" arg="11">AllocateAndInitializeSid</alloc>
<dealloc>FreeSid</dealloc>
</memory>
<function name="RtlCompareMemory">
<noreturn>false</noreturn>
<leak-ignore/>
@ -4188,6 +4192,161 @@ HFONT CreateFont(
</arg>
<warn severity="style" reason="Obsolete" alternatives="_strupr,_strupr_s"/>
</function>
<!--void WINAPI GetLocalTime(_Out_ LPSYSTEMTIME lpSystemTime);-->
<!--void WINAPI GetSystemTime(_Out_ LPSYSTEMTIME lpSystemTime);-->
<function name="GetLocalTime,GetSystemTime">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-null/>
</arg>
</function>
<!--DWORD WINAPI GetLastError(void);-->
<function name="GetLastError">
<noreturn>false</noreturn>
<returnValue type="DWORD"/>
<use-retval/>
</function>
<!--void WINAPI SetLastError(_In_ DWORD dwErrCode);-->
<function name="SetLastError">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--BOOL WINAPI AllocateAndInitializeSid(
_In_ PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
_In_ BYTE nSubAuthorityCount,
_In_ DWORD dwSubAuthority0,
_In_ DWORD dwSubAuthority1,
_In_ DWORD dwSubAuthority2,
_In_ DWORD dwSubAuthority3,
_In_ DWORD dwSubAuthority4,
_In_ DWORD dwSubAuthority5,
_In_ DWORD dwSubAuthority6,
_In_ DWORD dwSubAuthority7,
_Out_ PSID *pSid);-->
<function name="AllocateAndInitializeSid">
<noreturn>false</noreturn>
<returnValue type="BOOL"/>
<arg nr="1">
<not-null/>
</arg>
<arg nr="11">
<not-null/>
</arg>
</function>
<!--PVOID WINAPI FreeSid(_In_ PSID pSid);-->
<function name="FreeSid">
<noreturn>false</noreturn>
<returnValue type="PVOID"/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--LPVOID WINAPI HeapAlloc(
_In_ HANDLE hHeap,
_In_ DWORD dwFlags,
_In_ SIZE_T dwBytes);-->
<function name="HeapAlloc">
<noreturn>false</noreturn>
<returnValue type="LPVOID"/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<!--LPVOID WINAPI HeapReAlloc(
_In_ HANDLE hHeap,
_In_ DWORD dwFlags,
_In_ LPVOID lpMem,
_In_ SIZE_T dwBytes);-->
<function name="HeapReAlloc">
<noreturn>false</noreturn>
<returnValue type="LPVOID"/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-null/>
<not-uninit/>
</arg>
<arg nr="4">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<!--BOOL WINAPI HeapFree(
_In_ HANDLE hHeap,
_In_ DWORD dwFlags,
_In_ LPVOID lpMem);-->
<function name="HeapFree">
<noreturn>false</noreturn>
<returnValue type="BOOL"/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-null/>
<not-uninit/>
</arg>
</function>
<!--SIZE_T WINAPI HeapSize(
_In_ HANDLE hHeap,
_In_ DWORD dwFlags,
_In_ LPCVOID lpMem);-->
<function name="HeapSize">
<noreturn>false</noreturn>
<returnValue type="SIZE_T"/>
<use-retval/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
</function>
<!--BOOL WINAPI HeapValidate(
_In_ HANDLE hHeap,
_In_ DWORD dwFlags,
_In_opt_ LPCVOID lpMem);-->
<function name="HeapValidate">
<noreturn>false</noreturn>
<returnValue type="BOOL"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
</function>
<!--HANDLE WINAPI GetProcessHeap(void);-->
<function name="GetProcessHeap">
<noreturn>false</noreturn>
<returnValue type="HANDLE"/>
<use-retval/>
</function>
<podtype name="LARGE_INTEGER" sign="s" size="8"/>
<podtype name="POINTER_SIGNED" sign="s"/>
<podtype name="POINTER_UNSIGNED" sign="u"/>

View File

@ -40,6 +40,6 @@ ${CPPCHECK} ${CPPCHECK_OPT} ${DIR}std.cpp
# windows.cpp
# Syntax check via g++ does not work because it can not find a valid windows.h
#${CXX} ${CXX_OPT} ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --platform=win32A ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --platform=win32W ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --platform=win64 ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32A ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32W ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win64 ${DIR}windows.cpp

View File

@ -79,6 +79,21 @@ void validCode()
void *pMem2 = _alloca(10);
memset(pMem2, 0, 10);
SYSTEMTIME st;
GetSystemTime(&st);
DWORD lastError = GetLastError();
SetLastError(lastError);
PSID pEveryoneSID = NULL;
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID)
FreeSid(pEveryoneSID);
LPVOID pMem = HeapAlloc(GetProcessHeap(), 0, 10);
pMem = HeapReAlloc(GetProcessHeap(), 0, pMem, 0);
HeapFree(GetProcessHeap(), 0, pMem);
// Valid Library usage, no leaks, valid arguments
HINSTANCE hInstLib = LoadLibrary(L"My.dll");
FreeLibrary(hInstLib);
@ -152,6 +167,11 @@ void nullPointer()
// cppcheck-suppress struprCalled
// cppcheck-suppress nullPointer
strupr(str);
// cppcheck-suppress nullPointer
GetSystemTime(NULL);
// cppcheck-suppress nullPointer
GetLocalTime(NULL);
}
void memleak_malloca()
@ -161,6 +181,24 @@ void memleak_malloca()
// cppcheck-suppress memleak
}
void memleak_AllocateAndInitializeSid()
{
PSID pEveryoneSID = NULL;
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID)
// TODO: enable when #6994 is implemented cppcheck-suppress memleak
}
void memleak_HeapAlloc()
{
LPVOID pMem;
pMem = HeapAlloc(GetProcessHeap(), 0, 10);
HeapValidate(GetProcessHeap(), 0, pMem);
// cppcheck-suppress unreadVariable
SIZE_T memSize = HeapSize(GetProcessHeap(), 0, pMem);
// cppcheck-suppress memleak
}
void resourceLeak_CreateSemaphoreA()
{
HANDLE hSemaphore;
@ -280,6 +318,16 @@ void ignoredReturnValue()
_malloca(10);
// cppcheck-suppress ignoredReturnValue
_alloca(5);
// cppcheck-suppress ignoredReturnValue
GetLastError();
// cppcheck-suppress ignoredReturnValue
GetProcessHeap()
// cppcheck-suppress leakReturnValNotUsed
HeapAlloc(GetProcessHeap(), 0, 10);
// cppcheck-suppress leakReturnValNotUsed
HeapReAlloc(GetProcessHeap(), 0, 1, 0);
}
void invalidFunctionArg()
@ -361,6 +409,10 @@ void uninitvar()
// cppcheck-suppress struprCalled
// cppcheck-suppress uninitvar
strupr(buf_uninit);
DWORD dwordUninit;
// cppcheck-suppress uninitvar
SetLastError(dwordUninit);
}
void allocDealloc_GetModuleHandleEx()