From: Lennart Poettering Date: Wed, 16 Feb 2022 09:52:51 +0000 (+0100) Subject: coccinelle: automatically switch some uses of memcpy() → mempcpy() X-Git-Tag: v251-rc1~274^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=96ca229517c65c7f47c02e21e9778ac189a829c1;p=thirdparty%2Fsystemd.git coccinelle: automatically switch some uses of memcpy() → mempcpy() Inspired by #22520, let's add a coccinelle script that converts this automatically. --- diff --git a/coccinelle/mempcpy.cocci b/coccinelle/mempcpy.cocci new file mode 100644 index 00000000000..efb657ae790 --- /dev/null +++ b/coccinelle/mempcpy.cocci @@ -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); diff --git a/src/basic/hexdecoct.c b/src/basic/hexdecoct.c index 8c83a0e71a6..190fca8ee4d 100644 --- a/src/basic/hexdecoct.c +++ b/src/basic/hexdecoct.c @@ -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; } diff --git a/src/libsystemd/sd-journal/catalog.c b/src/libsystemd/sd-journal/catalog.c index 4a2ba02ad0e..16bd4a63f1d 100644 --- a/src/libsystemd/sd-journal/catalog.c +++ b/src/libsystemd/sd-journal/catalog.c @@ -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));