]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Address GCC 9.1 -O3 compilation warnings
authorMichał Kępień <michal@isc.org>
Fri, 31 May 2019 12:34:34 +0000 (14:34 +0200)
committerMichał Kępień <michal@isc.org>
Tue, 11 Jun 2019 08:18:23 +0000 (10:18 +0200)
Compiling with -O3 triggers the following warnings with GCC 9.1:

    task.c: In function ‘isc_taskmgr_create’:
    task.c:1384:43: warning: ‘%04u’ directive output may be truncated writing between 4 and 10 bytes into a region of size 6 [-Wformat-truncation=]
     1384 |   snprintf(name, sizeof(name), "isc-worker%04u", i);
          |                                           ^~~~
    task.c:1384:32: note: directive argument in the range [0, 4294967294]
     1384 |   snprintf(name, sizeof(name), "isc-worker%04u", i);
          |                                ^~~~~~~~~~~~~~~~
    task.c:1384:3: note: ‘snprintf’ output between 15 and 21 bytes into a destination of size 16
     1384 |   snprintf(name, sizeof(name), "isc-worker%04u", i);
          |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    private_test.c: In function ‘private_nsec3_totext_test’:
    private_test.c:110:9: warning: array subscript 4 is outside array bounds of ‘uint32_t[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
      110 |  while (*sp == '\0' && slen > 0) {
          |         ^~~
    private_test.c:103:11: note: while referencing ‘salt’
      103 |  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).

lib/dns/tests/private_test.c
lib/isc/task.c

index e7e2d47dc94866c8b1231144b0beeb7deef88a13..e8e642d1baea795f3e2cbe9c5629c74f14a5fde1 100644 (file)
@@ -107,7 +107,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++;
        }
index 9af6914af40fc2b07ed029cc512482bf870566a2..7bfce3be6361991d72f7f9652bfb0eb2b2e2d472 100644 (file)
@@ -1380,7 +1380,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);
        }