]> 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:19:26 +0000 (10:19 +0200)
Compiling with -O3 triggers the following warnings with GCC 9.1:

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

    rrl.c: In function ‘debit_rrl_entry’:
    rrl.c:602:35: error: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 9 [-Werror=format-truncation=]
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |                                   ^~
    rrl.c:602:30: note: directive argument in the range [0, 2147483647]
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |                              ^~~~~~~~
    rrl.c:602:3: note: ‘snprintf’ output between 6 and 15 bytes into a destination of size 13
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    rrl.c:602:35: error: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 9 [-Werror=format-truncation=]
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |                                   ^~
    rrl.c:602:30: note: directive argument in the range [0, 2147483647]
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |                              ^~~~~~~~
    rrl.c:602:3: note: ‘snprintf’ output between 6 and 15 bytes into a destination of size 13
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    rrl.c:602:35: error: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 9 [-Werror=format-truncation=]
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |                                   ^~
    rrl.c:602:30: note: directive argument in the range [0, 2147483647]
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |                              ^~~~~~~~
    rrl.c:602:3: note: ‘snprintf’ output between 6 and 15 bytes into a destination of size 13
      602 |   snprintf(buf, sizeof(buf), "age=%d", age);
          |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Prevent these warnings from being triggered by increasing the size of
the relevant arrays (task.c, rrl.c) and reordering conditions
(private_test.c).

(cherry picked from commit ce796ac1f4bf6c64ad0e8be937933309e6942c83)

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

index 0e51910e366b738481f25f2dffd7e8e1c83c6bb6..d4280515764e22b76641a9e6412b6a4f80cb4925 100644 (file)
@@ -593,7 +593,7 @@ get_entry(dns_rrl_t *rrl, const isc_sockaddr_t *client_addr,
 
 static void
 debit_log(const dns_rrl_entry_t *e, int age, const char *action) {
-       char buf[sizeof("age=12345678")];
+       char buf[sizeof("age=1234567890")];
        const char *age_str;
 
        if (age == DNS_RRL_FOREVER) {
index 8ecd54ad8d92d138f0a705d594b37a8097ca1b95..699da9b1c92f717db3078ceec909603b57818d27 100644 (file)
@@ -111,7 +111,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 51fe39649c398257dbbf240c6fbdb0b14327e364..a37b44312c96a31da87b47cd3236f8a3bf086512 100644 (file)
@@ -1452,7 +1452,7 @@ isc__taskmgr_create(isc_mem_t *mctx, unsigned int workers,
                if (isc_thread_create(run, manager,
                                      &manager->threads[manager->workers]) ==
                    ISC_R_SUCCESS) {
-                       char name[16];  /* thread name limit on Linux */
+                       char name[21];  /* thread name limit on Linux */
                        snprintf(name, sizeof(name), "isc-worker%04u", i);
                        isc_thread_setname(manager->threads[manager->workers],
                                           name);