From 4d907cecab1f25a1de6c7efdc3d1fd1a6b47d459 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 15 Aug 2021 18:46:17 -0400 Subject: [PATCH] [common] use correct argument order for calloc The signature for calloc is void *calloc(size_t num, size_t size), where num is the number of elements to allocate, and size is the size. Therefore, to allocate a single struct, we should pass 1 for num and the size of the struct as size. In some places, we use the opposite order, and we should flip it. --- common/src/platform/linux/event.c | 2 +- common/src/platform/windows/ivshmem.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/platform/linux/event.c b/common/src/platform/linux/event.c index c8fb2405..c593e281 100644 --- a/common/src/platform/linux/event.c +++ b/common/src/platform/linux/event.c @@ -39,7 +39,7 @@ struct LGEvent LGEvent * lgCreateEvent(bool autoReset, unsigned int msSpinTime) { - LGEvent * handle = (LGEvent *)calloc(sizeof(*handle), 1); + LGEvent * handle = (LGEvent *)calloc(1, sizeof(*handle)); if (!handle) { DEBUG_ERROR("Failed to allocate memory"); diff --git a/common/src/platform/windows/ivshmem.c b/common/src/platform/windows/ivshmem.c index f198f32d..6b1015ce 100644 --- a/common/src/platform/windows/ivshmem.c +++ b/common/src/platform/windows/ivshmem.c @@ -160,7 +160,7 @@ bool ivshmemInit(struct IVSHMEM * dev) return false; } - infData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)calloc(reqSize, 1); + infData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)calloc(1, reqSize); infData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); if (!SetupDiGetDeviceInterfaceDetail(devInfoSet, &devInterfaceData, infData, reqSize, NULL, NULL)) {