]> granicus.if.org Git - strace/commitdiff
xmalloc: introduce xzalloc
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 22 Feb 2019 17:34:33 +0000 (18:34 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 22 May 2019 11:05:13 +0000 (11:05 +0000)
* xmalloc.h (xmalloc, xcalloc, xreallocarray): Document.
(xzalloc): New function, a thin wrapper around xcalloc with xmalloc
interface.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
xmalloc.h

index a4e7792f4d29eccccc57187b5682aefd6975f418..57412cf8f2dab67e127fbb410a0710793bab931f 100644 (file)
--- a/xmalloc.h
+++ b/xmalloc.h
 # define xcalloc strace_calloc
 # define xmalloc strace_malloc
 
+/** Allocate memory, die if the allocation has failed. */
+void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
+
+/**
+ * Allocate an array and zero it out (similar to calloc), die if the allocation
+ * has failed or if the product of nmemb and size is too big.
+ */
 void *xcalloc(size_t nmemb, size_t size)
        ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2));
-void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
+
+/** Wrapper for xcalloc(1, size) with xmalloc-like interface. */
+ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1))
+static inline void *
+xzalloc(size_t size)
+{
+       return xcalloc(1, size);
+}
+
+/**
+ * Reallocate memory for the array, die if the allocation has failed or
+ * if the product of nmemb and size is too big.
+ */
 void *xreallocarray(void *ptr, size_t nmemb, size_t size)
        ATTRIBUTE_ALLOC_SIZE((2, 3));