summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coccinelle/mempcpy.cocci13
-rw-r--r--src/basic/hexdecoct.c3
-rw-r--r--src/libsystemd/sd-journal/catalog.c11
3 files changed, 18 insertions, 9 deletions
diff --git a/coccinelle/mempcpy.cocci b/coccinelle/mempcpy.cocci
new file mode 100644
index 0000000000..efb657ae79
--- /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 8c83a0e71a..190fca8ee4 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 4a2ba02ad0..16bd4a63f1 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));