p_clear should not be used with sizeof but *countof*
[apps/madmutt.git] / lib-lib / mem.h
index db5ef49..9ff2589 100644 (file)
@@ -24,6 +24,9 @@
 #include <string.h>
 #include <unistd.h>
 
+#define ssizeof(foo)            (ssize_t)sizeof(foo)
+#define countof(foo)            (ssizeof(foo) / ssizeof(foo[0]))
+
 #define p_new(type, count)      ((type *)xmalloc(sizeof(type) * (count)))
 #define p_clear(p, count)       ((void)memset((p), 0, sizeof(*(p)) * (count)))
 #define p_dup(p, count)         xmemdup((p), sizeof(*(p)) * (count))