]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix cppcheck 1.90 warnings
authorMichał Kępień <michal@isc.org>
Wed, 4 Mar 2020 11:41:01 +0000 (12:41 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 4 Mar 2020 11:41:01 +0000 (12:41 +0100)
cppcheck 1.90 reports some false positives for lib/dns/client.c:

    lib/dns/client.c:1431:2: warning: Either the condition 'rctx==((void*)0)' is redundant or there is possible null pointer dereference: rctx. [nullPointerRedundantCheck]
     rctx->rdataset = rdataset;
     ^
    lib/dns/client.c:1416:11: note: Assuming that condition 'rctx==((void*)0)' is not redundant
     if (rctx == NULL)
              ^
    lib/dns/client.c:1415:9: note: Assignment 'rctx=isc__mem_get(mctx,sizeof(*rctx),"lib/dns/client.c",1415)', assigned value is 0
     rctx = isc_mem_get(mctx, sizeof(*rctx));
            ^
    lib/dns/client.c:1431:2: note: Null pointer dereference
     rctx->rdataset = rdataset;
     ^
    lib/dns/client.c:1438:2: warning: Either the condition 'rctx==((void*)0)' is redundant or there is possible null pointer dereference: rctx. [nullPointerRedundantCheck]
     rctx->sigrdataset = sigrdataset;
     ^
    lib/dns/client.c:1416:11: note: Assuming that condition 'rctx==((void*)0)' is not redundant
     if (rctx == NULL)
              ^
    lib/dns/client.c:1415:9: note: Assignment 'rctx=isc__mem_get(mctx,sizeof(*rctx),"lib/dns/client.c",1415)', assigned value is 0
     rctx = isc_mem_get(mctx, sizeof(*rctx));
            ^
    lib/dns/client.c:1438:2: note: Null pointer dereference
     rctx->sigrdataset = sigrdataset;
     ^
    lib/dns/client.c:1445:2: warning: Either the condition 'rctx==((void*)0)' is redundant or there is possible null pointer dereference: rctx. [nullPointerRedundantCheck]
     rctx->client = client;
     ^
    lib/dns/client.c:1416:11: note: Assuming that condition 'rctx==((void*)0)' is not redundant
     if (rctx == NULL)
              ^
    lib/dns/client.c:1415:9: note: Assignment 'rctx=isc__mem_get(mctx,sizeof(*rctx),"lib/dns/client.c",1415)', assigned value is 0
     rctx = isc_mem_get(mctx, sizeof(*rctx));
            ^
    lib/dns/client.c:1445:2: note: Null pointer dereference
     rctx->client = client;
     ^
    lib/dns/client.c:1827:2: warning: Either the condition 'ctx==((void*)0)' is redundant or there is possible null pointer dereference: ctx. [nullPointerRedundantCheck]
     ctx->client = client;
     ^
    lib/dns/client.c:1815:10: note: Assuming that condition 'ctx==((void*)0)' is not redundant
     if (ctx == NULL)
             ^
    lib/dns/client.c:1814:8: note: Assignment 'ctx=isc__mem_get(client->mctx,sizeof(*ctx),"lib/dns/client.c",1814)', assigned value is 0
     ctx = isc_mem_get(client->mctx, sizeof(*ctx));
           ^
    lib/dns/client.c:1827:2: note: Null pointer dereference
     ctx->client = client;
     ^

All of them are caused by cppcheck not recognizing the relationship
between isc_mem_get() returning NULL and the result variable being set
to ISC_R_NOMEMORY (with a subsequent jump to a cleanup section).

Move "goto cleanup;" statements into error handling branches to prevent
cppcheck from generating these warnings.

lib/dns/client.c

index 822b4f9059b724404ce0d1a2197fe506048f1f2e..ce9d809f19ce8a6f1f52d5aeffe47640c7a82018 100644 (file)
@@ -1413,17 +1413,17 @@ dns_client_startresolve(dns_client_t *client, dns_name_t *name,
        ISC_LIST_INIT(event->answerlist);
 
        rctx = isc_mem_get(mctx, sizeof(*rctx));
-       if (rctx == NULL)
+       if (rctx == NULL) {
                result = ISC_R_NOMEMORY;
-       else {
+               goto cleanup;
+       } else {
                result = isc_mutex_init(&rctx->lock);
                if (result != ISC_R_SUCCESS) {
                        isc_mem_put(mctx, rctx, sizeof(*rctx));
                        rctx = NULL;
+                       goto cleanup;
                }
        }
-       if (result != ISC_R_SUCCESS)
-               goto cleanup;
 
        result = getrdataset(mctx, &rdataset);
        if (result != ISC_R_SUCCESS)
@@ -1812,17 +1812,17 @@ dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage,
        }
 
        ctx = isc_mem_get(client->mctx, sizeof(*ctx));
-       if (ctx == NULL)
+       if (ctx == NULL) {
                result = ISC_R_NOMEMORY;
-       else {
+               goto cleanup;
+       } else {
                result = isc_mutex_init(&ctx->lock);
                if (result != ISC_R_SUCCESS) {
                        isc_mem_put(client->mctx, ctx, sizeof(*ctx));
                        ctx = NULL;
+                       goto cleanup;
                }
        }
-       if (result != ISC_R_SUCCESS)
-               goto cleanup;
 
        ctx->client = client;
        ISC_LINK_INIT(ctx, link);