mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
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.
This commit is contained in:
committed by
Luca Boccassi
parent
51c58a9521
commit
2a9ab0974b
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user