]> 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:09:02 +0000 (12:09 +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).

tests/dns/name_test.c

index d598447ad3ab305f65174182f0e0bf1a448f29ef..be4cbb3c0fd9193a188432c39b04016f1baa998e 100644 (file)
@@ -219,11 +219,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.
         */
@@ -284,8 +286,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);
@@ -345,8 +347,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);