From 36c8d993a5256c4818e42792062223e0e641c0e2 Mon Sep 17 00:00:00 2001 From: Michel Machado Date: Mon, 10 Jun 2024 14:37:30 -0400 Subject: [PATCH] lib/net: avoid warning in log_if_name() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer GCC was issuing the following warning for the call of strncpy() in log_if_name(): /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: ‘__builtin_strncpy’ specified bound 32 equals destination size [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ The warning is not proper because the code is already handling string trucations. This commit disable -Wstringop-truncation for that single call of strncpy() using #pragma. --- lib/net.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/net.c b/lib/net.c index 5c5207f2..0673f390 100644 --- a/lib/net.c +++ b/lib/net.c @@ -1691,7 +1691,10 @@ log_if_name(char *if_name, size_t len, const struct gatekeeper_if *iface, } } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(if_name, iface->name, len); +#pragma GCC diagnostic pop if (unlikely(if_name[len - 1] != '\0')) { G_LOG(CRIT, "%s(%s/%u): bug: len = %lu < strlen(iface->name) = %lu\n", __func__, iface->name, port_id,