1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-27 03:21:32 +03:00

Merge pull request #22531 from poettering/mempcpy-cocci

coccinelle: add semantic patch for using more mempcpy() instead of memcpy()
This commit is contained in:
Lennart Poettering 2022-02-16 22:20:33 +01:00 committed by GitHub
commit 3414394e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 17 deletions

13
coccinelle/mempcpy.cocci Normal file
View 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);

View 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;
}

View 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));

View File

@ -183,9 +183,8 @@ int request_process_traffic_control(Request *req) {
tc = ASSERT_PTR(req->traffic_control);
r = traffic_control_is_ready_to_configure(link, tc);
if (r <= 0) {
if (r <= 0)
return r;
}
r = traffic_control_configure(link, tc);
if (r < 0)

View File

@ -221,13 +221,11 @@ static void test_dns_stream(bool tls) {
log_info("test-resolved-stream: Started %s test", tls ? "TLS" : "TCP");
#if ENABLE_DNS_OVER_TLS
if (tls) {
/* For TLS mode, use DNS_OVER_TLS_OPPORTUNISTIC instead of
* DNS_OVER_TLS_YES, just to make certificate validation more
* lenient, allowing us to use self-signed certificates.
* We never downgrade, everything we test always goes over TLS */
if (tls)
/* For TLS mode, use DNS_OVER_TLS_OPPORTUNISTIC instead of DNS_OVER_TLS_YES, just to make
* certificate validation more lenient, allowing us to use self-signed certificates. We
* never downgrade, everything we test always goes over TLS */
manager.dns_over_tls_mode = DNS_OVER_TLS_OPPORTUNISTIC;
}
#endif
assert_se(sd_event_new(&event) >= 0);