diff --git a/common/src/countedbuffer.c b/common/src/countedbuffer.c index 2e0bfcd3..76ae5222 100644 --- a/common/src/countedbuffer.c +++ b/common/src/countedbuffer.c @@ -24,7 +24,7 @@ struct CountedBuffer * countedBufferNew(size_t size) { - struct CountedBuffer * buffer = malloc(sizeof(struct CountedBuffer) + size); + struct CountedBuffer * buffer = malloc(sizeof(*buffer) + size); if (!buffer) return NULL; diff --git a/common/src/option.c b/common/src/option.c index e116c0f7..f89ae96d 100644 --- a/common/src/option.c +++ b/common/src/option.c @@ -120,14 +120,14 @@ bool option_register(struct Option options[]) state.options = realloc( state.options, - sizeof(struct Option *) * (state.oCount + new) + sizeof(*state.options) * (state.oCount + new) ); for(int i = 0; options[i].type != OPTION_TYPE_NONE; ++i) { - state.options[state.oCount + i] = (struct Option *)malloc(sizeof(struct Option)); + state.options[state.oCount + i] = (struct Option *)malloc(sizeof(**state.options)); struct Option * o = state.options[state.oCount + i]; - memcpy(o, &options[i], sizeof(struct Option)); + memcpy(o, &options[i], sizeof(*o)); if (!o->parser) { @@ -199,7 +199,7 @@ bool option_register(struct Option options[]) found = true; group->options = realloc( group->options, - sizeof(struct Option *) * (group->count + 1) + sizeof(*group->options) * (group->count + 1) ); group->options[group->count] = o; @@ -215,14 +215,14 @@ bool option_register(struct Option options[]) { state.groups = realloc( state.groups, - sizeof(struct OptionGroup) * (state.gCount + 1) + sizeof(*state.groups) * (state.gCount + 1) ); struct OptionGroup * group = &state.groups[state.gCount]; ++state.gCount; group->module = o->module; - group->options = malloc(sizeof(struct Option *)); + group->options = malloc(sizeof(*group->options)); group->options[0] = o; group->count = 1; group->pad = strlen(o->name); diff --git a/common/src/platform/linux/crash.c b/common/src/platform/linux/crash.c index a47c637b..10c4b07f 100644 --- a/common/src/platform/linux/crash.c +++ b/common/src/platform/linux/crash.c @@ -164,7 +164,7 @@ static int dl_iterate_phdr_callback(struct dl_phdr_info * info, size_t size, voi ttl += hdr.p_memsz; } - crash.ranges = realloc(crash.ranges, sizeof(struct range) * (crash.rangeCount + 1)); + crash.ranges = realloc(crash.ranges, sizeof(*crash.ranges) * (crash.rangeCount + 1)); crash.ranges[crash.rangeCount].start = info->dlpi_addr; crash.ranges[crash.rangeCount].end = info->dlpi_addr + ttl; ++crash.rangeCount; diff --git a/common/src/platform/linux/event.c b/common/src/platform/linux/event.c index dd30236c..c8fb2405 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(LGEvent), 1); + LGEvent * handle = (LGEvent *)calloc(sizeof(*handle), 1); if (!handle) { DEBUG_ERROR("Failed to allocate memory"); diff --git a/common/src/platform/linux/ivshmem.c b/common/src/platform/linux/ivshmem.c index 84660c76..92aef4f1 100644 --- a/common/src/platform/linux/ivshmem.c +++ b/common/src/platform/linux/ivshmem.c @@ -171,8 +171,7 @@ bool ivshmemOpenDev(struct IVSHMEM * dev, const char * shmDevice) return false; } - struct IVSHMEMInfo * info = - (struct IVSHMEMInfo *)malloc(sizeof(struct IVSHMEMInfo)); + struct IVSHMEMInfo * info = (struct IVSHMEMInfo *)malloc(sizeof(*info)); info->size = devSize; info->devFd = devFd; info->hasDMA = hasDMA; diff --git a/common/src/platform/linux/thread.c b/common/src/platform/linux/thread.c index 5a9d9e16..7e5ab24e 100644 --- a/common/src/platform/linux/thread.c +++ b/common/src/platform/linux/thread.c @@ -43,7 +43,7 @@ static void * threadWrapper(void * opaque) bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque, LGThread ** handle) { - *handle = (LGThread*)malloc(sizeof(LGThread)); + *handle = (LGThread*)malloc(sizeof(**handle)); (*handle)->name = name; (*handle)->function = function; (*handle)->opaque = opaque; diff --git a/common/src/platform/linux/time.c b/common/src/platform/linux/time.c index 86c5bd81..939dd9b1 100644 --- a/common/src/platform/linux/time.c +++ b/common/src/platform/linux/time.c @@ -49,7 +49,7 @@ static void TimerProc(union sigval arg) bool lgCreateTimer(const unsigned int intervalMS, LGTimerFn fn, void * udata, LGTimer ** result) { - LGTimer * ret = malloc(sizeof(LGTimer)); + LGTimer * ret = malloc(sizeof(*ret)); if (!ret) { diff --git a/common/src/platform/windows/ivshmem.c b/common/src/platform/windows/ivshmem.c index 486557f2..f198f32d 100644 --- a/common/src/platform/windows/ivshmem.c +++ b/common/src/platform/windows/ivshmem.c @@ -80,7 +80,7 @@ bool ivshmemInit(struct IVSHMEM * dev) SP_DEVICE_INTERFACE_DATA devInterfaceData = {0}; int deviceAllocated = 1; int deviceCount = 0; - struct IVSHMEMData * devices = malloc(sizeof(struct IVSHMEMData) * deviceAllocated); + struct IVSHMEMData * devices = malloc(sizeof(*devices) * deviceAllocated); devInfoSet = SetupDiGetClassDevs(&GUID_DEVINTERFACE_IVSHMEM, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); @@ -97,7 +97,7 @@ bool ivshmemInit(struct IVSHMEM * dev) if (deviceCount >= deviceAllocated) { int newCount = deviceAllocated * 2; - void * new = realloc(devices, newCount * sizeof(struct IVSHMEMData)); + struct IVSHMEMData * new = realloc(devices, newCount * sizeof(*new)); if (!new) { DEBUG_ERROR("Failed to allocate memory"); @@ -133,7 +133,7 @@ bool ivshmemInit(struct IVSHMEM * dev) } const int shmDevice = option_get_int("os", "shmDevice"); - qsort(devices, deviceCount, sizeof(struct IVSHMEMData), ivshmemComparator); + qsort(devices, deviceCount, sizeof(*devices), ivshmemComparator); for (int i = 0; i < deviceCount; ++i) { @@ -181,8 +181,7 @@ bool ivshmemInit(struct IVSHMEM * dev) free(infData); SetupDiDestroyDeviceInfoList(devInfoSet); - struct IVSHMEMInfo * info = - (struct IVSHMEMInfo *)malloc(sizeof(struct IVSHMEMInfo)); + struct IVSHMEMInfo * info = (struct IVSHMEMInfo *)malloc(sizeof(*info)); info->handle = handle; dev->opaque = info; diff --git a/common/src/platform/windows/thread.c b/common/src/platform/windows/thread.c index 30d3dd82..462b4400 100644 --- a/common/src/platform/windows/thread.c +++ b/common/src/platform/windows/thread.c @@ -44,7 +44,7 @@ static DWORD WINAPI threadWrapper(LPVOID lpParameter) bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque, LGThread ** handle) { - *handle = (LGThread *)malloc(sizeof(LGThread)); + *handle = (LGThread *)malloc(sizeof(**handle)); (*handle)->name = name; (*handle)->function = function; (*handle)->opaque = opaque; diff --git a/common/src/platform/windows/time.c b/common/src/platform/windows/time.c index 451510b4..185819d3 100644 --- a/common/src/platform/windows/time.c +++ b/common/src/platform/windows/time.c @@ -45,7 +45,7 @@ static void TimerProc(HWND Arg1, UINT Arg2, UINT_PTR Arg3, DWORD Arg4) bool lgCreateTimer(const unsigned int intervalMS, LGTimerFn fn, void * udata, LGTimer ** result) { - LGTimer * ret = malloc(sizeof(LGTimer)); + LGTimer * ret = malloc(sizeof(*ret)); if (!ret) { DEBUG_ERROR("failed to malloc LGTimer struct"); diff --git a/common/src/stringlist.c b/common/src/stringlist.c index f4cb06a6..2af26dbf 100644 --- a/common/src/stringlist.c +++ b/common/src/stringlist.c @@ -32,7 +32,7 @@ struct StringList StringList stringlist_new(bool owns_strings) { - StringList sl = malloc(sizeof(struct StringList)); + StringList sl = malloc(sizeof(*sl)); sl->owns_strings = owns_strings; sl->size = 32; @@ -58,7 +58,7 @@ int stringlist_push (StringList sl, char * str) if (sl->count == sl->size) { sl->size += 32; - sl->list = realloc(sl->list, sizeof(char *) * sl->size); + sl->list = realloc(sl->list, sizeof(*sl->list) * sl->size); } unsigned int index = sl->count; @@ -77,4 +77,4 @@ char * stringlist_at(StringList sl, unsigned int index) return NULL; return sl->list[index]; -} \ No newline at end of file +}