]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/alloc/: reallocarray[f]_(): Add helper macros to handle n?:1
authorAlejandro Colomar <alx@kernel.org>
Sat, 15 Nov 2025 20:33:21 +0000 (21:33 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 6 Dec 2025 03:22:45 +0000 (21:22 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/alloc/realloc.h
lib/alloc/reallocf.h

index c5e8cdb2901fd95bf9e3af668931b2b5545d36f8..bbf3c5f95b544094151ad92738931cc1168995e2 100644 (file)
 #define REALLOC(p, n, T)   REALLOC_(p, n, typeas(T))
 #define REALLOC_(p, n, T)                                             \
 (                                                                     \
-       _Generic(p, T *: (T *) reallocarray(p, (n) ?: 1, sizeof(T)))  \
+       _Generic(p, T *: (T *) reallocarray_(p, n, sizeof(T)))        \
 )
 
+#define reallocarray_(p, n, size)  reallocarray(p, (n) ?: 1, (size) ?: 1)
+
 
 #define XREALLOC(p, n, T)  exit_if_null(REALLOC(p, n, T))
 
index efc6870974fe9dbb6bbcb73ac21bec116cfa1aec..a4b61806d38afd1db326f807c0ec2b5fc2d4ebe3 100644 (file)
 #define REALLOCF(p, n, T)   REALLOCF_(p, n, typeas(T))
 #define REALLOCF_(p, n, T)                                            \
 (                                                                     \
-       _Generic(p, T *: (T *) reallocarrayf(p, (n) ?: 1, sizeof(T))) \
+       _Generic(p, T *: (T *) reallocarrayf_(p, n, sizeof(T)))       \
 )
 
+#define reallocarrayf_(p, n, size)  reallocarrayf(p, (n) ?: 1, (size) ?: 1)
+
 
 ATTR_ALLOC_SIZE(2, 3)
 ATTR_MALLOC(free)