From: Cristian Rodríguez Date: Sat, 13 Jan 2024 23:14:05 +0000 (-0300) Subject: Fix gcc14 -Wcalloc-transposed-args warnings X-Git-Tag: v256-rc1~1160 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2a9ab0974bb290bc66dc84d909c33d23361b0752;p=thirdparty%2Fsystemd.git Fix gcc14 -Wcalloc-transposed-args warnings all functions annotated with two parameter _alloc_ are calloc-like. gcc14 enforces this and warns if arguments are backwards. --- diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index 5fbfff0af41..05a6f211f7f 100644 --- a/src/basic/alloc-util.h +++ b/src/basic/alloc-util.h @@ -20,7 +20,7 @@ typedef void* (*mfree_func_t)(void *p); * proceeding and smashing the stack limits. Note that by default RLIMIT_STACK is 8M on Linux. */ #define ALLOCA_MAX (4U*1024U*1024U) -#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n))) +#define new(t, n) ((t*) malloc_multiply((n), sizeof(t))) #define new0(t, n) ((t*) calloc((n) ?: 1, sizeof(t))) @@ -45,7 +45,7 @@ typedef void* (*mfree_func_t)(void *p); (t*) alloca0((sizeof(t)*_n_)); \ }) -#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n))) +#define newdup(t, p, n) ((t*) memdup_multiply(p, (n), sizeof(t))) #define newdup_suffix0(t, p, n) ((t*) memdup_suffix0_multiply(p, sizeof(t), (n))) @@ -112,7 +112,7 @@ static inline bool size_multiply_overflow(size_t size, size_t need) { return _unlikely_(need != 0 && size > (SIZE_MAX / need)); } -_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t need) { +_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t need, size_t size) { if (size_multiply_overflow(size, need)) return NULL; @@ -128,7 +128,7 @@ _alloc_(2, 3) static inline void *reallocarray(void *p, size_t need, size_t size } #endif -_alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t size, size_t need) { +_alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t need, size_t size) { if (size_multiply_overflow(size, need)) return NULL; diff --git a/src/cryptenroll/cryptenroll.c b/src/cryptenroll/cryptenroll.c index 687b908f060..e1fdc3f5f02 100644 --- a/src/cryptenroll/cryptenroll.c +++ b/src/cryptenroll/cryptenroll.c @@ -488,7 +488,7 @@ static int parse_argv(int argc, char *argv[]) { if (n > INT_MAX) return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "Slot index out of range: %u", n); - a = reallocarray(arg_wipe_slots, sizeof(int), arg_n_wipe_slots + 1); + a = reallocarray(arg_wipe_slots, arg_n_wipe_slots + 1, sizeof(int)); if (!a) return log_oom(); diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 5ac90223ffd..e3d1eb8f33b 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -1288,7 +1288,7 @@ static int message_push_fd(sd_bus_message *m, int fd) { if (copy < 0) return -errno; - f = reallocarray(m->fds, sizeof(int), m->n_fds + 1); + f = reallocarray(m->fds, m->n_fds + 1, sizeof(int)); if (!f) { m->poisoned = true; safe_close(copy); diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 3e88d349e16..c72fccc229e 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -1081,7 +1081,7 @@ _public_ int sd_get_uids(uid_t **users) { uid_t *t; n = MAX(16, 2*r); - t = reallocarray(l, sizeof(uid_t), n); + t = reallocarray(l, n, sizeof(uid_t)); if (!t) return -ENOMEM;