]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Silence cppcheck 2.2 false positive in udp_recv()
authorMichał Kępień <michal@isc.org>
Wed, 25 Nov 2020 11:45:47 +0000 (12:45 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 25 Nov 2020 12:21:58 +0000 (13:21 +0100)
cppcheck 2.2 reports the following false positive:

    lib/dns/dispatch.c:1241:14: warning: Either the condition 'resp==NULL' is redundant or there is possible null pointer dereference: resp. [nullPointerRedundantCheck]
     if (disp != resp->disp) {
                 ^
    lib/dns/dispatch.c:1212:11: note: Assuming that condition 'resp==NULL' is not redundant
     if (resp == NULL) {
              ^
    lib/dns/dispatch.c:1241:14: note: Null pointer dereference
     if (disp != resp->disp) {
                 ^

Apparently this version of cppcheck gets confused about conditional
"goto" statements because line 1241 can never be reached if 'resp' is
NULL.

Move a code block to prevent the above false positive from being
reported without affecting the processing logic.

(cherry picked from commit 0b6216d1c702ef0aaa66a2a1bea70cfb12c81468)

lib/dns/dispatch.c

index 5c8d752a00ffc1d2fe8628ed6ec7ab91a7dfa423..bab7cd3a68777bb3912c2231e5fb82adbde95630 100644 (file)
@@ -1219,11 +1219,6 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) {
                             "search for response in bucket %d: %s", bucket,
                             (resp == NULL ? "not found" : "found"));
 
-               if (resp == NULL) {
-                       inc_stats(mgr, dns_resstatscounter_mismatch);
-                       free_buffer(disp, ev->region.base, ev->region.length);
-                       goto unlock;
-               }
        } else if (resp->id != id ||
                   !isc_sockaddr_equal(&ev->address, &resp->host)) {
                dispatch_log(disp, LVL(90),
@@ -1233,6 +1228,12 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) {
                goto unlock;
        }
 
+       if (resp == NULL) {
+               inc_stats(mgr, dns_resstatscounter_mismatch);
+               free_buffer(disp, ev->region.base, ev->region.length);
+               goto unlock;
+       }
+
        /*
         * Now that we have the original dispatch the query was sent
         * from check that the address and port the response was