From: Michał Kępień Date: Fri, 31 May 2019 12:34:34 +0000 (+0200) Subject: Address GCC 9.1 -O3 compilation warnings X-Git-Tag: v9.14.4~29^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=1d0bb1de10f2fa8a27bb5facb4a01b8828af2257;p=thirdparty%2Fbind9.git Address GCC 9.1 -O3 compilation warnings Compiling with -O3 triggers the following warnings with GCC 9.1: task.c: In function ‘isc_taskmgr_create’: task.c:1386:43: warning: ‘%04u’ directive output may be truncated writing between 4 and 10 bytes into a region of size 6 [-Wformat-truncation=] 1386 | snprintf(name, sizeof(name), "isc-worker%04u", i); | ^~~~ task.c:1386:32: note: directive argument in the range [0, 4294967294] 1386 | snprintf(name, sizeof(name), "isc-worker%04u", i); | ^~~~~~~~~~~~~~~~ task.c:1386:3: note: ‘snprintf’ output between 15 and 21 bytes into a destination of size 16 1386 | snprintf(name, sizeof(name), "isc-worker%04u", i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private_test.c: In function ‘private_nsec3_totext_test’: private_test.c:113:9: warning: array subscript 4 is outside array bounds of ‘uint32_t[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds] 113 | while (*sp == '\0' && slen > 0) { | ^~~ private_test.c:106:11: note: while referencing ‘salt’ 106 | uint32_t salt; | ^~~~ Prevent these warnings from being triggered by increasing the size of the relevant array (task.c) and reordering conditions (private_test.c). (cherry picked from commit ce796ac1f4bf6c64ad0e8be937933309e6942c83) --- diff --git a/lib/dns/tests/private_test.c b/lib/dns/tests/private_test.c index 517bb1a1470..ee3def20470 100644 --- a/lib/dns/tests/private_test.c +++ b/lib/dns/tests/private_test.c @@ -110,7 +110,7 @@ make_nsec3(nsec3_testcase_t *testcase, dns_rdata_t *private, /* for simplicity, we're using a maximum salt length of 4 */ salt = htonl(testcase->salt); sp = (unsigned char *) &salt; - while (*sp == '\0' && slen > 0) { + while (slen > 0 && *sp == '\0') { slen--; sp++; } diff --git a/lib/isc/task.c b/lib/isc/task.c index 96b24e73743..8d6d409d35c 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -1382,7 +1382,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers, RUNTIME_CHECK(isc_thread_create(run, &manager->queues[i], &manager->queues[i].thread) == ISC_R_SUCCESS); - char name[16]; + char name[21]; snprintf(name, sizeof(name), "isc-worker%04u", i); isc_thread_setname(manager->queues[i].thread, name); }