diff --git a/Meter.c b/Meter.c index 84370362..fa1eacb4 100644 --- a/Meter.c +++ b/Meter.c @@ -38,7 +38,7 @@ Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type) { this->param = param; this->pl = pl; this->curItems = type->maxItems; - this->values = xCalloc(type->maxItems, sizeof(double)); + this->values = type->maxItems ? xCalloc(type->maxItems, sizeof(double)) : NULL; this->total = type->total; this->caption = xStrdup(type->caption); if (Meter_initFn(this)) diff --git a/XUtils.c b/XUtils.c index 1e77cd3b..3bdcba84 100644 --- a/XUtils.c +++ b/XUtils.c @@ -25,26 +25,26 @@ void fail() { } void* xMalloc(size_t size) { + assert(size > 0); void* data = malloc(size); - if (!data && size > 0) { + if (!data) { fail(); } return data; } void* xCalloc(size_t nmemb, size_t size) { + assert(nmemb > 0); + assert(size > 0); void* data = calloc(nmemb, size); - if (!data && nmemb > 0 && size > 0) { + if (!data) { fail(); } return data; } void* xRealloc(void* ptr, size_t size) { - if (!size) { - free(ptr); - return NULL; - } + assert(size > 0); void* data = realloc(ptr, size); // deepcode ignore MemoryLeakOnRealloc: this goes to fail() if (!data) { free(ptr);