]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: avoid compiler warning in UTI_IPSockAddrToString()
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 Aug 2025 13:26:17 +0000 (15:26 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 Aug 2025 13:30:27 +0000 (15:30 +0200)
Don't print directly a buffer of the pool to another buffer of
the pool to avoid a -Wrestrict warning produced by a recent gcc version.

util.c

diff --git a/util.c b/util.c
index 837330b2b666815a72ba3107fbe6c645db3f10b2..21fbc1bd72292c73a84aa54abc871fad5208fe92 100644 (file)
--- a/util.c
+++ b/util.c
@@ -545,12 +545,14 @@ UTI_CompareIPs(const IPAddr *a, const IPAddr *b, const IPAddr *mask)
 char *
 UTI_IPSockAddrToString(const IPSockAddr *sa)
 {
-  char *result;
+  char buf[BUFFER_LENGTH], *result;
+
+  /* Copy to a separate buffer to avoid a compiler warning */
+  snprintf(buf, sizeof (buf), "%s", UTI_IPToString(&sa->ip_addr));
 
   result = NEXT_BUFFER;
   snprintf(result, BUFFER_LENGTH,
-           sa->ip_addr.family != IPADDR_INET6 ? "%s:%hu" : "[%s]:%hu",
-           UTI_IPToString(&sa->ip_addr), sa->port);
+           sa->ip_addr.family != IPADDR_INET6 ? "%s:%hu" : "[%s]:%hu", buf, sa->port);
 
   return result;
 }