mirror of
https://github.com/systemd/systemd
synced 2025-10-06 00:13:24 +02:00
coccinelle: automatically switch some uses of memcpy() → mempcpy()
Inspired by #22520, let's add a coccinelle script that converts this automatically.
This commit is contained in:
13
coccinelle/mempcpy.cocci
Normal file
13
coccinelle/mempcpy.cocci
Normal file
@@ -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);
|
@@ -683,8 +683,7 @@ static int base64_append_width(
|
|||||||
s += indent;
|
s += indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(s, x + width * line, act);
|
s = mempcpy(s, x + width * line, act);
|
||||||
s += act;
|
|
||||||
*(s++) = line < lines - 1 ? '\n' : '\0';
|
*(s++) = line < lines - 1 ? '\n' : '\0';
|
||||||
avail -= act;
|
avail -= act;
|
||||||
}
|
}
|
||||||
|
@@ -125,15 +125,12 @@ static char *combine_entries(const char *one, const char *two) {
|
|||||||
|
|
||||||
/* Body from @one */
|
/* Body from @one */
|
||||||
n = l1 - (b1 - one);
|
n = l1 - (b1 - one);
|
||||||
if (n > 0) {
|
if (n > 0)
|
||||||
memcpy(p, b1, n);
|
p = mempcpy(p, b1, n);
|
||||||
p += n;
|
|
||||||
|
|
||||||
/* Body from @two */
|
/* Body from @two */
|
||||||
} else {
|
else {
|
||||||
n = l2 - (b2 - two);
|
n = l2 - (b2 - two);
|
||||||
memcpy(p, b2, n);
|
p = mempcpy(p, b2, n);
|
||||||
p += n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(p - dest <= (ptrdiff_t)(l1 + l2));
|
assert(p - dest <= (ptrdiff_t)(l1 + l2));
|
||||||
|
Reference in New Issue
Block a user