]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Silence warning when initialising compress
authorMark Andrews <marka@isc.org>
Wed, 26 Mar 2025 03:31:25 +0000 (14:31 +1100)
committerMark Andrews <marka@isc.org>
Wed, 26 Mar 2025 12:43:55 +0000 (12:43 +0000)
The string literal initialalising compressed was too big for the
array as it has an unwanted NUL terminator.  This is allowed for
in C for historical reasons but produces a warning with some
compilers.  Adjust the declaration to include the NUL and adjust
the users to pass in an adjusted size which excludes the NUL rather
than sizeof(compressed).

(cherry picked from commit 6a6b6be824ead47e24d48ffd8ab7c8277618fbc8)

tests/dns/name_test.c

index 4cb3b9cce7247fe1d4a096f641a93ae424df1ce1..da34c7b20234057075a35278d85895cdc43367fd 100644 (file)
@@ -209,11 +209,13 @@ ISC_RUN_TEST_IMPL(compression) {
                                "\003bar\003yyy\003foo\0"
                                "\003xxx\003bar\003foo";
 
-       unsigned char compressed[29] = "\x0E\xAD"
-                                      "\003yyy\003foo\0"
-                                      "\003bar\xc0\x02"
-                                      "\xc0\x0B"
-                                      "\003xxx\003bar\xc0\x06";
+       unsigned char compressed[] = "\x0E\xAD"
+                                    "\003yyy\003foo\0"
+                                    "\003bar\xc0\x02"
+                                    "\xc0\x0B"
+                                    "\003xxx\003bar\xc0\x06";
+       const size_t compressed_len = sizeof(compressed) - 1;
+
        /*
         * Only the second owner name is compressed.
         */
@@ -268,8 +270,8 @@ ISC_RUN_TEST_IMPL(compression) {
        dns_compress_setpermitted(&cctx, permitted);
        dctx = dns_decompress_setpermitted(DNS_DECOMPRESS_DEFAULT, permitted);
 
-       compress_test(&name1, &name2, &name3, compressed, sizeof(compressed),
-                     plain, sizeof(plain), &cctx, dctx, true);
+       compress_test(&name1, &name2, &name3, compressed, compressed_len, plain,
+                     sizeof(plain), &cctx, dctx, true);
 
        dns_compress_rollback(&cctx, 0);
        dns_compress_invalidate(&cctx);
@@ -329,8 +331,8 @@ ISC_RUN_TEST_IMPL(compression) {
        dns_compress_setpermitted(&cctx, permitted);
        dctx = dns_decompress_setpermitted(DNS_DECOMPRESS_DEFAULT, permitted);
 
-       compress_test(&name1, &name2, &name3, compressed, sizeof(compressed),
-                     plain, sizeof(plain), &cctx, dctx, false);
+       compress_test(&name1, &name2, &name3, compressed, compressed_len, plain,
+                     sizeof(plain), &cctx, dctx, false);
 
        dns_compress_rollback(&cctx, 0);
        dns_compress_invalidate(&cctx);