[pacman-dev] [PATCH] lib/util: call malloc from MALLOC, not calloc

Dave Reisner d at falconindy.com
Thu Oct 13 12:33:26 EDT 2011


This was added in cc754bc6 as a "safety" measure, but sort of defeats
the purpose of having this macro. If we're using malloc unsafely, then
we've already lost.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 lib/libalpm/util.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 2a2d3a9..86aa7f2 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -51,7 +51,7 @@
 
 #define ALLOC_FAIL(s) do { fprintf(stderr, "alloc failure: could not allocate %zd bytes\n", s); } while(0)
 
-#define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
+#define MALLOC(p, s, action) do { p = malloc(s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
 #define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
 /* This strdup macro is NULL safe- copying NULL will yield NULL */
 #define STRDUP(r, s, action) do { if(s != NULL) { r = strdup(s); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } else { r = NULL; } } while(0)
-- 
1.7.7



More information about the pacman-dev mailing list