]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: automatically switch some uses of memcpy() → mempcpy()
authorLennart Poettering <lennart@poettering.net>
Wed, 16 Feb 2022 09:52:51 +0000 (10:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 16 Feb 2022 16:26:26 +0000 (17:26 +0100)
Inspired by #22520, let's add a coccinelle script that converts this
automatically.

coccinelle/mempcpy.cocci [new file with mode: 0644]
src/basic/hexdecoct.c
src/libsystemd/sd-journal/catalog.c

diff --git a/coccinelle/mempcpy.cocci b/coccinelle/mempcpy.cocci
new file mode 100644 (file)
index 0000000..efb657a
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+@@
+expression x, y, z;
+@@
+- memcpy(x, y, z);
+- x += z;
++ x = mempcpy(x, y, z);
+@@
+expression x, y, z;
+@@
+- memcpy_safe(x, y, z);
+- x += z;
++ x = mempcpy_safe(x, y, z);
index 8c83a0e71a6befe1b6549d5ea8c1c921b40449c0..190fca8ee4d8ddffc28bbaa4e3afe38ad44f90ac 100644 (file)
@@ -683,8 +683,7 @@ static int base64_append_width(
                         s += indent;
                 }
 
-                memcpy(s, x + width * line, act);
-                s += act;
+                s = mempcpy(s, x + width * line, act);
                 *(s++) = line < lines - 1 ? '\n' : '\0';
                 avail -= act;
         }
index 4a2ba02ad0ed0ca90b5607666caaca5cf952a38f..16bd4a63f1d9389773c6d49d49f019d09d7ef06c 100644 (file)
@@ -125,15 +125,12 @@ static char *combine_entries(const char *one, const char *two) {
 
         /* Body from @one */
         n = l1 - (b1 - one);
-        if (n > 0) {
-                memcpy(p, b1, n);
-                p += n;
-
+        if (n > 0)
+                p = mempcpy(p, b1, n);
         /* Body from @two */
-        else {
+        else {
                 n = l2 - (b2 - two);
-                memcpy(p, b2, n);
-                p += n;
+                p = mempcpy(p, b2, n);
         }
 
         assert(p - dest <= (ptrdiff_t)(l1 + l2));