]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix -Wformat-truncation warning in totext_in_wks() 12519/head
authorMichal Nowak <mnowak@isc.org>
Thu, 6 Aug 2026 08:53:55 +0000 (10:53 +0200)
committerMichal Nowak <mnowak@isc.org>
Mon, 10 Aug 2026 11:08:38 +0000 (11:08 +0000)
GCC 16 at -O3 rejects the WKS port bitmap loop with:

  error: '%u' directive output may be truncated writing between 1 and
  10 bytes into a region of size 6 [-Werror=format-truncation=]

The INSIST() bounding the bitmap length keeps the printed port below
65536, but 'sr' escapes into inet_totext(), so the compiler must
assume every later call can clobber it and loses the range it needs
to prove the port fits.  Printing the port with '%hu' states the
16-bit bound in the format string instead of leaving it to be
re-derived from the bitmap length.

lib/dns/rdata/in_1/wks_11.c

index 8c980d4bc3c188776146eadab5289203fbe40cf6..0a49e0be197980e1ee8eb26bfeea8de7dcab9b49 100644 (file)
@@ -193,8 +193,8 @@ totext_in_wks(ARGS_TOTEXT) {
                        for (j = 0; j < 8; j++) {
                                if ((sr.base[i] & (0x80 >> j)) != 0) {
                                        {
-                                               snprintf(buf, sizeof(buf), "%u",
-                                                        i * 8 + j);
+                                               snprintf(buf, sizeof(buf),
+                                                        "%hu", i * 8 + j);
                                                RETERR(str_totext(" ", target));
                                                RETERR(str_totext(buf, target));
                                        }