windows library: Enhance Event function configuration, add tests (#1064)

This commit is contained in:
Sebastian 2018-01-29 14:08:56 +01:00 committed by GitHub
parent e8a262a1f2
commit 30b9391461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 3 deletions

View File

@ -960,7 +960,11 @@
<alloc init="true">OpenFileMapping</alloc>
<alloc init="true">CreateNamedPipe</alloc>
<alloc init="true">CreateEvent</alloc>
<alloc init="true">CreateEventA</alloc>
<alloc init="true">CreateEventW</alloc>
<alloc init="true">CreateEventEx</alloc>
<alloc init="true">CreateEventExA</alloc>
<alloc init="true">CreateEventExW</alloc>
<alloc init="true">CreateMutex</alloc>
<alloc init="true">CreateMutexA</alloc>
<alloc init="true">CreateMutexW</alloc>
@ -976,6 +980,8 @@
<alloc init="true">CreateTimerQueue</alloc>
<alloc init="true">CreateWaitableTimer</alloc>
<alloc init="true">OpenEvent</alloc>
<alloc init="true">OpenEventA</alloc>
<alloc init="true">OpenEventW</alloc>
<alloc init="true">OpenMutex</alloc>
<alloc init="true">OpenMutexA</alloc>
<alloc init="true">OpenMutexW</alloc>
@ -3752,7 +3758,7 @@ HFONT CreateFont(
_In_ BOOL bManualReset,
_In_ BOOL bInitialState,
_In_opt_ LPCTSTR lpName);-->
<function name="CreateEvent">
<function name="CreateEvent,CreateEventA,CreateEventW">
<noreturn>false</noreturn>
<returnValue type="HANDLE"/>
<arg nr="1">
@ -3775,7 +3781,7 @@ HFONT CreateFont(
_In_opt_ LPCTSTR lpName,
_In_ DWORD dwFlags,
_In_ DWORD dwDesiredAccess);-->
<function name="CreateEventEx">
<function name="CreateEventEx,CreateEventExA,CreateEventExW">
<noreturn>false</noreturn>
<returnValue type="HANDLE"/>
<arg nr="1">
@ -3799,7 +3805,7 @@ HFONT CreateFont(
_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ LPCTSTR lpName);-->
<function name="OpenEvent">
<function name="OpenEvent,OpenEventA,OpenEventW">
<noreturn>false</noreturn>
<returnValue type="HANDLE"/>
<arg nr="1">

View File

@ -59,6 +59,25 @@ void validCode()
FreeLibrary(hModule);
hModule = GetModuleHandle(NULL);
FreeLibrary(hModule);
// Valid Event usage, no leaks, valid arguments
HANDLE event;
event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (NULL != event) {
SetEvent(event);
CloseHandle(event);
}
event = OpenEvent(EVENT_ALL_ACCESS, FALSE, L"testevent");
if (NULL != event) {
PulseEvent(event);
SetEvent(event);
CloseHandle(event);
}
event = CreateEventEx(NULL, L"testevent3", CREATE_EVENT_INITIAL_SET, EVENT_MODIFY_STATE);
if (NULL != event) {
ResetEvent(event);
CloseHandle(event);
}
}
void bufferAccessOutOfBounds()
@ -102,6 +121,17 @@ void nullPointer()
HMODULE * phModule = NULL;
// cppcheck-suppress nullPointer
GetModuleHandleEx(0, NULL, phModule);
// cppcheck-suppress leakReturnValNotUsed
// cppcheck-suppress nullPointer
OpenEvent(EVENT_ALL_ACCESS, FALSE, NULL);
HANDLE hEvent = NULL;
// cppcheck-suppress nullPointer
PulseEvent(hEvent);
// cppcheck-suppress nullPointer
ResetEvent(hEvent);
// cppcheck-suppress nullPointer
SetEvent(hEvent);
}
void resourceLeak_CreateSemaphoreA()
@ -162,6 +192,30 @@ void resourceLeak_LoadLibrary()
// cppcheck-suppress resourceLeak
}
void resourceLeak_CreateEvent()
{
HANDLE hEvent;
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
SetEvent(hEvent);
// cppcheck-suppress resourceLeak
}
void resourceLeak_CreateEventExA()
{
HANDLE hEvent;
// cppcheck-suppress unreadVariable
hEvent = CreateEventExA(NULL, "test", CREATE_EVENT_INITIAL_SET, EVENT_MODIFY_STATE);
// cppcheck-suppress resourceLeak
}
void resourceLeak_OpenEventW()
{
HANDLE hEvent;
// cppcheck-suppress unreadVariable
hEvent = OpenEventW(EVENT_ALL_ACCESS, TRUE, L"testevent");
// cppcheck-suppress resourceLeak
}
void ignoredReturnValue()
{
// cppcheck-suppress leakReturnValNotUsed
@ -187,6 +241,13 @@ void ignoredReturnValue()
// cppcheck-suppress ignoredReturnValue
GetProcAddress(hInstLib, "name");
FreeLibrary(hInstLib);
// cppcheck-suppress leakReturnValNotUsed
CreateEvent(NULL, FALSE, FALSE, NULL);
// cppcheck-suppress leakReturnValNotUsed
OpenEvent(EVENT_ALL_ACCESS, FALSE, L"testevent");
// cppcheck-suppress leakReturnValNotUsed
CreateEventEx(NULL, L"test", CREATE_EVENT_INITIAL_SET, EVENT_MODIFY_STATE);
}
void invalidFunctionArg()
@ -243,6 +304,16 @@ void uninitvar()
ReleaseMutex(hMutex);
// cppcheck-suppress uninitvar
CloseHandle(hMutex);
HANDLE hEvent;
// cppcheck-suppress uninitvar
PulseEvent(hEvent);
// cppcheck-suppress uninitvar
ResetEvent(hEvent);
// cppcheck-suppress uninitvar
SetEvent(hEvent);
// cppcheck-suppress uninitvar
CloseHandle(hEvent);
}
void allocDealloc_GetModuleHandleEx()