From 7d3f67e8223168f1da4f82f928029056f74ad651 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Fri, 11 Mar 2016 10:43:31 +0800 Subject: [PATCH] Revert 5c593fae4227651075cfc9445f17dad6ae0a0b47 (xCalloc) calloc() allows 'nmemb' or 'size' to be zero, in which case NULL may be returned. Letting htop die because of either argument being zero doesn't make sense. As a side note: As size_t is unsigned, compiler should be able to optimize conditional (nmemb > 0 && size > 0) to (nmemb && size). This theorically shouldn't increase code size too much. --- XAlloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XAlloc.c b/XAlloc.c index cc290211..38556987 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -29,7 +29,7 @@ void* xMalloc(size_t size) { void* xCalloc(size_t nmemb, size_t size) { void* data = calloc(nmemb, size); - if (!data) { + if (!data && nmemb > 0 && size > 0) { fail(); } return data;