From: Mark Andrews Date: Wed, 26 Mar 2025 03:31:25 +0000 (+1100) Subject: Silence warning when initialising compress X-Git-Tag: v9.21.7~22^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a6b6be824ead47e24d48ffd8ab7c8277618fbc8;p=thirdparty%2Fbind9.git Silence warning when initialising compress 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). --- diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index d598447ad3a..be4cbb3c0fd 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -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);