]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Reorder arguments for calloc()-like functions, part #2
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 16 Jan 2024 21:42:39 +0000 (22:42 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 17 Jan 2024 10:09:09 +0000 (11:09 +0100)
To appease gcc-14's -Wcalloc-transposed-args check.

Follow-up for 2a9ab0974bb290bc66dc84d909c33d23361b0752.

src/basic/alloc-util.h
src/boot/efi/util.h
src/nspawn/nspawn-bind-user.c
src/test/test-alloc-util.c

index 05a6f211f7fc60a57a545056b34440c627b3f19e..136d2b3e687bcbd158248794f4ec447fba9dc495 100644 (file)
@@ -47,7 +47,7 @@ typedef void* (*mfree_func_t)(void *p);
 
 #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)))
+#define newdup_suffix0(t, p, n) ((t*) memdup_suffix0_multiply(p, (n), sizeof(t)))
 
 #define malloc0(n) (calloc(1, (n) ?: 1))
 
@@ -137,7 +137,7 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t need, si
 
 /* Note that we can't decorate this function with _alloc_() since the returned memory area is one byte larger
  * than the product of its parameters. */
-static inline void *memdup_suffix0_multiply(const void *p, size_t size, size_t need) {
+static inline void *memdup_suffix0_multiply(const void *p, size_t need, size_t size) {
         if (size_multiply_overflow(size, need))
                 return NULL;
 
index aef831d1327f6548e4eebe505d99b0160007918b..6e15a8b85dc4a5287c10a660e7acfa2ee3f6c1e3 100644 (file)
@@ -36,7 +36,7 @@ static inline void *xmalloc(size_t size) {
 }
 
 _malloc_ _alloc_(1, 2) _returns_nonnull_ _warn_unused_result_
-static inline void *xmalloc_multiply(size_t size, size_t n) {
+static inline void *xmalloc_multiply(size_t n, size_t size) {
         assert_se(!__builtin_mul_overflow(size, n, &size));
         return xmalloc(size);
 }
@@ -57,7 +57,7 @@ static inline void* xmemdup(const void *p, size_t l) {
         return memcpy(xmalloc(l), p, l);
 }
 
-#define xnew(type, n) ((type *) xmalloc_multiply(sizeof(type), (n)))
+#define xnew(type, n) ((type *) xmalloc_multiply((n), sizeof(type)))
 
 typedef struct {
         EFI_PHYSICAL_ADDRESS addr;
index c7e1a9253c557755e007bda9d060f566271af789..018e7a37e23cc37b89369f68ffdab61759f853ac 100644 (file)
@@ -286,7 +286,7 @@ int bind_user_prepare(
                 if (!sd)
                         return log_oom();
 
-                cm = reallocarray(*custom_mounts, sizeof(CustomMount), *n_custom_mounts + 1);
+                cm = reallocarray(*custom_mounts, *n_custom_mounts + 1, sizeof(CustomMount));
                 if (!cm)
                         return log_oom();
 
index 57cb886c4111455785f3dd98958b61b863082173..24cb5f73eb78cfd85ad0291a70d33631c5032c38 100644 (file)
@@ -100,7 +100,7 @@ TEST(memdup_multiply_and_greedy_realloc) {
         size_t i;
         int *p;
 
-        dup = memdup_suffix0_multiply(org, sizeof(int), 3);
+        dup = memdup_suffix0_multiply(org, 3, sizeof(int));
         assert_se(dup);
         assert_se(dup[0] == 1);
         assert_se(dup[1] == 2);
@@ -108,7 +108,7 @@ TEST(memdup_multiply_and_greedy_realloc) {
         assert_se(((uint8_t*) dup)[sizeof(int) * 3] == 0);
         free(dup);
 
-        dup = memdup_multiply(org, sizeof(int), 3);
+        dup = memdup_multiply(org, 3, sizeof(int));
         assert_se(dup);
         assert_se(dup[0] == 1);
         assert_se(dup[1] == 2);