From 43c5289928dc18454691ed88d1e03ff7977ff0b4 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 13 Oct 2022 16:25:36 +0200 Subject: [PATCH] Replaced memset/ZeroMemory with initializer * Addes WINPR_ASSERT on many occations * Replaced memset with array initializer * Replaced ZeroMemory with array initializer --- channels/remdesk/server/remdesk_main.c | 3 +- channels/sshagent/client/sshagent_main.c | 4 +- channels/tsmf/client/alsa/tsmf_alsa.c | 9 +- channels/tsmf/client/oss/tsmf_oss.c | 9 +- channels/tsmf/client/tsmf_main.c | 3 +- .../src/main/cpp/android_cliprdr.c | 9 +- .../src/main/cpp/android_freerdp.c | 3 + client/Mac/Clipboard.m | 20 +- client/Mac/cli/AppDelegate.m | 4 +- client/Wayland/wlfreerdp.c | 1 + client/Windows/wf_cliprdr.c | 25 +-- client/Windows/wf_graphics.c | 3 +- client/Windows/wf_rail.c | 10 +- client/X11/xf_client.c | 4 +- client/X11/xf_cliprdr.c | 9 +- client/X11/xf_graphics.c | 4 +- client/X11/xf_input.c | 3 +- client/X11/xf_keyboard.c | 2 +- client/X11/xf_window.c | 3 +- client/iOS/FreeRDP/ios_freerdp.m | 2 + libfreerdp/cache/persistent.c | 49 +++-- libfreerdp/codec/color.c | 3 + libfreerdp/codec/h264_openh264.c | 3 +- libfreerdp/codec/jpeg.c | 11 +- libfreerdp/codec/rfx.c | 4 +- .../codec/test/TestFreeRDPCodecProgressive.c | 6 +- libfreerdp/codec/xcrush.c | 8 +- libfreerdp/common/assistance.c | 7 +- libfreerdp/core/credssp_auth.c | 1 + libfreerdp/core/info.c | 15 +- libfreerdp/core/license.c | 3 +- libfreerdp/core/test/TestConnect.c | 5 +- libfreerdp/locale/keyboard.c | 12 +- libfreerdp/locale/keyboard_xkbfile.c | 2 + .../primitives/test/TestPrimitivesAdd.c | 10 +- .../primitives/test/TestPrimitivesAlphaComp.c | 5 +- .../primitives/test/TestPrimitivesColors.c | 12 +- .../primitives/test/TestPrimitivesCopy.c | 3 +- .../primitives/test/TestPrimitivesSet.c | 17 +- .../primitives/test/TestPrimitivesSign.c | 2 - libfreerdp/utils/smartcard_pack.c | 5 + server/Mac/mf_event.c | 3 +- server/Sample/sfreerdp.c | 2 +- server/Windows/wf_dxgi.c | 3 +- server/Windows/wf_input.c | 8 +- server/shadow/Win/win_dxgi.c | 3 +- server/shadow/Win/win_rdp.c | 4 +- server/shadow/Win/win_shadow.c | 11 +- server/shadow/Win/win_wds.c | 4 +- server/shadow/X11/x11_shadow.c | 3 +- server/shadow/shadow_capture.c | 2 +- server/shadow/shadow_subsystem.c | 1 + winpr/libwinpr/comm/comm.c | 6 +- winpr/libwinpr/comm/comm_ioctl.c | 3 +- winpr/libwinpr/comm/comm_sercx2_sys.c | 1 + winpr/libwinpr/comm/comm_serial_sys.c | 2 +- winpr/libwinpr/comm/test/TestCommConfig.c | 8 +- winpr/libwinpr/comm/test/TestCommMonitor.c | 3 +- winpr/libwinpr/comm/test/TestSerialChars.c | 9 +- winpr/libwinpr/comm/test/TestSetCommState.c | 2 + winpr/libwinpr/comm/test/TestTimeouts.c | 3 +- winpr/libwinpr/crypto/test/TestCryptoCipher.c | 14 +- winpr/libwinpr/file/file.c | 4 +- winpr/libwinpr/file/namedPipeClient.c | 3 +- winpr/libwinpr/io/io.c | 3 +- winpr/libwinpr/nt/test/TestNtCreateFile.c | 5 +- winpr/libwinpr/pipe/pipe.c | 6 +- .../pipe/test/TestPipeCreateNamedPipe.c | 177 ++++++++++-------- winpr/libwinpr/pipe/test/TestPipeCreatePipe.c | 5 +- winpr/libwinpr/pool/test/TestPoolWork.c | 20 +- winpr/libwinpr/sspi/test/TestNTLM.c | 6 +- winpr/libwinpr/sspi/test/TestSchannel.c | 43 ++--- winpr/libwinpr/synch/timer.c | 3 +- winpr/libwinpr/thread/process.c | 5 +- .../thread/test/TestThreadCreateProcess.c | 8 +- winpr/libwinpr/utils/wlog/UdpAppender.c | 7 +- winpr/libwinpr/winsock/winsock.c | 12 +- winpr/libwinpr/wtsapi/wtsapi_win32.c | 16 +- 78 files changed, 353 insertions(+), 378 deletions(-) diff --git a/channels/remdesk/server/remdesk_main.c b/channels/remdesk/server/remdesk_main.c index 4a475faaf..88bc8384d 100644 --- a/channels/remdesk/server/remdesk_main.c +++ b/channels/remdesk/server/remdesk_main.c @@ -97,8 +97,7 @@ static UINT remdesk_write_channel_header(wStream* s, REMDESK_CHANNEL_HEADER* hea { int index; UINT32 ChannelNameLen; - WCHAR ChannelNameW[32]; - ZeroMemory(ChannelNameW, sizeof(ChannelNameW)); + WCHAR ChannelNameW[32] = { 0 }; for (index = 0; index < 32; index++) { diff --git a/channels/sshagent/client/sshagent_main.c b/channels/sshagent/client/sshagent_main.c index b4cc15acf..5d71f9ee4 100644 --- a/channels/sshagent/client/sshagent_main.c +++ b/channels/sshagent/client/sshagent_main.c @@ -102,9 +102,7 @@ static int connect_to_sshagent(const char* udspath) return -1; } - struct sockaddr_un addr; - - memset(&addr, 0, sizeof(addr)); + struct sockaddr_un addr = { 0 }; addr.sun_family = AF_UNIX; diff --git a/channels/tsmf/client/alsa/tsmf_alsa.c b/channels/tsmf/client/alsa/tsmf_alsa.c index 3a44f3488..146c4f9d7 100644 --- a/channels/tsmf/client/alsa/tsmf_alsa.c +++ b/channels/tsmf/client/alsa/tsmf_alsa.c @@ -226,14 +226,15 @@ static void tsmf_alsa_free(ITSMFAudioDevice* audio) ITSMFAudioDevice* alsa_freerdp_tsmf_client_audio_subsystem_entry(void) { - TSMFAlsaAudioDevice* alsa; - alsa = (TSMFAlsaAudioDevice*)malloc(sizeof(TSMFAlsaAudioDevice)); - ZeroMemory(alsa, sizeof(TSMFAlsaAudioDevice)); + TSMFAlsaAudioDevice* alsa = calloc(1, sizeof(TSMFAlsaAudioDevice)); + if (!alsa) + return NULL; + alsa->iface.Open = tsmf_alsa_open; alsa->iface.SetFormat = tsmf_alsa_set_format; alsa->iface.Play = tsmf_alsa_play; alsa->iface.GetLatency = tsmf_alsa_get_latency; alsa->iface.Flush = tsmf_alsa_flush; alsa->iface.Free = tsmf_alsa_free; - return (ITSMFAudioDevice*)alsa; + return &alsa->iface; } diff --git a/channels/tsmf/client/oss/tsmf_oss.c b/channels/tsmf/client/oss/tsmf_oss.c index 374bc5c89..bf488599d 100644 --- a/channels/tsmf/client/oss/tsmf_oss.c +++ b/channels/tsmf/client/oss/tsmf_oss.c @@ -232,9 +232,10 @@ static void tsmf_oss_free(ITSMFAudioDevice* audio) ITSMFAudioDevice* oss_freerdp_tsmf_client_audio_subsystem_entry(void) { - TSMFOssAudioDevice* oss; - oss = (TSMFOssAudioDevice*)malloc(sizeof(TSMFOssAudioDevice)); - ZeroMemory(oss, sizeof(TSMFOssAudioDevice)); + TSMFOssAudioDevice* oss = calloc(1, sizeof(TSMFOssAudioDevice)); + if (!oss) + return NULL; + oss->iface.Open = tsmf_oss_open; oss->iface.SetFormat = tsmf_oss_set_format; oss->iface.Play = tsmf_oss_play; @@ -242,5 +243,5 @@ ITSMFAudioDevice* oss_freerdp_tsmf_client_audio_subsystem_entry(void) oss->iface.Flush = tsmf_oss_flush; oss->iface.Free = tsmf_oss_free; oss->pcm_handle = -1; - return (ITSMFAudioDevice*)oss; + return &oss->iface; } diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index be8a827d4..ced04139f 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -130,7 +130,7 @@ static UINT tsmf_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* output; UINT error = CHANNEL_RC_OK; BOOL processed = FALSE; - TSMF_IFMAN ifman; + TSMF_IFMAN ifman = { 0 }; UINT32 MessageId; UINT32 FunctionId; UINT32 InterfaceId; @@ -154,7 +154,6 @@ static UINT tsmf_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, DEBUG_TSMF("cbSize=%" PRIu32 " InterfaceId=0x%" PRIX32 " MessageId=0x%" PRIX32 " FunctionId=0x%" PRIX32 "", cbSize, InterfaceId, MessageId, FunctionId); - ZeroMemory(&ifman, sizeof(TSMF_IFMAN)); ifman.channel_callback = pChannelCallback; ifman.decoder_name = ((TSMF_PLUGIN*)callback->plugin)->decoder_name; ifman.audio_name = ((TSMF_PLUGIN*)callback->plugin)->audio_name; diff --git a/client/Android/Studio/freeRDPCore/src/main/cpp/android_cliprdr.c b/client/Android/Studio/freeRDPCore/src/main/cpp/android_cliprdr.c index e5f8e91f8..62bb1e1de 100644 --- a/client/Android/Studio/freeRDPCore/src/main/cpp/android_cliprdr.c +++ b/client/Android/Studio/freeRDPCore/src/main/cpp/android_cliprdr.c @@ -42,7 +42,7 @@ UINT android_cliprdr_send_client_format_list(CliprdrClientContext* cliprdr) UINT32* pFormatIds; const char* formatName; CLIPRDR_FORMAT* formats; - CLIPRDR_FORMAT_LIST formatList; + CLIPRDR_FORMAT_LIST formatList = { 0 }; if (!cliprdr) return ERROR_INVALID_PARAMETER; @@ -52,7 +52,6 @@ UINT android_cliprdr_send_client_format_list(CliprdrClientContext* cliprdr) if (!afc || !afc->cliprdr) return ERROR_INVALID_PARAMETER; - ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST)); pFormatIds = NULL; numFormats = ClipboardGetFormatIds(afc->clipboard, &pFormatIds); formats = (CLIPRDR_FORMAT*)calloc(numFormats, sizeof(CLIPRDR_FORMAT)); @@ -95,7 +94,7 @@ static UINT android_cliprdr_send_client_format_data_request(CliprdrClientContext UINT32 formatId) { UINT rc = ERROR_INVALID_PARAMETER; - CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest; + CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = { 0 }; androidContext* afc; if (!cliprdr) @@ -106,7 +105,6 @@ static UINT android_cliprdr_send_client_format_data_request(CliprdrClientContext if (!afc || !afc->clipboardRequestEvent || !cliprdr->ClientFormatDataRequest) goto fail; - ZeroMemory(&formatDataRequest, sizeof(CLIPRDR_FORMAT_DATA_REQUEST)); formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST; formatDataRequest.common.msgFlags = 0; formatDataRequest.requestedFormatId = formatId; @@ -336,7 +334,7 @@ android_cliprdr_server_format_data_request(CliprdrClientContext* cliprdr, BYTE* data; UINT32 size; UINT32 formatId; - CLIPRDR_FORMAT_DATA_RESPONSE response; + CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 }; androidContext* afc; if (!cliprdr || !formatDataRequest || !cliprdr->ClientFormatDataResponse) @@ -347,7 +345,6 @@ android_cliprdr_server_format_data_request(CliprdrClientContext* cliprdr, if (!afc) return ERROR_INVALID_PARAMETER; - ZeroMemory(&response, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE)); formatId = formatDataRequest->requestedFormatId; data = (BYTE*)ClipboardGetData(afc->clipboard, formatId, &size); response.common.msgFlags = CB_RESPONSE_OK; diff --git a/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c b/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c index f920998a2..783b2eff1 100644 --- a/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c +++ b/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c @@ -553,7 +553,10 @@ static void android_client_free(freerdp* instance, rdpContext* context) static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) { + WINPR_ASSERT(pEntryPoints); + ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS)); + pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION; pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1); pEntryPoints->GlobalInit = NULL; diff --git a/client/Mac/Clipboard.m b/client/Mac/Clipboard.m index e6a21a34d..b9b8527da 100644 --- a/client/Mac/Clipboard.m +++ b/client/Mac/Clipboard.m @@ -30,9 +30,10 @@ int mac_cliprdr_send_client_format_list(CliprdrClientContext *cliprdr) const char *formatName; CLIPRDR_FORMAT *formats; CLIPRDR_FORMAT_LIST formatList = { 0 }; - mfContext *mfc = (mfContext *)cliprdr->custom; - ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST)); + WINPR_ASSERT(cliprdr); + mfContext *mfc = (mfContext *)cliprdr->custom; + WINPR_ASSERT(mfc); pFormatIds = NULL; numFormats = ClipboardGetFormatIds(mfc->clipboard, &pFormatIds); @@ -88,10 +89,11 @@ static int mac_cliprdr_send_client_format_list_response(CliprdrClientContext *cl static int mac_cliprdr_send_client_format_data_request(CliprdrClientContext *cliprdr, UINT32 formatId) { - CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest; - mfContext *mfc = (mfContext *)cliprdr->custom; + CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = { 0 }; + WINPR_ASSERT(cliprdr); - ZeroMemory(&formatDataRequest, sizeof(CLIPRDR_FORMAT_DATA_REQUEST)); + mfContext *mfc = (mfContext *)cliprdr->custom; + WINPR_ASSERT(mfc); formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST; formatDataRequest.common.msgFlags = 0; @@ -287,10 +289,12 @@ mac_cliprdr_server_format_data_request(CliprdrClientContext *cliprdr, BYTE *data; UINT32 size; UINT32 formatId; - CLIPRDR_FORMAT_DATA_RESPONSE response; - mfContext *mfc = (mfContext *)cliprdr->custom; + CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 }; - ZeroMemory(&response, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE)); + WINPR_ASSERT(cliprdr); + + mfContext *mfc = (mfContext *)cliprdr->custom; + WINPR_ASSERT(mfc); formatId = formatDataRequest->requestedFormatId; data = (BYTE *)ClipboardGetData(mfc->clipboard, formatId, &size); diff --git a/client/Mac/cli/AppDelegate.m b/client/Mac/cli/AppDelegate.m index c87239ecc..d9f93df85 100644 --- a/client/Mac/cli/AppDelegate.m +++ b/client/Mac/cli/AppDelegate.m @@ -148,8 +148,8 @@ void mac_set_view_size(rdpContext *context, MRDPView *view); - (void)CreateContext { - RDP_CLIENT_ENTRY_POINTS clientEntryPoints; - ZeroMemory(&clientEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS)); + RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 }; + clientEntryPoints.Size = sizeof(RDP_CLIENT_ENTRY_POINTS); clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION; RdpClientEntry(&clientEntryPoints); diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c index 8e487e73f..3042a0acb 100644 --- a/client/Wayland/wlfreerdp.c +++ b/client/Wayland/wlfreerdp.c @@ -660,6 +660,7 @@ static int wfl_client_start(rdpContext* context) static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) { + WINPR_ASSERT(pEntryPoints); ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS)); pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION; pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1); diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 2b0949726..e4e63f88f 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -1237,8 +1237,6 @@ static UINT cliprdr_send_format_list(wfClipboard* clipboard) if (!clipboard) return ERROR_INTERNAL_ERROR; - ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST)); - /* Ignore if other app is holding clipboard */ if (try_open_clipboard(clipboard->hwnd)) { @@ -1518,8 +1516,8 @@ static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM static int create_cliprdr_window(wfClipboard* clipboard) { - WNDCLASSEX wnd_cls; - ZeroMemory(&wnd_cls, sizeof(WNDCLASSEX)); + WNDCLASSEX wnd_cls = { 0 }; + wnd_cls.cbSize = sizeof(WNDCLASSEX); wnd_cls.style = CS_OWNDC; wnd_cls.lpfnWndProc = cliprdr_proc; @@ -2063,18 +2061,16 @@ wf_cliprdr_server_format_data_request(CliprdrClientContext* context, size_t i; WCHAR* wFileName; HRESULT result; - LPDATAOBJECT dataObj; - FORMATETC format_etc; - STGMEDIUM stg_medium; - DROPFILES* dropFiles; + LPDATAOBJECT dataObj = NULL; + FORMATETC format_etc = { 0 }; + STGMEDIUM stg_medium = { 0 }; + DROPFILES* dropFiles = NULL; FILEGROUPDESCRIPTORW* groupDsc; result = OleGetClipboard(&dataObj); if (FAILED(result)) return ERROR_INTERNAL_ERROR; - ZeroMemory(&format_etc, sizeof(FORMATETC)); - ZeroMemory(&stg_medium, sizeof(STGMEDIUM)); /* get DROPFILES struct from OLE */ format_etc.cfFormat = CF_HDROP; format_etc.tymed = TYMED_HGLOBAL; @@ -2248,9 +2244,9 @@ wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, DWORD uSize = 0; BYTE* pData = NULL; HRESULT hRet = S_OK; - FORMATETC vFormatEtc; + FORMATETC vFormatEtc = { 0 }; LPDATAOBJECT pDataObj = NULL; - STGMEDIUM vStgMedium; + STGMEDIUM vStgMedium = { 0 }; BOOL bIsStreamFile = TRUE; static LPSTREAM pStreamStc = NULL; static UINT32 uStreamIdStc = 0; @@ -2284,8 +2280,6 @@ wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, goto error; } - ZeroMemory(&vFormatEtc, sizeof(FORMATETC)); - ZeroMemory(&vStgMedium, sizeof(STGMEDIUM)); vFormatEtc.cfFormat = RegisterClipboardFormat(CFSTR_FILECONTENTS); vFormatEtc.tymed = TYMED_ISTREAM; vFormatEtc.dwAspect = 1; @@ -2337,8 +2331,7 @@ wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, { if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE) { - STATSTG vStatStg; - ZeroMemory(&vStatStg, sizeof(STATSTG)); + STATSTG vStatStg = { 0 }; hRet = IStream_Stat(pStreamStc, &vStatStg, STATFLAG_NONAME); if (hRet == S_OK) diff --git a/client/Windows/wf_graphics.c b/client/Windows/wf_graphics.c index a719ebaef..885d4a378 100644 --- a/client/Windows/wf_graphics.c +++ b/client/Windows/wf_graphics.c @@ -336,13 +336,12 @@ static BOOL wf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y) BOOL wf_register_pointer(rdpGraphics* graphics) { wfContext* wfc; - rdpPointer pointer; + rdpPointer pointer = { 0 }; if (!graphics) return FALSE; wfc = (wfContext*)graphics->context; - ZeroMemory(&pointer, sizeof(rdpPointer)); pointer.size = sizeof(wfPointer); pointer.New = wf_Pointer_New; pointer.Free = wf_Pointer_Free; diff --git a/client/Windows/wf_rail.c b/client/Windows/wf_rail.c index 6a66b8ddf..c1fde2a4b 100644 --- a/client/Windows/wf_rail.c +++ b/client/Windows/wf_rail.c @@ -434,7 +434,7 @@ static BOOL wf_rail_window_common(rdpContext* context, const WINDOW_ORDER_INFO* BOOL rc; HANDLE hInstance; WCHAR* titleW = NULL; - WNDCLASSEX wndClassEx; + WNDCLASSEX wndClassEx = { 0 }; railWindow = (wfRailWindow*)calloc(1, sizeof(wfRailWindow)); if (!railWindow) @@ -486,7 +486,7 @@ static BOOL wf_rail_window_common(rdpContext* context, const WINDOW_ORDER_INFO* ConvertToUnicode(CP_UTF8, 0, railWindow->title, -1, &titleW, 0); hInstance = GetModuleHandle(NULL); - ZeroMemory(&wndClassEx, sizeof(WNDCLASSEX)); + wndClassEx.cbSize = sizeof(WNDCLASSEX); wndClassEx.style = 0; wndClassEx.lpfnWndProc = wf_RailWndProc; @@ -687,8 +687,8 @@ static BOOL wf_rail_window_icon(rdpContext* context, const WINDOW_ORDER_INFO* or int height; HICON hIcon; BOOL bigIcon; - ICONINFO iconInfo; - BITMAPINFO bitmapInfo; + ICONINFO iconInfo = { 0 }; + BITMAPINFO bitmapInfo = { 0 }; wfRailWindow* railWindow; BITMAPINFOHEADER* bitmapInfoHeader; wfContext* wfc = (wfContext*)context; @@ -706,7 +706,7 @@ static BOOL wf_rail_window_icon(rdpContext* context, const WINDOW_ORDER_INFO* or iconInfo.fIcon = TRUE; iconInfo.xHotspot = 0; iconInfo.yHotspot = 0; - ZeroMemory(&bitmapInfo, sizeof(BITMAPINFO)); + bitmapInfoHeader = &(bitmapInfo.bmiHeader); bpp = windowIcon->iconInfo->bpp; width = windowIcon->iconInfo->width; diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 7185ede65..b18d22ee2 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -628,7 +628,7 @@ static char* xf_window_get_title(rdpSettings* settings) BOOL xf_create_window(xfContext* xfc) { - XGCValues gcv; + XGCValues gcv = { 0 }; XEvent xevent = { 0 }; int width, height; char* windowTitle; @@ -697,8 +697,6 @@ BOOL xf_create_window(xfContext* xfc) xfc->drawable = xf_CreateDummyWindow(xfc); } - ZeroMemory(&gcv, sizeof(gcv)); - if (xfc->modifierMap) XFreeModifiermap(xfc->modifierMap); diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index a7686264e..c2573289d 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -1624,8 +1624,7 @@ xf_cliprdr_server_file_contents_response(CliprdrClientContext* context, ino->st_size = size; ino->size_set = TRUE; - struct fuse_entry_param e; - memset(&e, 0, sizeof(e)); + struct fuse_entry_param e = { 0 }; e.ino = ino->ino; e.attr_timeout = 1.0; e.entry_timeout = 1.0; @@ -2750,7 +2749,6 @@ static void xf_cliprdr_fuse_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, size_t child_ino; size_t direntry_len; char* buf; - struct stat stbuf; size_t pos = 0; xfCliprdrFuseInode* child_node; xfCliprdrFuseInode* node; @@ -2795,7 +2793,7 @@ static void xf_cliprdr_fuse_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, } for (index = off; index < count + 2; index++) { - memset(&stbuf, 0, sizeof(stbuf)); + struct stat stbuf = { 0 }; if (index == 0) { stbuf.st_ino = ino; @@ -2905,7 +2903,7 @@ static void xf_cliprdr_fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char size_t count; size_t child_ino; BOOL found = FALSE; - struct fuse_entry_param e; + struct fuse_entry_param e = { 0 }; xfCliprdrFuseInode* parent_node; xfCliprdrFuseInode* child_node = NULL; xfClipboard* clipboard = (xfClipboard*)fuse_req_userdata(req); @@ -2979,7 +2977,6 @@ static void xf_cliprdr_fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char 0); return; } - memset(&e, 0, sizeof(e)); e.ino = ino; e.attr_timeout = 1.0; e.entry_timeout = 1.0; diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index 3084dd653..3da66b30a 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -525,9 +525,9 @@ static BOOL xf_Pointer_SetNull(rdpContext* context) if (nullcursor == None) { - XcursorImage ci; + XcursorImage ci = { 0 }; XcursorPixel xp = 0; - ZeroMemory(&ci, sizeof(ci)); + ci.version = XCURSOR_IMAGE_VERSION; ci.size = sizeof(ci); ci.width = ci.height = 1; diff --git a/client/X11/xf_input.c b/client/X11/xf_input.c index 1db7f2423..1e051dc2b 100644 --- a/client/X11/xf_input.c +++ b/client/X11/xf_input.c @@ -549,11 +549,10 @@ static void xf_input_hide_cursor(xfContext* xfc) if (!xfc->cursorHidden) { - XcursorImage ci; + XcursorImage ci = { 0 }; XcursorPixel xp = 0; static Cursor nullcursor = None; xf_lock_x11(xfc); - ZeroMemory(&ci, sizeof(ci)); ci.version = XCURSOR_IMAGE_VERSION; ci.size = sizeof(ci); ci.width = ci.height = 1; diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 96130fd8d..1eead8369 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -57,7 +57,7 @@ static BOOL xf_sync_kbd_state(xfContext* xfc) static void xf_keyboard_clear(xfContext* xfc) { WINPR_ASSERT(xfc); - ZeroMemory(xfc->KeyboardState, 256 * sizeof(BOOL)); + ZeroMemory(xfc->KeyboardState, sizeof(xfc->KeyboardState)); } static BOOL xf_keyboard_action_script_init(xfContext* xfc) diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 29918370e..c3c16d75e 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -785,7 +785,7 @@ int xf_AppWindowInit(xfContext* xfc, xfAppWindow* appWindow) int xf_AppWindowCreate(xfContext* xfc, xfAppWindow* appWindow) { - XGCValues gcv; + XGCValues gcv = { 0 }; int input_mask; XWMHints* InputModeHint; XClassHint* class_hints; @@ -817,7 +817,6 @@ int xf_AppWindowCreate(xfContext* xfc, xfAppWindow* appWindow) if (!appWindow->handle) return -1; - ZeroMemory(&gcv, sizeof(gcv)); appWindow->gc = XCreateGC(xfc->display, appWindow->handle, GCGraphicsExposures, &gcv); class_hints = XAllocClassHint(); diff --git a/client/iOS/FreeRDP/ios_freerdp.m b/client/iOS/FreeRDP/ios_freerdp.m index 8b4934586..c78b88d71 100644 --- a/client/iOS/FreeRDP/ios_freerdp.m +++ b/client/iOS/FreeRDP/ios_freerdp.m @@ -356,6 +356,8 @@ static void ios_client_free(freerdp *instance, rdpContext *context) static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS *pEntryPoints) { + WINPR_ASSERT(pEntryPoints); + ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS)); pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION; pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1); diff --git a/libfreerdp/cache/persistent.c b/libfreerdp/cache/persistent.c index 870d0cac7..4d9551050 100644 --- a/libfreerdp/cache/persistent.c +++ b/libfreerdp/cache/persistent.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -43,18 +44,23 @@ struct rdp_persistent_cache int persistent_cache_get_version(rdpPersistentCache* persistent) { + WINPR_ASSERT(persistent); return persistent->version; } int persistent_cache_get_count(rdpPersistentCache* persistent) { + WINPR_ASSERT(persistent); return persistent->count; } static int persistent_cache_read_entry_v2(rdpPersistentCache* persistent, PERSISTENT_CACHE_ENTRY* entry) { - PERSISTENT_CACHE_ENTRY_V2 entry2; + PERSISTENT_CACHE_ENTRY_V2 entry2 = { 0 }; + + WINPR_ASSERT(persistent); + WINPR_ASSERT(entry); if (fread((void*)&entry2, sizeof(entry2), 1, persistent->fp) != 1) return -1; @@ -77,8 +83,10 @@ static int persistent_cache_write_entry_v2(rdpPersistentCache* persistent, const PERSISTENT_CACHE_ENTRY* entry) { int padding; - PERSISTENT_CACHE_ENTRY_V2 entry2; + PERSISTENT_CACHE_ENTRY_V2 entry2 = { 0 }; + WINPR_ASSERT(persistent); + WINPR_ASSERT(entry); entry2.key64 = entry->key64; entry2.width = entry->width; entry2.height = entry->height; @@ -109,9 +117,10 @@ static int persistent_cache_write_entry_v2(rdpPersistentCache* persistent, static int persistent_cache_read_v2(rdpPersistentCache* persistent) { + WINPR_ASSERT(persistent); while (1) { - PERSISTENT_CACHE_ENTRY_V2 entry; + PERSISTENT_CACHE_ENTRY_V2 entry = { 0 }; if (fread((void*)&entry, sizeof(entry), 1, persistent->fp) != 1) break; @@ -128,7 +137,10 @@ static int persistent_cache_read_v2(rdpPersistentCache* persistent) static int persistent_cache_read_entry_v3(rdpPersistentCache* persistent, PERSISTENT_CACHE_ENTRY* entry) { - PERSISTENT_CACHE_ENTRY_V3 entry3; + PERSISTENT_CACHE_ENTRY_V3 entry3 = { 0 }; + + WINPR_ASSERT(persistent); + WINPR_ASSERT(entry); if (fread((void*)&entry3, sizeof(entry3), 1, persistent->fp) != 1) return -1; @@ -166,7 +178,10 @@ static int persistent_cache_read_entry_v3(rdpPersistentCache* persistent, static int persistent_cache_write_entry_v3(rdpPersistentCache* persistent, const PERSISTENT_CACHE_ENTRY* entry) { - PERSISTENT_CACHE_ENTRY_V3 entry3; + PERSISTENT_CACHE_ENTRY_V3 entry3 = { 0 }; + + WINPR_ASSERT(persistent); + WINPR_ASSERT(entry); entry3.key64 = entry->key64; entry3.width = entry->width; @@ -185,9 +200,10 @@ static int persistent_cache_write_entry_v3(rdpPersistentCache* persistent, static int persistent_cache_read_v3(rdpPersistentCache* persistent) { + WINPR_ASSERT(persistent); while (1) { - PERSISTENT_CACHE_ENTRY_V3 entry; + PERSISTENT_CACHE_ENTRY_V3 entry = { 0 }; if (fread((void*)&entry, sizeof(entry), 1, persistent->fp) != 1) break; @@ -203,6 +219,9 @@ static int persistent_cache_read_v3(rdpPersistentCache* persistent) int persistent_cache_read_entry(rdpPersistentCache* persistent, PERSISTENT_CACHE_ENTRY* entry) { + WINPR_ASSERT(persistent); + WINPR_ASSERT(entry); + if (persistent->version == 3) return persistent_cache_read_entry_v3(persistent, entry); else if (persistent->version == 2) @@ -214,6 +233,9 @@ int persistent_cache_read_entry(rdpPersistentCache* persistent, PERSISTENT_CACHE int persistent_cache_write_entry(rdpPersistentCache* persistent, const PERSISTENT_CACHE_ENTRY* entry) { + WINPR_ASSERT(persistent); + WINPR_ASSERT(entry); + if (persistent->version == 3) return persistent_cache_write_entry_v3(persistent, entry); else if (persistent->version == 2) @@ -224,10 +246,11 @@ int persistent_cache_write_entry(rdpPersistentCache* persistent, static int persistent_cache_open_read(rdpPersistentCache* persistent) { - BYTE sig[8]; + BYTE sig[8] = { 0 }; int status = 1; long offset; + WINPR_ASSERT(persistent); persistent->fp = fopen(persistent->filename, "rb"); if (!persistent->fp) @@ -266,6 +289,7 @@ static int persistent_cache_open_read(rdpPersistentCache* persistent) static int persistent_cache_open_write(rdpPersistentCache* persistent) { + WINPR_ASSERT(persistent); persistent->fp = fopen(persistent->filename, "w+b"); @@ -274,7 +298,7 @@ static int persistent_cache_open_write(rdpPersistentCache* persistent) if (persistent->version == 3) { - PERSISTENT_CACHE_HEADER_V3 header; + PERSISTENT_CACHE_HEADER_V3 header = { 0 }; strncpy((char*)header.sig, "RDP8bmp", 8); header.flags = 0x00000006; @@ -290,6 +314,8 @@ static int persistent_cache_open_write(rdpPersistentCache* persistent) int persistent_cache_open(rdpPersistentCache* persistent, const char* filename, BOOL write, UINT32 version) { + WINPR_ASSERT(persistent); + WINPR_ASSERT(filename); persistent->write = write; persistent->filename = _strdup(filename); @@ -308,6 +334,7 @@ int persistent_cache_open(rdpPersistentCache* persistent, const char* filename, int persistent_cache_close(rdpPersistentCache* persistent) { + WINPR_ASSERT(persistent); if (persistent->fp) { fclose(persistent->fp); @@ -319,15 +346,13 @@ int persistent_cache_close(rdpPersistentCache* persistent) rdpPersistentCache* persistent_cache_new(void) { - rdpPersistentCache* persistent; - - persistent = (rdpPersistentCache*)calloc(1, sizeof(rdpPersistentCache)); + rdpPersistentCache* persistent = calloc(1, sizeof(rdpPersistentCache)); if (!persistent) return NULL; persistent->bmpSize = 0x4000; - persistent->bmpData = (BYTE*)malloc(persistent->bmpSize); + persistent->bmpData = calloc(1, persistent->bmpSize); if (!persistent->bmpData) return NULL; diff --git a/libfreerdp/codec/color.c b/libfreerdp/codec/color.c index d550e8d35..198e08a06 100644 --- a/libfreerdp/codec/color.c +++ b/libfreerdp/codec/color.c @@ -159,6 +159,9 @@ static void fill_gdi_palette_for_icon(const BYTE* colorTable, UINT16 cbColorTabl gdiPalette* palette) { UINT16 i; + + WINPR_ASSERT(palette); + palette->format = PIXEL_FORMAT_BGRX32; ZeroMemory(palette->palette, sizeof(palette->palette)); diff --git a/libfreerdp/codec/h264_openh264.c b/libfreerdp/codec/h264_openh264.c index 5a140dfec..c1dd7d040 100644 --- a/libfreerdp/codec/h264_openh264.c +++ b/libfreerdp/codec/h264_openh264.c @@ -493,7 +493,6 @@ static BOOL openh264_init(H264_CONTEXT* h264) #endif UINT32 x; long status; - SDecodingParam sDecParam = { 0 }; H264_CONTEXT_OPENH264* sysContexts; static int traceLevel = WELS_LOG_DEBUG; #if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5) @@ -535,6 +534,7 @@ static BOOL openh264_init(H264_CONTEXT* h264) for (x = 0; x < h264->numSystemData; x++) { + SDecodingParam sDecParam = { 0 }; H264_CONTEXT_OPENH264* sys = &sysContexts[x]; if (h264->Compressor) @@ -557,7 +557,6 @@ static BOOL openh264_init(H264_CONTEXT* h264) goto EXCEPTION; } - ZeroMemory(&sDecParam, sizeof(sDecParam)); #if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5) sDecParam.eOutputColorFormat = videoFormatI420; #endif diff --git a/libfreerdp/codec/jpeg.c b/libfreerdp/codec/jpeg.c index 9a921f6e7..152095808 100644 --- a/libfreerdp/codec/jpeg.c +++ b/libfreerdp/codec/jpeg.c @@ -73,17 +73,15 @@ static void my_term_source(j_decompress_ptr cinfo) static int do_decompress(char* comp_data, int comp_data_bytes, int* width, int* height, int* bpp, char* decomp_data, int* decomp_data_bytes) { - struct jpeg_decompress_struct cinfo; + struct jpeg_decompress_struct cinfo = { 0 }; struct jpeg_error_mgr jerr; - struct jpeg_source_mgr src_mgr; - struct mydata_decomp md; - JSAMPROW row_pointer[1]; + struct jpeg_source_mgr src_mgr = { 0 }; + struct mydata_decomp md = { 0 }; + JSAMPROW row_pointer[1] = { 0 }; - memset(&cinfo, 0, sizeof(cinfo)); cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); - memset(&src_mgr, 0, sizeof(src_mgr)); cinfo.src = &src_mgr; src_mgr.init_source = my_init_source; src_mgr.fill_input_buffer = my_fill_input_buffer; @@ -91,7 +89,6 @@ static int do_decompress(char* comp_data, int comp_data_bytes, int* width, int* src_mgr.resync_to_restart = my_resync_to_restart; src_mgr.term_source = my_term_source; - memset(&md, 0, sizeof(md)); md.data = comp_data; md.data_bytes = comp_data_bytes; cinfo.client_data = &md; diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index b9b433a9c..09576beab 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -273,8 +273,8 @@ RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags) #ifdef _WIN32 { BOOL isVistaOrLater; - OSVERSIONINFOA verinfo; - ZeroMemory(&verinfo, sizeof(OSVERSIONINFOA)); + OSVERSIONINFOA verinfo = { 0 }; + verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); GetVersionExA(&verinfo); isVistaOrLater = diff --git a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c index 3b425b8b7..75147f6ad 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c @@ -920,14 +920,12 @@ static int test_progressive_ms_sample(char* ms_sample_path) int i, j, k; int count; int status; - EGFX_SAMPLE_FILE files[3][4][4]; - EGFX_SAMPLE_FILE bitmaps[3][4][4]; + EGFX_SAMPLE_FILE files[3][4][4] = { 0 }; + EGFX_SAMPLE_FILE bitmaps[3][4][4] = { 0 }; PROGRESSIVE_CONTEXT* progressive; g_Width = 1920; g_Height = 1080; g_DstStep = g_Width * 4; - ZeroMemory(files, sizeof(files)); - ZeroMemory(bitmaps, sizeof(bitmaps)); status = test_progressive_load_files(ms_sample_path, files); if (status < 0) diff --git a/libfreerdp/codec/xcrush.c b/libfreerdp/codec/xcrush.c index 775df9b8b..684cfca6a 100644 --- a/libfreerdp/codec/xcrush.c +++ b/libfreerdp/codec/xcrush.c @@ -506,16 +506,14 @@ static int xcrush_find_all_matches(XCRUSH_CONTEXT* xcrush, UINT32 SignatureIndex UINT32 i = 0; UINT32 j = 0; int status = 0; - UINT32 offset = 0; UINT32 ChunkIndex = 0; UINT32 ChunkCount = 0; XCRUSH_CHUNK* chunk = NULL; UINT32 MatchLength = 0; UINT32 MaxMatchLength = 0; UINT32 PrevMatchEnd = 0; - XCRUSH_MATCH_INFO MatchInfo = { 0 }; - XCRUSH_MATCH_INFO MaxMatchInfo = { 0 }; XCRUSH_SIGNATURE* Signatures = NULL; + XCRUSH_MATCH_INFO MaxMatchInfo = { 0 }; WINPR_ASSERT(xcrush); @@ -523,7 +521,8 @@ static int xcrush_find_all_matches(XCRUSH_CONTEXT* xcrush, UINT32 SignatureIndex for (i = 0; i < SignatureIndex; i++) { - offset = SrcOffset + HistoryOffset; + XCRUSH_MATCH_INFO MatchInfo = { 0 }; + UINT32 offset = SrcOffset + HistoryOffset; if (!Signatures[i].size) return -1001; /* error */ @@ -537,7 +536,6 @@ static int xcrush_find_all_matches(XCRUSH_CONTEXT* xcrush, UINT32 SignatureIndex { ChunkCount = 0; MaxMatchLength = 0; - ZeroMemory(&MaxMatchInfo, sizeof(XCRUSH_MATCH_INFO)); while (chunk) { diff --git a/libfreerdp/common/assistance.c b/libfreerdp/common/assistance.c index 3a0dcacdc..edc7f539d 100644 --- a/libfreerdp/common/assistance.c +++ b/libfreerdp/common/assistance.c @@ -633,9 +633,9 @@ static BOOL freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* pas BYTE* pbIn = NULL; BYTE* pbOut = NULL; size_t cbOut, cbIn, cbFinal; - BYTE DerivedKey[WINPR_AES_BLOCK_SIZE]; - BYTE InitializationVector[WINPR_AES_BLOCK_SIZE]; - BYTE PasswordHash[WINPR_SHA1_DIGEST_LENGTH]; + BYTE DerivedKey[WINPR_AES_BLOCK_SIZE] = { 0 }; + BYTE InitializationVector[WINPR_AES_BLOCK_SIZE] = { 0 }; + BYTE PasswordHash[WINPR_SHA1_DIGEST_LENGTH] = { 0 }; if (!file || !password) return FALSE; @@ -658,7 +658,6 @@ static BOOL freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* pas sizeof(DerivedKey))) goto fail; - ZeroMemory(InitializationVector, sizeof(InitializationVector)); aesDec = winpr_Cipher_New(WINPR_CIPHER_AES_128_CBC, WINPR_DECRYPT, DerivedKey, InitializationVector); diff --git a/libfreerdp/core/credssp_auth.c b/libfreerdp/core/credssp_auth.c index 27c2c7e1a..741d0616f 100644 --- a/libfreerdp/core/credssp_auth.c +++ b/libfreerdp/core/credssp_auth.c @@ -124,6 +124,7 @@ BOOL credssp_auth_setup_auth_data(rdpCredsspAuth* auth, const SEC_WINNT_AUTH_IDE { SEC_WINNT_AUTH_IDENTITY_EXW* identityEx; + WINPR_ASSERT(pAuthData); ZeroMemory(pAuthData, sizeof(SEC_WINNT_AUTH_IDENTITY_WINPR)); identityEx = &pAuthData->identity; diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index a2ffbd3a3..a6d1eee84 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -146,11 +146,15 @@ static char* rdp_info_package_flags_description(UINT32 flags) static BOOL rdp_compute_client_auto_reconnect_cookie(rdpRdp* rdp) { - BYTE ClientRandom[32]; - BYTE AutoReconnectRandom[32]; + BYTE ClientRandom[32] = { 0 }; + BYTE AutoReconnectRandom[32] = { 0 }; ARC_SC_PRIVATE_PACKET* serverCookie; ARC_CS_PRIVATE_PACKET* clientCookie; + + WINPR_ASSERT(rdp); rdpSettings* settings = rdp->settings; + WINPR_ASSERT(settings); + serverCookie = settings->ServerAutoReconnectCookie; clientCookie = settings->ClientAutoReconnectCookie; clientCookie->cbLen = 28; @@ -1297,8 +1301,8 @@ BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s) { UINT32 infoType; BOOL status; - logon_info logonInfo; - logon_info_ex logonInfoEx; + logon_info logonInfo = { 0 }; + logon_info_ex logonInfoEx = { 0 }; rdpContext* context = rdp->context; rdpUpdate* update = rdp->context->update; @@ -1310,7 +1314,6 @@ BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s) switch (infoType) { case INFO_TYPE_LOGON: - ZeroMemory(&logonInfo, sizeof(logonInfo)); status = rdp_recv_logon_info_v1(rdp, s, &logonInfo); if (status && update->SaveSessionInfo) @@ -1321,7 +1324,6 @@ BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s) break; case INFO_TYPE_LOGON_LONG: - ZeroMemory(&logonInfo, sizeof(logonInfo)); status = rdp_recv_logon_info_v2(rdp, s, &logonInfo); if (status && update->SaveSessionInfo) @@ -1340,7 +1342,6 @@ BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s) break; case INFO_TYPE_LOGON_EXTENDED_INF: - ZeroMemory(&logonInfoEx, sizeof(logonInfoEx)); status = rdp_recv_logon_info_extended(rdp, s, &logonInfoEx); if (status && update->SaveSessionInfo) diff --git a/libfreerdp/core/license.c b/libfreerdp/core/license.c index e0dd49c41..183242db8 100644 --- a/libfreerdp/core/license.c +++ b/libfreerdp/core/license.c @@ -610,13 +610,12 @@ BOOL license_generate_hwid(rdpLicense* license) { const BYTE* hashTarget; size_t targetLen; - BYTE macAddress[6]; + BYTE macAddress[6] = { 0 }; ZeroMemory(license->HardwareId, HWID_LENGTH); if (license->rdp->settings->OldLicenseBehaviour) { - ZeroMemory(macAddress, sizeof(macAddress)); hashTarget = macAddress; targetLen = sizeof(macAddress); } diff --git a/libfreerdp/core/test/TestConnect.c b/libfreerdp/core/test/TestConnect.c index d14f188fe..fa8068cbe 100644 --- a/libfreerdp/core/test/TestConnect.c +++ b/libfreerdp/core/test/TestConnect.c @@ -220,8 +220,8 @@ static int testSuccess(int port) { int r; int rc = -2; - STARTUPINFOA si; - PROCESS_INFORMATION process; + STARTUPINFOA si = { 0 }; + PROCESS_INFORMATION process = { 0 }; char arg1[] = "/v:127.0.0.1:XXXXX"; char* clientArgs[] = { "test", "/v:127.0.0.1:XXXXX", "/cert-ignore", "/rfx", NULL }; char* commandLine = NULL; @@ -266,7 +266,6 @@ static int testSuccess(int port) goto fail; _snprintf(commandLine, commandLineLen, "%s --port=%d", exe, port); - memset(&si, 0, sizeof(si)); si.cb = sizeof(si); if (!CreateProcessA(NULL, commandLine, NULL, NULL, FALSE, 0, NULL, wpath, &si, &process)) diff --git a/libfreerdp/locale/keyboard.c b/libfreerdp/locale/keyboard.c index 179d0f9e9..0466b348a 100644 --- a/libfreerdp/locale/keyboard.c +++ b/libfreerdp/locale/keyboard.c @@ -260,10 +260,10 @@ static int freerdp_keyboard_init_apple(DWORD* keyboardLayoutId, { DWORD vkcode; DWORD keycode; - DWORD keycode_to_vkcode[256]; - - ZeroMemory(keycode_to_vkcode, sizeof(keycode_to_vkcode)); + DWORD keycode_to_vkcode[256] = { 0 }; + WINPR_ASSERT(x11_keycode_to_rdp_scancode); + WINPR_ASSERT(keyboardLayoutId); for (keycode = 0; keycode < 256; keycode++) { vkcode = keycode_to_vkcode[keycode] = @@ -279,10 +279,10 @@ static int freerdp_keyboard_init_x11_evdev(DWORD* keyboardLayoutId, { DWORD vkcode; DWORD keycode; - DWORD keycode_to_vkcode[256]; - - ZeroMemory(keycode_to_vkcode, sizeof(keycode_to_vkcode)); + DWORD keycode_to_vkcode[256] = { 0 }; + WINPR_ASSERT(keyboardLayoutId); + WINPR_ASSERT(x11_keycode_to_rdp_scancode); for (keycode = 0; keycode < 256; keycode++) { vkcode = keycode_to_vkcode[keycode] = diff --git a/libfreerdp/locale/keyboard_xkbfile.c b/libfreerdp/locale/keyboard_xkbfile.c index 18879fd29..66863ffaf 100644 --- a/libfreerdp/locale/keyboard_xkbfile.c +++ b/libfreerdp/locale/keyboard_xkbfile.c @@ -332,6 +332,8 @@ int freerdp_keyboard_init_xkbfile(DWORD* keyboardLayoutId, DWORD x11_keycode_to_ { void* display; + WINPR_ASSERT(keyboardLayoutId); + WINPR_ASSERT(x11_keycode_to_rdp_scancode); ZeroMemory(x11_keycode_to_rdp_scancode, sizeof(DWORD) * 256); display = freerdp_keyboard_xkb_init(); diff --git a/libfreerdp/primitives/test/TestPrimitivesAdd.c b/libfreerdp/primitives/test/TestPrimitivesAdd.c index 56841d6a8..091527661 100644 --- a/libfreerdp/primitives/test/TestPrimitivesAdd.c +++ b/libfreerdp/primitives/test/TestPrimitivesAdd.c @@ -23,15 +23,13 @@ static BOOL test_add16s_func(void) { pstatus_t status; - INT16 ALIGN(src1[FUNC_TEST_SIZE + 3]), ALIGN(src2[FUNC_TEST_SIZE + 3]), - ALIGN(d1[FUNC_TEST_SIZE + 3]), ALIGN(d2[FUNC_TEST_SIZE + 3]); + INT16 ALIGN(src1[FUNC_TEST_SIZE + 3]) = { 0 }, ALIGN(src2[FUNC_TEST_SIZE + 3]) = { 0 }, + ALIGN(d1[FUNC_TEST_SIZE + 3]) = { 0 }, + ALIGN(d2[FUNC_TEST_SIZE + 3]) = { 0 }; - char testStr[256]; - testStr[0] = '\0'; + char testStr[256] = { 0 }; winpr_RAND((BYTE*)src1, sizeof(src1)); winpr_RAND((BYTE*)src2, sizeof(src2)); - memset(d1, 0, sizeof(d1)); - memset(d2, 0, sizeof(d2)); status = generic->add_16s(src1 + 1, src2 + 1, d1 + 1, FUNC_TEST_SIZE); if (status != PRIMITIVES_SUCCESS) return FALSE; diff --git a/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c b/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c index d584e0204..3237a7095 100644 --- a/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c +++ b/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c @@ -134,7 +134,6 @@ static BOOL test_alphaComp_func(void) for (i = 0; i < sizeof(src2) / 4; ++i) *ptr++ |= 0xFF000000U; - memset(dst1, 0, sizeof(dst1)); status = generic->alphaComp_argb(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT); @@ -164,7 +163,7 @@ static int test_alphaComp_speed(void) BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]) = { 0 }; BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]) = { 0 }; BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]) = { 0 }; - char testStr[256]; + char testStr[256] = { 0 }; UINT32* ptr; UINT32 i; testStr[0] = '\0'; @@ -179,8 +178,6 @@ static int test_alphaComp_speed(void) for (i = 0; i < sizeof(src2) / 4; ++i) *ptr++ |= 0xFF000000U; - memset(dst1, 0, sizeof(dst1)); - if (!speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->alphaComp_argb, (speed_test_fkt)optimized->alphaComp_argb, src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT)) diff --git a/libfreerdp/primitives/test/TestPrimitivesColors.c b/libfreerdp/primitives/test/TestPrimitivesColors.c index 8a8a24fed..291f42a06 100644 --- a/libfreerdp/primitives/test/TestPrimitivesColors.c +++ b/libfreerdp/primitives/test/TestPrimitivesColors.c @@ -163,9 +163,9 @@ static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(void) static BOOL test_yCbCrToRGB_16s16s_P3P3_func(void) { pstatus_t status; - INT16 ALIGN(y[4096]), ALIGN(cb[4096]), ALIGN(cr[4096]); - INT16 ALIGN(r1[4096]), ALIGN(g1[4096]), ALIGN(b1[4096]); - INT16 ALIGN(r2[4096]), ALIGN(g2[4096]), ALIGN(b2[4096]); + INT16 ALIGN(y[4096]) = { 0 }, ALIGN(cb[4096]) = { 0 }, ALIGN(cr[4096]) = { 0 }; + INT16 ALIGN(r1[4096]) = { 0 }, ALIGN(g1[4096]) = { 0 }, ALIGN(b1[4096]) = { 0 }; + INT16 ALIGN(r2[4096]) = { 0 }, ALIGN(g2[4096]) = { 0 }, ALIGN(b2[4096]) = { 0 }; int i; const INT16* in[3]; INT16* out1[3]; @@ -183,12 +183,6 @@ static BOOL test_yCbCrToRGB_16s16s_P3P3_func(void) cr[i] &= 0x1FE0U; } - memset(r1, 0, sizeof(r1)); - memset(g1, 0, sizeof(g1)); - memset(b1, 0, sizeof(b1)); - memset(r2, 0, sizeof(r2)); - memset(g2, 0, sizeof(g2)); - memset(b2, 0, sizeof(b2)); in[0] = y; in[1] = cb; in[2] = cr; diff --git a/libfreerdp/primitives/test/TestPrimitivesCopy.c b/libfreerdp/primitives/test/TestPrimitivesCopy.c index b72913217..6b216a8c2 100644 --- a/libfreerdp/primitives/test/TestPrimitivesCopy.c +++ b/libfreerdp/primitives/test/TestPrimitivesCopy.c @@ -25,7 +25,6 @@ static BOOL test_copy8u_func(void) primitives_t* prims = primitives_get(); BYTE ALIGN(data[COPY_TESTSIZE + 15]) = { 0 }; int i, soff; - BYTE ALIGN(dest[COPY_TESTSIZE + 15]) = { 0 }; winpr_RAND(data, sizeof(data)); for (soff = 0; soff < 16; ++soff) @@ -38,7 +37,7 @@ static BOOL test_copy8u_func(void) for (length = 1; length <= COPY_TESTSIZE - doff; ++length) { - memset(dest, 0, sizeof(dest)); + BYTE ALIGN(dest[COPY_TESTSIZE + 15]) = { 0 }; if (prims->copy_8u(data + soff, dest + doff, length) != PRIMITIVES_SUCCESS) return FALSE; diff --git a/libfreerdp/primitives/test/TestPrimitivesSet.c b/libfreerdp/primitives/test/TestPrimitivesSet.c index 712aa0241..eaf7ba0a0 100644 --- a/libfreerdp/primitives/test/TestPrimitivesSet.c +++ b/libfreerdp/primitives/test/TestPrimitivesSet.c @@ -40,13 +40,13 @@ static BOOL test_set8u_func(void) { pstatus_t status; UINT32 off; - BYTE dest[1024]; for (off = 0; off < 16; ++off) { UINT32 len; - memset(dest, 3, sizeof(dest)); + BYTE dest[1024]; + memset(dest, 3, sizeof(dest)); for (len = 1; len < 48 - off; ++len) { status = generic->set_8u(0xa5, dest + off, len); @@ -62,8 +62,9 @@ static BOOL test_set8u_func(void) for (off = 0; off < 16; ++off) { UINT32 len; - memset(dest, 3, sizeof(dest)); + BYTE dest[1024]; + memset(dest, 3, sizeof(dest)); for (len = 1; len < 48 - off; ++len) { status = optimized->set_8u(0xa5, dest + off, len); @@ -121,13 +122,12 @@ static BOOL test_set32s_func(void) { pstatus_t status; UINT32 off; - INT32 dest[1024]; const INT32 value = -0x12345678; for (off = 0; off < 16; ++off) { UINT32 len; - memset(dest, 0, sizeof(dest)); + INT32 dest[1024] = { 0 }; for (len = 1; len < 48 - off; ++len) { @@ -144,7 +144,7 @@ static BOOL test_set32s_func(void) for (off = 0; off < 16; ++off) { UINT32 len; - memset(dest, 0, sizeof(dest)); + INT32 dest[1024] = { 0 }; for (len = 1; len < 48 - off; ++len) { @@ -184,13 +184,12 @@ static BOOL test_set32u_func(void) { pstatus_t status; UINT32 off; - UINT32 dest[1024]; const UINT32 value = 0xABCDEF12; for (off = 0; off < 16; ++off) { UINT32 len; - memset(dest, 0, sizeof(dest)); + UINT32 dest[1024] = { 0 }; for (len = 1; len < 48 - off; ++len) { @@ -207,7 +206,7 @@ static BOOL test_set32u_func(void) for (off = 0; off < 16; ++off) { UINT32 len; - memset(dest, 0, sizeof(dest)); + UINT32 dest[1024] = { 0 }; for (len = 1; len < 48 - off; ++len) { diff --git a/libfreerdp/primitives/test/TestPrimitivesSign.c b/libfreerdp/primitives/test/TestPrimitivesSign.c index 3933783bd..ca6464338 100644 --- a/libfreerdp/primitives/test/TestPrimitivesSign.c +++ b/libfreerdp/primitives/test/TestPrimitivesSign.c @@ -27,8 +27,6 @@ static BOOL test_sign16s_func(void) INT16 ALIGN(d1[TEST_BUFFER_SIZE + 16]) = { 0 }; INT16 ALIGN(d2[TEST_BUFFER_SIZE + 16]) = { 0 }; winpr_RAND((BYTE*)src, sizeof(src)); - memset(d1, 0, sizeof(d1)); - memset(d2, 0, sizeof(d2)); status = generic->sign_16s(src + 1, d1 + 1, TEST_BUFFER_SIZE); if (status != PRIMITIVES_SUCCESS) diff --git a/libfreerdp/utils/smartcard_pack.c b/libfreerdp/utils/smartcard_pack.c index bb7d4ccfd..693c5c750 100644 --- a/libfreerdp/utils/smartcard_pack.c +++ b/libfreerdp/utils/smartcard_pack.c @@ -1607,6 +1607,7 @@ SCARDCONTEXT smartcard_scard_context_native_from_redir(REDIR_SCARDCONTEXT* conte void smartcard_scard_context_native_to_redir(REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext) { + WINPR_ASSERT(context); ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT)); context->cbContext = sizeof(ULONG_PTR); CopyMemory(&(context->pbContext), &hContext, context->cbContext); @@ -1636,6 +1637,7 @@ SCARDHANDLE smartcard_scard_handle_native_from_redir(REDIR_SCARDHANDLE* handle) void smartcard_scard_handle_native_to_redir(REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard) { + WINPR_ASSERT(handle); ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE)); handle->cbHandle = sizeof(ULONG_PTR); CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle); @@ -1647,6 +1649,7 @@ LONG smartcard_unpack_redir_scard_context_(wStream* s, REDIR_SCARDCONTEXT* conte UINT32 pbContextNdrPtr; WINPR_UNUSED(file); + WINPR_ASSERT(context); ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT)); @@ -1704,6 +1707,7 @@ LONG smartcard_unpack_redir_scard_context_ref(wStream* s, REDIR_SCARDCONTEXT* co { UINT32 length; + WINPR_ASSERT(context); if (context->cbContext == 0) return SCARD_S_SUCCESS; @@ -1752,6 +1756,7 @@ LONG smartcard_pack_redir_scard_context_ref(wStream* s, const REDIR_SCARDCONTEXT LONG smartcard_unpack_redir_scard_handle_(wStream* s, REDIR_SCARDHANDLE* handle, UINT32* index, const char* file, const char* function, int line) { + WINPR_ASSERT(handle); ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE)); if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) diff --git a/server/Mac/mf_event.c b/server/Mac/mf_event.c index 686c8b818..e30b9ac22 100644 --- a/server/Mac/mf_event.c +++ b/server/Mac/mf_event.c @@ -34,11 +34,10 @@ int mf_is_event_set(mfEventQueue* event_queue) { fd_set rfds; int num_set; - struct timeval time; + struct timeval time = { 0 }; FD_ZERO(&rfds); FD_SET(event_queue->pipe_fd[0], &rfds); - memset(&time, 0, sizeof(time)); num_set = select(event_queue->pipe_fd[0] + 1, &rfds, 0, 0, &time); return (num_set == 1); diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 15bfeecf8..f5d11f9a8 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -298,7 +298,7 @@ static BOOL test_peer_load_icon(freerdp_peer* client) testPeerContext* context; FILE* fp; int i; - char line[50]; + char line[50] = { 0 }; BYTE* rgb_data = NULL; int c; rdpSettings* settings; diff --git a/server/Windows/wf_dxgi.c b/server/Windows/wf_dxgi.c index 0bce60e50..fe84d2d6e 100644 --- a/server/Windows/wf_dxgi.c +++ b/server/Windows/wf_dxgi.c @@ -107,7 +107,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi) { HRESULT status; UINT dTop, i = 0; - DXGI_OUTPUT_DESC desc; + DXGI_OUTPUT_DESC desc = { 0 }; IDXGIOutput* pOutput; IDXGIDevice* DxgiDevice = NULL; IDXGIAdapter* DxgiAdapter = NULL; @@ -132,7 +132,6 @@ int wf_dxgi_getDuplication(wfInfo* wfi) return 1; } - ZeroMemory(&desc, sizeof(desc)); pOutput = NULL; while (DxgiAdapter->lpVtbl->EnumOutputs(DxgiAdapter, i, &pOutput) != DXGI_ERROR_NOT_FOUND) diff --git a/server/Windows/wf_input.c b/server/Windows/wf_input.c index aba1fcc55..a9fdd4555 100644 --- a/server/Windows/wf_input.c +++ b/server/Windows/wf_input.c @@ -65,10 +65,11 @@ BOOL wf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) BOOL wf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - INPUT mouse_event; + INPUT mouse_event = { 0 }; float width, height; WINPR_UNUSED(input); - ZeroMemory(&mouse_event, sizeof(INPUT)); + + WINPR_ASSERT(input); mouse_event.type = INPUT_MOUSE; if (flags & PTR_FLAGS_WHEEL) @@ -142,8 +143,7 @@ BOOL wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT1 { if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2)) { - INPUT mouse_event; - ZeroMemory(&mouse_event, sizeof(INPUT)); + INPUT mouse_event = { 0 }; mouse_event.type = INPUT_MOUSE; if (flags & PTR_FLAGS_MOVE) diff --git a/server/shadow/Win/win_dxgi.c b/server/shadow/Win/win_dxgi.c index 5790c984e..0d16db970 100644 --- a/server/shadow/Win/win_dxgi.c +++ b/server/shadow/Win/win_dxgi.c @@ -296,7 +296,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) HRESULT hr; UINT dTop, i = 0; IDXGIOutput* pOutput; - DXGI_OUTPUT_DESC outputDesc; + DXGI_OUTPUT_DESC outputDesc = { 0 }; DXGI_OUTPUT_DESC* pOutputDesc; D3D11_TEXTURE2D_DESC textureDesc; IDXGIDevice* dxgiDevice = NULL; @@ -330,7 +330,6 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) } pOutput = NULL; - ZeroMemory(&outputDesc, sizeof(outputDesc)); while (dxgiAdapter->lpVtbl->EnumOutputs(dxgiAdapter, i, &pOutput) != DXGI_ERROR_NOT_FOUND) { diff --git a/server/shadow/Win/win_rdp.c b/server/shadow/Win/win_rdp.c index 170d562c2..70e7dd460 100644 --- a/server/shadow/Win/win_rdp.c +++ b/server/shadow/Win/win_rdp.c @@ -355,8 +355,8 @@ int shw_RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) int win_shadow_rdp_init(winShadowSubsystem* subsystem) { rdpContext* context; - RDP_CLIENT_ENTRY_POINTS clientEntryPoints; - ZeroMemory(&clientEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS)); + RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 }; + clientEntryPoints.Size = sizeof(RDP_CLIENT_ENTRY_POINTS); clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION; shw_RdpClientEntry(&clientEntryPoints); diff --git a/server/shadow/Win/win_shadow.c b/server/shadow/Win/win_shadow.c index 0595d3ec4..058d52527 100644 --- a/server/shadow/Win/win_shadow.c +++ b/server/shadow/Win/win_shadow.c @@ -94,10 +94,10 @@ static BOOL win_shadow_input_mouse_event(rdpShadowSubsystem* subsystem, rdpShado UINT16 flags, UINT16 x, UINT16 y) { UINT rc = 1; - INPUT event; + INPUT event = { 0 }; float width; float height; - ZeroMemory(&event, sizeof(INPUT)); + event.type = INPUT_MOUSE; if (flags & (PTR_FLAGS_WHEEL | PTR_FLAGS_HWHEEL)) @@ -179,10 +179,9 @@ static BOOL win_shadow_input_extended_mouse_event(rdpShadowSubsystem* subsystem, UINT16 y) { UINT rc = 1; - INPUT event; + INPUT event = { 0 }; float width; float height; - ZeroMemory(&event, sizeof(INPUT)); if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2)) { @@ -425,8 +424,8 @@ static UINT32 win_shadow_enum_monitors(MONITOR_DEF* monitors, UINT32 maxMonitors DWORD iDevNum = 0; int numMonitors = 0; MONITOR_DEF* monitor; - DISPLAY_DEVICE displayDevice; - ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE)); + DISPLAY_DEVICE displayDevice = { 0 }; + displayDevice.cb = sizeof(DISPLAY_DEVICE); if (EnumDisplayDevices(NULL, iDevNum, &displayDevice, 0)) diff --git a/server/shadow/Win/win_wds.c b/server/shadow/Win/win_wds.c index e0da3da58..40608faf4 100644 --- a/server/shadow/Win/win_wds.c +++ b/server/shadow/Win/win_wds.c @@ -478,9 +478,9 @@ int win_shadow_wds_wnd_init(winShadowSubsystem* subsystem) { HMODULE hModule; HINSTANCE hInstance; - WNDCLASSEX wndClassEx; + WNDCLASSEX wndClassEx = { 0 }; hModule = GetModuleHandle(NULL); - ZeroMemory(&wndClassEx, sizeof(WNDCLASSEX)); + wndClassEx.cbSize = sizeof(WNDCLASSEX); wndClassEx.style = 0; wndClassEx.lpfnWndProc = ShadowWndProc; diff --git a/server/shadow/X11/x11_shadow.c b/server/shadow/X11/x11_shadow.c index c2028cf05..dacfa4662 100644 --- a/server/shadow/X11/x11_shadow.c +++ b/server/shadow/X11/x11_shadow.c @@ -1251,7 +1251,7 @@ static int x11_shadow_subsystem_init(rdpShadowSubsystem* sub) char** extensions; XVisualInfo* vi; XVisualInfo* vis; - XVisualInfo template; + XVisualInfo template = { 0 }; XPixmapFormatValues* pf; XPixmapFormatValues* pfs; @@ -1306,7 +1306,6 @@ static int x11_shadow_subsystem_init(rdpShadowSubsystem* sub) } XFree(pfs); - ZeroMemory(&template, sizeof(template)); template.class = TrueColor; template.screen = subsystem->number; vis = XGetVisualInfo(subsystem->display, VisualClassMask | VisualScreenMask, &template, diff --git a/server/shadow/shadow_capture.c b/server/shadow/shadow_capture.c index 927b55fb0..3d2dbcd19 100644 --- a/server/shadow/shadow_capture.c +++ b/server/shadow/shadow_capture.c @@ -89,7 +89,7 @@ int shadow_capture_compare(BYTE* pData1, UINT32 nStep1, UINT32 nWidth, UINT32 nH BYTE *p1, *p2; BOOL rows[1024]; #ifdef WITH_DEBUG_SHADOW_CAPTURE - BOOL cols[1024]; + BOOL cols[1024] = { FALSE }; #endif allEqual = TRUE; ZeroMemory(rect, sizeof(RECTANGLE_16)); diff --git a/server/shadow/shadow_subsystem.c b/server/shadow/shadow_subsystem.c index 9b3a356af..a1d5190d5 100644 --- a/server/shadow/shadow_subsystem.c +++ b/server/shadow/shadow_subsystem.c @@ -31,6 +31,7 @@ void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry) static int shadow_subsystem_load_entry_points(RDP_SHADOW_ENTRY_POINTS* pEntryPoints) { + WINPR_ASSERT(pEntryPoints); ZeroMemory(pEntryPoints, sizeof(RDP_SHADOW_ENTRY_POINTS)); if (!pSubsystemEntry) diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index 56c051e50..e89c51617 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -472,7 +472,7 @@ error_handle: */ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) { - struct termios upcomingTermios; + struct termios upcomingTermios = { 0 }; WINPR_COMM* pComm = (WINPR_COMM*)hFile; DWORD bytesReturned; @@ -535,8 +535,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) return FALSE; } - SERIAL_HANDFLOW handflow; - ZeroMemory(&handflow, sizeof(SERIAL_HANDFLOW)); + SERIAL_HANDFLOW handflow = { 0 }; if (lpDCB->fOutxCtsFlow) { @@ -641,7 +640,6 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) } /** upcomingTermios stage **/ - ZeroMemory(&upcomingTermios, sizeof(struct termios)); if (tcgetattr(pComm->fd, &upcomingTermios) < 0) /* NB: preserves current settings not directly handled by the Communication Functions */ diff --git a/winpr/libwinpr/comm/comm_ioctl.c b/winpr/libwinpr/comm/comm_ioctl.c index 3742bb689..f81613791 100644 --- a/winpr/libwinpr/comm/comm_ioctl.c +++ b/winpr/libwinpr/comm/comm_ioctl.c @@ -687,7 +687,7 @@ BOOL CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffe int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios* termios_p) { int result; - struct termios currentState; + struct termios currentState = { 0 }; if ((result = tcsetattr(fd, optional_actions, termios_p)) < 0) { @@ -696,7 +696,6 @@ int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios* te } /* NB: tcsetattr() can succeed even if not all changes have been applied. */ - ZeroMemory(¤tState, sizeof(struct termios)); if ((result = tcgetattr(fd, ¤tState)) < 0) { CommLog_Print(WLOG_WARN, "tcgetattr failure, errno: %d", errno); diff --git a/winpr/libwinpr/comm/comm_sercx2_sys.c b/winpr/libwinpr/comm/comm_sercx2_sys.c index 34ff7a57a..66bd8616d 100644 --- a/winpr/libwinpr/comm/comm_sercx2_sys.c +++ b/winpr/libwinpr/comm/comm_sercx2_sys.c @@ -47,6 +47,7 @@ static BOOL _set_serial_chars(WINPR_COMM* pComm, const SERIAL_CHARS* pSerialChar static BOOL _get_serial_chars(WINPR_COMM* pComm, SERIAL_CHARS* pSerialChars) { + WINPR_ASSERT(pSerialChars); ZeroMemory(pSerialChars, sizeof(SERIAL_CHARS)); return TRUE; } diff --git a/winpr/libwinpr/comm/comm_serial_sys.c b/winpr/libwinpr/comm/comm_serial_sys.c index ce8934ecd..dd254cb28 100644 --- a/winpr/libwinpr/comm/comm_serial_sys.c +++ b/winpr/libwinpr/comm/comm_serial_sys.c @@ -167,7 +167,7 @@ static BOOL _get_properties(WINPR_COMM* pComm, COMMPROP* pProperties) /* FIXME: properties should be better probed. The current * implementation just relies on the Linux' implementation. */ - + WINPR_ASSERT(pProperties); if (pProperties->dwProvSpec1 != COMMPROP_INITIALIZED) { ZeroMemory(pProperties, sizeof(COMMPROP)); diff --git a/winpr/libwinpr/comm/test/TestCommConfig.c b/winpr/libwinpr/comm/test/TestCommConfig.c index 0d89149d8..c405f14dd 100644 --- a/winpr/libwinpr/comm/test/TestCommConfig.c +++ b/winpr/libwinpr/comm/test/TestCommConfig.c @@ -28,12 +28,12 @@ int TestCommConfig(int argc, char* argv[]) { - DCB dcb; + DCB dcb = { 0 }; HANDLE hComm; BOOL success; LPCSTR lpFileName = "\\\\.\\COM1"; - COMMPROP commProp; - struct stat statbuf; + COMMPROP commProp = { 0 }; + struct stat statbuf = { 0 }; hComm = CreateFileA(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); @@ -82,7 +82,6 @@ int TestCommConfig(int argc, char* argv[]) /* TODO: a second call to CreateFileA should failed and * GetLastError should return ERROR_SHARING_VIOLATION */ - ZeroMemory(&dcb, sizeof(DCB)); dcb.DCBlength = sizeof(DCB); success = GetCommState(hComm, &dcb); if (!success) @@ -95,7 +94,6 @@ int TestCommConfig(int argc, char* argv[]) "BaudRate: %" PRIu32 " ByteSize: %" PRIu8 " Parity: %" PRIu8 " StopBits: %" PRIu8 "\n", dcb.BaudRate, dcb.ByteSize, dcb.Parity, dcb.StopBits); - ZeroMemory(&commProp, sizeof(COMMPROP)); if (!GetCommProperties(hComm, &commProp)) { fprintf(stderr, "GetCommProperties failure: GetLastError(): 0x%08x\n", GetLastError()); diff --git a/winpr/libwinpr/comm/test/TestCommMonitor.c b/winpr/libwinpr/comm/test/TestCommMonitor.c index aa295bbfe..fe28a86bf 100644 --- a/winpr/libwinpr/comm/test/TestCommMonitor.c +++ b/winpr/libwinpr/comm/test/TestCommMonitor.c @@ -11,7 +11,7 @@ int TestCommMonitor(int argc, char* argv[]) DWORD dwError; BOOL fSuccess; DWORD dwEvtMask; - OVERLAPPED overlapped; + OVERLAPPED overlapped = { 0 }; LPCSTR lpFileName = "\\\\.\\COM1"; hComm = CreateFileA(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, @@ -31,7 +31,6 @@ int TestCommMonitor(int argc, char* argv[]) return -1; } - ZeroMemory(&overlapped, sizeof(OVERLAPPED)); if (!(overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) { printf("CreateEvent failed: GetLastError() = %" PRIu32 "\n", GetLastError()); diff --git a/winpr/libwinpr/comm/test/TestSerialChars.c b/winpr/libwinpr/comm/test/TestSerialChars.c index f2c605e4a..b235321fa 100644 --- a/winpr/libwinpr/comm/test/TestSerialChars.c +++ b/winpr/libwinpr/comm/test/TestSerialChars.c @@ -31,19 +31,17 @@ static BOOL test_SerCxSys(HANDLE hComm) { - DCB dcb; + DCB dcb = { 0 }; UCHAR XonChar, XoffChar; - struct termios currentTermios; + struct termios currentTermios = { 0 }; - ZeroMemory(¤tTermios, sizeof(struct termios)); if (tcgetattr(((WINPR_COMM*)hComm)->fd, ¤tTermios) < 0) { fprintf(stderr, "tcgetattr failure.\n"); return FALSE; } - ZeroMemory(&dcb, sizeof(DCB)); dcb.DCBlength = sizeof(DCB); if (!GetCommState(hComm, &dcb)) { @@ -111,9 +109,8 @@ static BOOL test_SerCxSys(HANDLE hComm) static BOOL test_SerCx2Sys(HANDLE hComm) { - DCB dcb; + DCB dcb = { 0 }; - ZeroMemory(&dcb, sizeof(DCB)); dcb.DCBlength = sizeof(DCB); if (!GetCommState(hComm, &dcb)) { diff --git a/winpr/libwinpr/comm/test/TestSetCommState.c b/winpr/libwinpr/comm/test/TestSetCommState.c index 53f976477..0204058aa 100644 --- a/winpr/libwinpr/comm/test/TestSetCommState.c +++ b/winpr/libwinpr/comm/test/TestSetCommState.c @@ -27,6 +27,8 @@ static void init_empty_dcb(DCB* pDcb) { + WINPR_ASSERT(pDcb); + ZeroMemory(pDcb, sizeof(DCB)); pDcb->DCBlength = sizeof(DCB); pDcb->XonChar = 1; diff --git a/winpr/libwinpr/comm/test/TestTimeouts.c b/winpr/libwinpr/comm/test/TestTimeouts.c index 06075924a..c2d3be827 100644 --- a/winpr/libwinpr/comm/test/TestTimeouts.c +++ b/winpr/libwinpr/comm/test/TestTimeouts.c @@ -31,7 +31,7 @@ static BOOL test_generic(HANDLE hComm) { - COMMTIMEOUTS timeouts, timeouts2; + COMMTIMEOUTS timeouts = { 0 }, timeouts2 = { 0 }; timeouts.ReadIntervalTimeout = 1; timeouts.ReadTotalTimeoutMultiplier = 2; @@ -45,7 +45,6 @@ static BOOL test_generic(HANDLE hComm) return FALSE; } - ZeroMemory(&timeouts2, sizeof(COMMTIMEOUTS)); if (!GetCommTimeouts(hComm, &timeouts2)) { fprintf(stderr, "GetCommTimeouts failure, GetLastError: 0x%08x\n", GetLastError()); diff --git a/winpr/libwinpr/crypto/test/TestCryptoCipher.c b/winpr/libwinpr/crypto/test/TestCryptoCipher.c index e93bc4054..f20de689a 100644 --- a/winpr/libwinpr/crypto/test/TestCryptoCipher.c +++ b/winpr/libwinpr/crypto/test/TestCryptoCipher.c @@ -10,8 +10,8 @@ static BOOL test_crypto_cipher_aes_128_cbc() BOOL result = FALSE; BYTE key[] = "0123456789abcdeF"; BYTE iv[] = "1234567887654321"; - BYTE ibuf[1024]; - BYTE obuf[1024]; + BYTE ibuf[1024] = { 0 }; + BYTE obuf[1024] = { 0 }; size_t ilen; size_t olen; size_t xlen; @@ -26,9 +26,6 @@ static BOOL test_crypto_cipher_aes_128_cbc() return FALSE; } - memset(ibuf, 0, sizeof(ibuf)); - memset(obuf, 0, sizeof(obuf)); - ilen = strnlen(plaintext, sizeof(plaintext)) + 1; memcpy(ibuf, plaintext, ilen); @@ -181,13 +178,10 @@ static const BYTE* TEST_CIPHER_IV = static BOOL test_crypto_cipher_key() { int status; - BYTE key[32]; - BYTE iv[16]; + BYTE key[32] = { 0 }; + BYTE iv[16] = { 0 }; BYTE salt[8] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; - ZeroMemory(key, sizeof(key)); - ZeroMemory(iv, sizeof(iv)); - status = winpr_Cipher_BytesToKey(WINPR_CIPHER_AES_256_CBC, WINPR_MD_SHA1, salt, TEST_RAND_DATA, 64, 4, key, iv); diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index ad886881a..9ae8eb2c6 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -1123,9 +1123,7 @@ HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { HANDLE hFile; - CREATEFILE2_EXTENDED_PARAMETERS params; - - ZeroMemory(¶ms, sizeof(CREATEFILE2_EXTENDED_PARAMETERS)); + CREATEFILE2_EXTENDED_PARAMETERS params = { 0 }; params.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS); diff --git a/winpr/libwinpr/file/namedPipeClient.c b/winpr/libwinpr/file/namedPipeClient.c index ffa11eda6..7593d6287 100644 --- a/winpr/libwinpr/file/namedPipeClient.c +++ b/winpr/libwinpr/file/namedPipeClient.c @@ -126,7 +126,7 @@ static HANDLE NamedPipeClientCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAcces char* name; int status; HANDLE hNamedPipe; - struct sockaddr_un s; + struct sockaddr_un s = { 0 }; WINPR_NAMED_PIPE* pNamedPipe; if (dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED) @@ -196,7 +196,6 @@ static HANDLE NamedPipeClientCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAcces pNamedPipe->clientfd = socket(PF_LOCAL, SOCK_STREAM, 0); pNamedPipe->serverfd = -1; pNamedPipe->ServerMode = FALSE; - ZeroMemory(&s, sizeof(struct sockaddr_un)); s.sun_family = AF_UNIX; sprintf_s(s.sun_path, ARRAYSIZE(s.sun_path), "%s", pNamedPipe->lpFilePath); status = connect(pNamedPipe->clientfd, (struct sockaddr*)&s, sizeof(struct sockaddr_un)); diff --git a/winpr/libwinpr/io/io.c b/winpr/libwinpr/io/io.c index 68a689734..dbd5e3437 100644 --- a/winpr/libwinpr/io/io.c +++ b/winpr/libwinpr/io/io.c @@ -96,13 +96,12 @@ BOOL GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped, else if (request == 2) { socklen_t length; - struct sockaddr_un s; + struct sockaddr_un s = { 0 }; if (pipe->serverfd == -1) return FALSE; length = sizeof(struct sockaddr_un); - ZeroMemory(&s, sizeof(struct sockaddr_un)); status = accept(pipe->serverfd, (struct sockaddr*)&s, &length); diff --git a/winpr/libwinpr/nt/test/TestNtCreateFile.c b/winpr/libwinpr/nt/test/TestNtCreateFile.c index 18e21fe93..94305c90b 100644 --- a/winpr/libwinpr/nt/test/TestNtCreateFile.c +++ b/winpr/libwinpr/nt/test/TestNtCreateFile.c @@ -18,8 +18,8 @@ int TestNtCreateFile(int argc, char* argv[]) UNICODE_STRING uString; ULONG CreateDisposition; ACCESS_MASK DesiredAccess = 0; - OBJECT_ATTRIBUTES attributes; - IO_STATUS_BLOCK ioStatusBlock; + OBJECT_ATTRIBUTES attributes = { 0 }; + IO_STATUS_BLOCK ioStatusBlock = { 0 }; int result = -1; WINPR_UNUSED(argc); @@ -35,7 +35,6 @@ int TestNtCreateFile(int argc, char* argv[]) } handle = NULL; - ZeroMemory(&ioStatusBlock, sizeof(IO_STATUS_BLOCK)); _InitializeObjectAttributes(&attributes, &uString, 0, NULL, NULL); DesiredAccess = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE; CreateOptions = FILE_DIRECTORY_FILE | FILE_WRITE_THROUGH; diff --git a/winpr/libwinpr/pipe/pipe.c b/winpr/libwinpr/pipe/pipe.c index ec7252d51..faf8acbae 100644 --- a/winpr/libwinpr/pipe/pipe.c +++ b/winpr/libwinpr/pipe/pipe.c @@ -560,7 +560,6 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD { size_t index; char* lpPipePath; - struct sockaddr_un s; WINPR_NAMED_PIPE* pNamedPipe = NULL; int serverfd = -1; NamedPipeServerSocketEntry* baseSocket = NULL; @@ -627,6 +626,7 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD /* If this is the first instance of the named pipe... */ if (serverfd == -1) { + struct sockaddr_un s = { 0 }; /* Create the UNIX domain socket and start listening. */ if (!(lpPipePath = GetNamedPipeUnixDomainSocketBaseFilePathA())) goto out; @@ -653,7 +653,6 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD goto out; } - ZeroMemory(&s, sizeof(struct sockaddr_un)); s.sun_family = AF_UNIX; sprintf_s(s.sun_path, ARRAYSIZE(s.sun_path), "%s", pNamedPipe->lpFilePath); @@ -735,7 +734,6 @@ BOOL ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped) { int status; socklen_t length; - struct sockaddr_un s; WINPR_NAMED_PIPE* pNamedPipe; if (lpOverlapped) @@ -752,8 +750,8 @@ BOOL ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped) if (!(pNamedPipe->dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED)) { + struct sockaddr_un s = { 0 }; length = sizeof(struct sockaddr_un); - ZeroMemory(&s, sizeof(struct sockaddr_un)); status = accept(pNamedPipe->serverfd, (struct sockaddr*)&s, &length); if (status < 0) diff --git a/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipe.c b/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipe.c index 9a96358d6..bff822015 100644 --- a/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipe.c +++ b/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipe.c @@ -191,18 +191,14 @@ out: #define TESTNUMPIPESST 16 static DWORD WINAPI named_pipe_single_thread(LPVOID arg) { - HANDLE servers[TESTNUMPIPESST]; - HANDLE clients[TESTNUMPIPESST]; - char sndbuf[PIPE_BUFFER_SIZE]; - char rcvbuf[PIPE_BUFFER_SIZE]; + HANDLE servers[TESTNUMPIPESST] = { 0 }; + HANDLE clients[TESTNUMPIPESST] = { 0 }; DWORD dwRead; DWORD dwWritten; int i; int numPipes; BOOL bSuccess = FALSE; numPipes = TESTNUMPIPESST; - memset(servers, 0, sizeof(servers)); - memset(clients, 0, sizeof(clients)); WaitForSingleObject(ReadyEvent, INFINITE); for (i = 0; i < numPipes; i++) @@ -306,52 +302,59 @@ static DWORD WINAPI named_pipe_single_thread(LPVOID arg) for (i = 0; i < numPipes; i++) { - /* Test writing from clients to servers */ - ZeroMemory(sndbuf, sizeof(sndbuf)); - ZeroMemory(rcvbuf, sizeof(rcvbuf)); - sprintf_s(sndbuf, sizeof(sndbuf), "CLIENT->SERVER ON PIPE #%05d", i); - - if (!WriteFile(clients[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL) || - dwWritten != sizeof(sndbuf)) { - printf("%s: Error writing to client end of pipe #%d\n", __FUNCTION__, i); - goto out; + char sndbuf[PIPE_BUFFER_SIZE] = { 0 }; + char rcvbuf[PIPE_BUFFER_SIZE] = { 0 }; + /* Test writing from clients to servers */ + sprintf_s(sndbuf, sizeof(sndbuf), "CLIENT->SERVER ON PIPE #%05d", i); + + if (!WriteFile(clients[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL) || + dwWritten != sizeof(sndbuf)) + { + printf("%s: Error writing to client end of pipe #%d\n", __FUNCTION__, i); + goto out; + } + + if (!ReadFile(servers[i], rcvbuf, dwWritten, &dwRead, NULL) || dwRead != dwWritten) + { + printf("%s: Error reading on server end of pipe #%d\n", __FUNCTION__, i); + goto out; + } + + if (memcmp(sndbuf, rcvbuf, sizeof(sndbuf))) + { + printf("%s: Error data read on server end of pipe #%d is corrupted\n", __FUNCTION__, + i); + goto out; + } } - - if (!ReadFile(servers[i], rcvbuf, dwWritten, &dwRead, NULL) || dwRead != dwWritten) { - printf("%s: Error reading on server end of pipe #%d\n", __FUNCTION__, i); - goto out; - } - if (memcmp(sndbuf, rcvbuf, sizeof(sndbuf))) - { - printf("%s: Error data read on server end of pipe #%d is corrupted\n", __FUNCTION__, i); - goto out; - } + char sndbuf[PIPE_BUFFER_SIZE] = { 0 }; + char rcvbuf[PIPE_BUFFER_SIZE] = { 0 }; + /* Test writing from servers to clients */ - /* Test writing from servers to clients */ - ZeroMemory(sndbuf, sizeof(sndbuf)); - ZeroMemory(rcvbuf, sizeof(rcvbuf)); - sprintf_s(sndbuf, sizeof(sndbuf), "SERVER->CLIENT ON PIPE #%05d", i); + sprintf_s(sndbuf, sizeof(sndbuf), "SERVER->CLIENT ON PIPE #%05d", i); - if (!WriteFile(servers[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL) || - dwWritten != sizeof(sndbuf)) - { - printf("%s: Error writing to server end of pipe #%d\n", __FUNCTION__, i); - goto out; - } + if (!WriteFile(servers[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL) || + dwWritten != sizeof(sndbuf)) + { + printf("%s: Error writing to server end of pipe #%d\n", __FUNCTION__, i); + goto out; + } - if (!ReadFile(clients[i], rcvbuf, dwWritten, &dwRead, NULL) || dwRead != dwWritten) - { - printf("%s: Error reading on client end of pipe #%d\n", __FUNCTION__, i); - goto out; - } + if (!ReadFile(clients[i], rcvbuf, dwWritten, &dwRead, NULL) || dwRead != dwWritten) + { + printf("%s: Error reading on client end of pipe #%d\n", __FUNCTION__, i); + goto out; + } - if (memcmp(sndbuf, rcvbuf, sizeof(sndbuf))) - { - printf("%s: Error data read on client end of pipe #%d is corrupted\n", __FUNCTION__, i); - goto out; + if (memcmp(sndbuf, rcvbuf, sizeof(sndbuf))) + { + printf("%s: Error data read on client end of pipe #%d is corrupted\n", __FUNCTION__, + i); + goto out; + } } } @@ -362,23 +365,26 @@ static DWORD WINAPI named_pipe_single_thread(LPVOID arg) */ i = numPipes - 1; DisconnectNamedPipe(servers[i]); - - if (ReadFile(clients[i], rcvbuf, sizeof(rcvbuf), &dwRead, NULL)) { - printf( - "%s: Error ReadFile on client should have failed after DisconnectNamedPipe on server\n", - __FUNCTION__); - goto out; - } + char sndbuf[PIPE_BUFFER_SIZE] = { 0 }; + char rcvbuf[PIPE_BUFFER_SIZE] = { 0 }; + if (ReadFile(clients[i], rcvbuf, sizeof(rcvbuf), &dwRead, NULL)) + { + printf("%s: Error ReadFile on client should have failed after DisconnectNamedPipe on " + "server\n", + __FUNCTION__); + goto out; + } - if (WriteFile(clients[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL)) - { - printf("%s: Error WriteFile on client end should have failed after DisconnectNamedPipe on " - "server\n", - __FUNCTION__); - goto out; + if (WriteFile(clients[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL)) + { + printf( + "%s: Error WriteFile on client end should have failed after DisconnectNamedPipe on " + "server\n", + __FUNCTION__); + goto out; + } } - CloseHandle(servers[i]); CloseHandle(clients[i]); numPipes--; @@ -389,20 +395,26 @@ static DWORD WINAPI named_pipe_single_thread(LPVOID arg) i = numPipes - 1; CloseHandle(servers[i]); - if (ReadFile(clients[i], rcvbuf, sizeof(rcvbuf), &dwRead, NULL)) { - printf("%s: Error ReadFile on client end should have failed after CloseHandle on server\n", - __FUNCTION__); - goto out; - } + char sndbuf[PIPE_BUFFER_SIZE] = { 0 }; + char rcvbuf[PIPE_BUFFER_SIZE] = { 0 }; - if (WriteFile(clients[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL)) - { - printf("%s: Error WriteFile on client end should have failed after CloseHandle on server\n", - __FUNCTION__); - goto out; - } + if (ReadFile(clients[i], rcvbuf, sizeof(rcvbuf), &dwRead, NULL)) + { + printf( + "%s: Error ReadFile on client end should have failed after CloseHandle on server\n", + __FUNCTION__); + goto out; + } + if (WriteFile(clients[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL)) + { + printf("%s: Error WriteFile on client end should have failed after CloseHandle on " + "server\n", + __FUNCTION__); + goto out; + } + } CloseHandle(clients[i]); numPipes--; /** @@ -412,18 +424,25 @@ static DWORD WINAPI named_pipe_single_thread(LPVOID arg) i = numPipes - 1; CloseHandle(clients[i]); - if (ReadFile(servers[i], rcvbuf, sizeof(rcvbuf), &dwRead, NULL)) { - printf("%s: Error ReadFile on server end should have failed after CloseHandle on client\n", - __FUNCTION__); - goto out; - } + char sndbuf[PIPE_BUFFER_SIZE] = { 0 }; + char rcvbuf[PIPE_BUFFER_SIZE] = { 0 }; - if (WriteFile(servers[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL)) - { - printf("%s: Error WriteFile on server end should have failed after CloseHandle on client\n", - __FUNCTION__); - goto out; + if (ReadFile(servers[i], rcvbuf, sizeof(rcvbuf), &dwRead, NULL)) + { + printf( + "%s: Error ReadFile on server end should have failed after CloseHandle on client\n", + __FUNCTION__); + goto out; + } + + if (WriteFile(servers[i], sndbuf, sizeof(sndbuf), &dwWritten, NULL)) + { + printf("%s: Error WriteFile on server end should have failed after CloseHandle on " + "client\n", + __FUNCTION__); + goto out; + } } DisconnectNamedPipe(servers[i]); diff --git a/winpr/libwinpr/pipe/test/TestPipeCreatePipe.c b/winpr/libwinpr/pipe/test/TestPipeCreatePipe.c index c8fb7efdd..45edbcf3f 100644 --- a/winpr/libwinpr/pipe/test/TestPipeCreatePipe.c +++ b/winpr/libwinpr/pipe/test/TestPipeCreatePipe.c @@ -14,8 +14,8 @@ int TestPipeCreatePipe(int argc, char* argv[]) DWORD dwWrite; HANDLE hReadPipe; HANDLE hWritePipe; - BYTE readBuffer[BUFFER_SIZE]; - BYTE writeBuffer[BUFFER_SIZE]; + BYTE readBuffer[BUFFER_SIZE] = { 0 }; + BYTE writeBuffer[BUFFER_SIZE] = { 0 }; WINPR_UNUSED(argc); WINPR_UNUSED(argv); status = CreatePipe(&hReadPipe, &hWritePipe, NULL, BUFFER_SIZE * 2); @@ -43,7 +43,6 @@ int TestPipeCreatePipe(int argc, char* argv[]) return -1; } - ZeroMemory(readBuffer, sizeof(readBuffer)); status = ReadFile(hReadPipe, &readBuffer, sizeof(readBuffer), &dwRead, NULL); if (!status) diff --git a/winpr/libwinpr/pool/test/TestPoolWork.c b/winpr/libwinpr/pool/test/TestPoolWork.c index 1b04d3a66..bf43ca7f1 100644 --- a/winpr/libwinpr/pool/test/TestPoolWork.c +++ b/winpr/libwinpr/pool/test/TestPoolWork.c @@ -1,4 +1,5 @@ +#include #include #include #include @@ -8,21 +9,20 @@ static LONG count = 0; static void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work) { int index; - BYTE a[1024]; - BYTE b[1024]; - BYTE c[1024]; printf("Hello %s: %03" PRId32 " (thread: 0x%08" PRIX32 ")\n", (char*)context, InterlockedIncrement(&count), GetCurrentThreadId()); for (index = 0; index < 100; index++) { - ZeroMemory(a, 1024); - ZeroMemory(b, 1024); - ZeroMemory(c, 1024); - FillMemory(a, 1024, 0xAA); - FillMemory(b, 1024, 0xBB); - CopyMemory(c, a, 1024); - CopyMemory(c, b, 1024); + BYTE a[1024]; + BYTE b[1024]; + BYTE c[1024] = { 0 }; + + FillMemory(a, ARRAYSIZE(a), 0xAA); + FillMemory(b, ARRAYSIZE(b), 0xBB); + + CopyMemory(c, a, ARRAYSIZE(a)); + CopyMemory(c, b, ARRAYSIZE(b)); } } diff --git a/winpr/libwinpr/sspi/test/TestNTLM.c b/winpr/libwinpr/sspi/test/TestNTLM.c index 3044e2b92..19b736e3c 100644 --- a/winpr/libwinpr/sspi/test/TestNTLM.c +++ b/winpr/libwinpr/sspi/test/TestNTLM.c @@ -398,10 +398,8 @@ static int test_ntlm_server_authenticate(TEST_NTLM_SERVER* ntlm) if (!hash_set && status == SEC_I_CONTINUE_NEEDED) { - SecPkgContext_AuthIdentity AuthIdentity; - SecPkgContext_AuthNtlmHash AuthNtlmHash; - ZeroMemory(&AuthIdentity, sizeof(SecPkgContext_AuthIdentity)); - ZeroMemory(&AuthNtlmHash, sizeof(SecPkgContext_AuthNtlmHash)); + SecPkgContext_AuthIdentity AuthIdentity = { 0 }; + SecPkgContext_AuthNtlmHash AuthNtlmHash = { 0 }; if (ntlm->UseNtlmV2Hash) { diff --git a/winpr/libwinpr/sspi/test/TestSchannel.c b/winpr/libwinpr/sspi/test/TestSchannel.c index 047fa7b82..5b377f94a 100644 --- a/winpr/libwinpr/sspi/test/TestSchannel.c +++ b/winpr/libwinpr/sspi/test/TestSchannel.c @@ -218,12 +218,12 @@ static int schannel_send(PSecurityFunctionTable table, HANDLE hPipe, PCtxtHandle BYTE* ioBuffer; UINT32 ioBufferLength; BYTE* pMessageBuffer; - SecBuffer Buffers[4]; + SecBuffer Buffers[4] = { 0 }; SecBufferDesc Message; SECURITY_STATUS status; DWORD NumberOfBytesWritten; - SecPkgContext_StreamSizes StreamSizes; - ZeroMemory(&StreamSizes, sizeof(SecPkgContext_StreamSizes)); + SecPkgContext_StreamSizes StreamSizes = { 0 }; + status = table->QueryContextAttributes(phContext, SECPKG_ATTR_STREAM_SIZES, &StreamSizes); ioBufferLength = StreamSizes.cbHeader + StreamSizes.cbMaximumMessage + StreamSizes.cbTrailer; ioBuffer = (BYTE*)calloc(1, ioBufferLength); @@ -278,12 +278,12 @@ static int schannel_recv(PSecurityFunctionTable table, HANDLE hPipe, PCtxtHandle BYTE* ioBuffer; UINT32 ioBufferLength; // BYTE* pMessageBuffer; - SecBuffer Buffers[4]; + SecBuffer Buffers[4] = { 0 }; SecBufferDesc Message; SECURITY_STATUS status; DWORD NumberOfBytesRead; - SecPkgContext_StreamSizes StreamSizes; - ZeroMemory(&StreamSizes, sizeof(SecPkgContext_StreamSizes)); + SecPkgContext_StreamSizes StreamSizes = { 0 }; + status = table->QueryContextAttributes(phContext, SECPKG_ATTR_STREAM_SIZES, &StreamSizes); ioBufferLength = StreamSizes.cbHeader + StreamSizes.cbMaximumMessage + StreamSizes.cbTrailer; ioBuffer = (BYTE*)calloc(1, ioBufferLength); @@ -344,7 +344,7 @@ static DWORD WINAPI schannel_test_server_thread(LPVOID arg) UINT32 cbMaxToken; UINT32 fContextReq; ULONG fContextAttr; - SCHANNEL_CRED cred; + SCHANNEL_CRED cred = { 0 }; CtxtHandle context; CredHandle credentials; DWORD cchNameString; @@ -352,8 +352,8 @@ static DWORD WINAPI schannel_test_server_thread(LPVOID arg) HCERTSTORE hCertStore; PCCERT_CONTEXT pCertContext; PSecBuffer pSecBuffer; - SecBuffer SecBuffer_in[2]; - SecBuffer SecBuffer_out[2]; + SecBuffer SecBuffer_in[2] = { 0 }; + SecBuffer SecBuffer_out[2] = { 0 }; SecBufferDesc SecBufferDesc_in; SecBufferDesc SecBufferDesc_out; DWORD NumberOfBytesRead; @@ -407,7 +407,6 @@ static DWORD WINAPI schannel_test_server_thread(LPVOID arg) cchNameString = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, pszNameString, cchNameString); _tprintf(_T("Certificate Name: %s\n"), pszNameString); - ZeroMemory(&cred, sizeof(SCHANNEL_CRED)); cred.dwVersion = SCHANNEL_CRED_VERSION; cred.cCreds = 1; cred.paCred = &pCertContext; @@ -600,7 +599,7 @@ int TestSchannel(int argc, char* argv[]) BYTE* lpTokenOut; TimeStamp expiry; UINT32 cbMaxToken; - SCHANNEL_CRED cred; + SCHANNEL_CRED cred = { 0 }; UINT32 fContextReq; ULONG fContextAttr; CtxtHandle context; @@ -608,16 +607,12 @@ int TestSchannel(int argc, char* argv[]) SECURITY_STATUS status; PSecPkgInfo pPackageInfo; PSecBuffer pSecBuffer; - SecBuffer SecBuffer_in[2]; - SecBuffer SecBuffer_out[1]; - SecBufferDesc SecBufferDesc_in; - SecBufferDesc SecBufferDesc_out; PSecurityFunctionTable table; DWORD NumberOfBytesRead; DWORD NumberOfBytesWritten; - SecPkgCred_SupportedAlgs SupportedAlgs; - SecPkgCred_CipherStrengths CipherStrengths; - SecPkgCred_SupportedProtocols SupportedProtocols; + SecPkgCred_SupportedAlgs SupportedAlgs = { 0 }; + SecPkgCred_CipherStrengths CipherStrengths = { 0 }; + SecPkgCred_SupportedProtocols SupportedProtocols = { 0 }; return 0; /* disable by default - causes crash */ sspi_GlobalInit(); dump_test_certificate_files(); @@ -652,7 +647,6 @@ int TestSchannel(int argc, char* argv[]) } cbMaxToken = pPackageInfo->cbMaxToken; - ZeroMemory(&cred, sizeof(SCHANNEL_CRED)); cred.dwVersion = SCHANNEL_CRED_VERSION; cred.cCreds = 0; cred.paCred = NULL; @@ -671,7 +665,6 @@ int TestSchannel(int argc, char* argv[]) return -1; } - ZeroMemory(&SupportedAlgs, sizeof(SecPkgCred_SupportedAlgs)); status = table->QueryCredentialsAttributes(&credentials, SECPKG_ATTR_SUPPORTED_ALGS, &SupportedAlgs); @@ -697,7 +690,6 @@ int TestSchannel(int argc, char* argv[]) } printf("\n"); - ZeroMemory(&CipherStrengths, sizeof(SecPkgCred_CipherStrengths)); status = table->QueryCredentialsAttributes(&credentials, SECPKG_ATTR_CIPHER_STRENGTHS, &CipherStrengths); @@ -711,7 +703,6 @@ int TestSchannel(int argc, char* argv[]) /* CipherStrengths: Minimum: 40 Maximum: 256 */ printf("CipherStrengths: Minimum: %" PRIu32 " Maximum: %" PRIu32 "\n", CipherStrengths.dwMinimumCipherStrength, CipherStrengths.dwMaximumCipherStrength); - ZeroMemory(&SupportedProtocols, sizeof(SecPkgCred_SupportedProtocols)); status = table->QueryCredentialsAttributes(&credentials, SECPKG_ATTR_SUPPORTED_PROTOCOLS, &SupportedProtocols); @@ -738,14 +729,14 @@ int TestSchannel(int argc, char* argv[]) printf("Memory allocation failed\n"); return -1; } - ZeroMemory(&SecBuffer_in, sizeof(SecBuffer_in)); - ZeroMemory(&SecBuffer_out, sizeof(SecBuffer_out)); - ZeroMemory(&SecBufferDesc_in, sizeof(SecBufferDesc)); - ZeroMemory(&SecBufferDesc_out, sizeof(SecBufferDesc)); g_ClientWait = FALSE; do { + SecBuffer SecBuffer_in[2] = { 0 }; + SecBuffer SecBuffer_out[1] = { 0 }; + SecBufferDesc SecBufferDesc_in = { 0 }; + SecBufferDesc SecBufferDesc_out = { 0 }; if (g_ClientWait) { if (!ReadFile(g_ClientReadPipe, lpTokenIn, cbMaxToken, &NumberOfBytesRead, NULL)) diff --git a/winpr/libwinpr/synch/timer.c b/winpr/libwinpr/synch/timer.c index fd544a845..ff5b873a8 100644 --- a/winpr/libwinpr/synch/timer.c +++ b/winpr/libwinpr/synch/timer.c @@ -258,9 +258,8 @@ static int InitializeWaitableTimer(WINPR_TIMER* timer) if (timer->fd <= 0) return -1; #elif defined(TIMER_IMPL_POSIX) - struct sigevent sigev; + struct sigevent sigev = { 0 }; InitOnceExecuteOnce(&TimerSignalHandler_InitOnce, InstallTimerSignalHandler, NULL, NULL); - ZeroMemory(&sigev, sizeof(struct sigevent)); sigev.sigev_notify = SIGEV_SIGNAL; sigev.sigev_signo = SIGALRM; sigev.sigev_value.sival_ptr = (void*)timer; diff --git a/winpr/libwinpr/thread/process.c b/winpr/libwinpr/thread/process.c index 850ceea98..bf0ff3559 100644 --- a/winpr/libwinpr/thread/process.c +++ b/winpr/libwinpr/thread/process.c @@ -226,10 +226,9 @@ static BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags, LPCSTR lpApplic #endif int fd; int sig; - sigset_t set; - struct sigaction act; + sigset_t set = { 0 }; + struct sigaction act = { 0 }; /* set default signal handlers */ - memset(&act, 0, sizeof(act)); act.sa_handler = SIG_DFL; act.sa_flags = 0; sigemptyset(&act.sa_mask); diff --git a/winpr/libwinpr/thread/test/TestThreadCreateProcess.c b/winpr/libwinpr/thread/test/TestThreadCreateProcess.c index 29016b1bf..369245fcb 100644 --- a/winpr/libwinpr/thread/test/TestThreadCreateProcess.c +++ b/winpr/libwinpr/thread/test/TestThreadCreateProcess.c @@ -29,12 +29,12 @@ int TestThreadCreateProcess(int argc, char* argv[]) DWORD dwCreationFlags; LPVOID lpEnvironment; LPCTSTR lpCurrentDirectory; - STARTUPINFO StartupInfo; - PROCESS_INFORMATION ProcessInformation; + STARTUPINFO StartupInfo = { 0 }; + PROCESS_INFORMATION ProcessInformation = { 0 }; LPTCH lpszEnvironmentBlock; HANDLE pipe_read = NULL; HANDLE pipe_write = NULL; - char buf[1024]; + char buf[1024] = { 0 }; DWORD read_bytes; int ret = 0; SECURITY_ATTRIBUTES saAttr; @@ -55,9 +55,7 @@ int TestThreadCreateProcess(int argc, char* argv[]) #endif lpEnvironment = lpszEnvironmentBlock; lpCurrentDirectory = NULL; - ZeroMemory(&StartupInfo, sizeof(STARTUPINFO)); StartupInfo.cb = sizeof(STARTUPINFO); - ZeroMemory(&ProcessInformation, sizeof(PROCESS_INFORMATION)); status = CreateProcess(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.c b/winpr/libwinpr/utils/wlog/UdpAppender.c index 0d76135a6..c84abf8c1 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.c +++ b/winpr/libwinpr/utils/wlog/UdpAppender.c @@ -38,9 +38,9 @@ typedef struct static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender) { wLogUdpAppender* udpAppender; - char addressString[256]; - struct addrinfo hints; - struct addrinfo* result; + char addressString[256] = { 0 }; + struct addrinfo hints = { 0 }; + struct addrinfo* result = { 0 }; int status; size_t addrLen; char* colonPos; @@ -61,7 +61,6 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender) addrLen = (colonPos - udpAppender->host); memcpy(addressString, udpAppender->host, addrLen); addressString[addrLen] = '\0'; - ZeroMemory(&hints, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_DGRAM; status = getaddrinfo(addressString, colonPos + 1, &hints, &result); diff --git a/winpr/libwinpr/winsock/winsock.c b/winpr/libwinpr/winsock/winsock.c index 013716e4e..04caa97d5 100644 --- a/winpr/libwinpr/winsock/winsock.c +++ b/winpr/libwinpr/winsock/winsock.c @@ -236,8 +236,8 @@ PCSTR winpr_inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBuf { if (Family == AF_INET) { - struct sockaddr_in in; - memset(&in, 0, sizeof(in)); + struct sockaddr_in in = { 0 }; + in.sin_family = AF_INET; memcpy(&in.sin_addr, pAddr, sizeof(struct in_addr)); getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in), pStringBuf, StringBufSize, @@ -246,8 +246,8 @@ PCSTR winpr_inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBuf } else if (Family == AF_INET6) { - struct sockaddr_in6 in; - memset(&in, 0, sizeof(in)); + struct sockaddr_in6 in = { 0 }; + in.sin6_family = AF_INET6; memcpy(&in.sin6_addr, pAddr, sizeof(struct in_addr6)); getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in6), pStringBuf, StringBufSize, @@ -295,12 +295,16 @@ INT winpr_inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf) #include #include +#include + #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 #endif int WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData) { + WINPR_ASSERT(lpWSAData); + ZeroMemory(lpWSAData, sizeof(WSADATA)); lpWSAData->wVersion = wVersionRequired; lpWSAData->wHighVersion = MAKEWORD(2, 2); diff --git a/winpr/libwinpr/wtsapi/wtsapi_win32.c b/winpr/libwinpr/wtsapi/wtsapi_win32.c index fa5ecb67d..8b86a08f8 100644 --- a/winpr/libwinpr/wtsapi/wtsapi_win32.c +++ b/winpr/libwinpr/wtsapi/wtsapi_win32.c @@ -334,14 +334,12 @@ BOOL WINAPI Win32_WTSVirtualChannelRead_Static(WTSAPI_CHANNEL* pChannel, DWORD d else if (pChannel->readSync) { BOOL bSuccess; - OVERLAPPED overlapped; + OVERLAPPED overlapped = { 0 }; DWORD numBytesRead = 0; DWORD numBytesToRead = 0; *lpNumberOfBytesTransferred = 0; - ZeroMemory(&overlapped, sizeof(OVERLAPPED)); - numBytesToRead = nNumberOfBytesToRead; if (numBytesToRead > (pChannel->header->length - pChannel->readOffset)) @@ -454,14 +452,12 @@ BOOL WINAPI Win32_WTSVirtualChannelRead_Dynamic(WTSAPI_CHANNEL* pChannel, DWORD if (pChannel->readSync) { BOOL bSuccess; - OVERLAPPED overlapped; + OVERLAPPED overlapped = { 0 }; DWORD numBytesRead = 0; DWORD numBytesToRead = 0; *lpNumberOfBytesTransferred = 0; - ZeroMemory(&overlapped, sizeof(OVERLAPPED)); - numBytesToRead = nNumberOfBytesToRead; if (numBytesToRead > (pChannel->header->length - pChannel->readOffset)) @@ -581,9 +577,7 @@ BOOL WINAPI Win32_WTSVirtualChannelRead(HANDLE hChannel, DWORD dwMilliseconds, L if (!pChannel->waitObjectMode) { - OVERLAPPED overlapped; - - ZeroMemory(&overlapped, sizeof(OVERLAPPED)); + OVERLAPPED overlapped = { 0 }; if (ReadFile(pChannel->hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesTransferred, &overlapped)) @@ -631,7 +625,7 @@ BOOL WINAPI Win32_WTSVirtualChannelWrite(HANDLE hChannel, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesTransferred) { - OVERLAPPED overlapped; + OVERLAPPED overlapped = { 0 }; WTSAPI_CHANNEL* pChannel = (WTSAPI_CHANNEL*)hChannel; if (!pChannel || (pChannel->magic != WTSAPI_CHANNEL_MAGIC)) @@ -640,8 +634,6 @@ BOOL WINAPI Win32_WTSVirtualChannelWrite(HANDLE hChannel, LPCVOID lpBuffer, return FALSE; } - ZeroMemory(&overlapped, sizeof(OVERLAPPED)); - if (WriteFile(pChannel->hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesTransferred, &overlapped)) return TRUE;