From: Alejandro Colomar Date: Sat, 15 Nov 2025 20:33:21 +0000 (+0100) Subject: lib/alloc/: reallocarray[f]_(): Add helper macros to handle n?:1 X-Git-Tag: 4.19.0-rc1~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=882fbdf99b77b13207653e9b44efb5ea7083f481;p=thirdparty%2Fshadow.git lib/alloc/: reallocarray[f]_(): Add helper macros to handle n?:1 Signed-off-by: Alejandro Colomar --- diff --git a/lib/alloc/realloc.h b/lib/alloc/realloc.h index c5e8cdb2..bbf3c5f9 100644 --- a/lib/alloc/realloc.h +++ b/lib/alloc/realloc.h @@ -17,9 +17,11 @@ #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)) diff --git a/lib/alloc/reallocf.h b/lib/alloc/reallocf.h index efc68709..a4b61806 100644 --- a/lib/alloc/reallocf.h +++ b/lib/alloc/reallocf.h @@ -18,9 +18,11 @@ #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)