From a16276abcec25b5d494600e59613dc90984114b3 Mon Sep 17 00:00:00 2001 From: Matthijs Mekking Date: Wed, 24 Jun 2020 14:14:29 +0200 Subject: [PATCH] Fix cppcheck warnings --- bin/dig/dighost.c | 1 + bin/dnssec/dnssec-keyfromlabel.c | 4 ++++ bin/dnssec/dnssec-keygen.c | 2 ++ doc/man/dnssec-importkey.1in | 2 +- lib/dns/update.c | 2 +- lib/isc/mem.c | 2 ++ lib/isc/radix.c | 12 ++++-------- lib/ns/client.c | 2 +- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index a12ff400192..7c720ea672a 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -1494,6 +1494,7 @@ save_opt(dig_lookup_t *lookup, char *code, char *value) { if (lookup->ednsopts == NULL) { cloneopts(lookup, NULL); } + INSIST(lookup->ednsopts != NULL); if (lookup->ednsopts[lookup->ednsoptscnt].value != NULL) { isc_mem_free(mctx, lookup->ednsopts[lookup->ednsoptscnt].value); diff --git a/bin/dnssec/dnssec-keyfromlabel.c b/bin/dnssec/dnssec-keyfromlabel.c index dc3b8d24287..e12169043a8 100644 --- a/bin/dnssec/dnssec-keyfromlabel.c +++ b/bin/dnssec/dnssec-keyfromlabel.c @@ -362,6 +362,7 @@ main(int argc, char **argv) { setup_logging(mctx, &log); if (predecessor == NULL) { + /* cppcheck-suppress nullPointerRedundantCheck */ if (label == NULL) { fatal("the key label was not specified"); } @@ -383,6 +384,7 @@ main(int argc, char **argv) { isc_result_totext(ret)); } + /* cppcheck-suppress nullPointerRedundantCheck */ if (strchr(label, ':') == NULL) { char *l; int len; @@ -394,11 +396,13 @@ main(int argc, char **argv) { label = l; } + /* cppcheck-suppress nullPointerRedundantCheck */ if (algname == NULL) { fatal("no algorithm specified"); } r.base = algname; + /* cppcheck-suppress nullPointerRedundantCheck */ r.length = strlen(algname); ret = dns_secalg_fromtext(&alg, &r); if (ret != ISC_R_SUCCESS) { diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index 996b3ac6a62..849947f08d9 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -1180,10 +1180,12 @@ main(int argc, char **argv) { } if (ctx.predecessor == NULL && ctx.policy == NULL) { + /* cppcheck-suppress nullPointerRedundantCheck */ if (algname == NULL) { fatal("no algorithm specified"); } r.base = algname; + /* cppcheck-suppress nullPointerRedundantCheck */ r.length = strlen(algname); ret = dns_secalg_fromtext(&ctx.alg, &r); if (ret != ISC_R_SUCCESS) { diff --git a/doc/man/dnssec-importkey.1in b/doc/man/dnssec-importkey.1in index cc941ac00f6..78a094684aa 100644 --- a/doc/man/dnssec-importkey.1in +++ b/doc/man/dnssec-importkey.1in @@ -39,7 +39,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .sp \fBdnssec\-importkey\fP reads a public DNSKEY record and generates a pair of .key/.private files. The DNSKEY record may be read from an existing -\&.key file, in which case a corresponding .private file will be +.key file, in which case a corresponding .private file will be generated, or it may be read from any other file or from the standard input, in which case both .key and .private files will be generated. .sp diff --git a/lib/dns/update.c b/lib/dns/update.c index 49f177002b5..2de3b5bf466 100644 --- a/lib/dns/update.c +++ b/lib/dns/update.c @@ -2183,7 +2183,7 @@ failure: dst_key_free(&state->zone_keys[i]); } - if (state != &mystate && state != NULL) { + if (state != &mystate) { *statep = NULL; state->magic = 0; isc_mem_put(diff->mctx, state, sizeof(*state)); diff --git a/lib/isc/mem.c b/lib/isc/mem.c index f90c520540b..ba58d02d156 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -445,6 +445,7 @@ more_frags(isc__mem_t *ctx, size_t new_size) { if (ctx->basic_blocks == NULL) { more_basic_blocks(ctx); } + INSIST(ctx->basic_blocks != NULL); total_size = ctx->mem_target; tmp = ctx->basic_blocks; @@ -516,6 +517,7 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) { if (ctx->freelists[new_size] == NULL) { more_frags(ctx, new_size); } + INSIST(ctx->freelists[new_size] != NULL); /* * The free list uses the "rounded-up" size "new_size". diff --git a/lib/isc/radix.c b/lib/isc/radix.c index 72416a61a59..6410e9d74d3 100644 --- a/lib/isc/radix.c +++ b/lib/isc/radix.c @@ -232,15 +232,15 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target, *target = NULL; - if (radix->head == NULL) { + node = radix->head; + if (node == NULL) { return (ISC_R_NOTFOUND); } - node = radix->head; addr = isc_prefix_touchar(prefix); bitlen = prefix->bitlen; - while (node->bit < bitlen) { + while (node != NULL && node->bit < bitlen) { if (node->prefix) { stack[cnt++] = node; } @@ -251,13 +251,9 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target, } else { node = node->l; } - - if (node == NULL) { - break; - } } - if (node && node->prefix) { + if (node != NULL && node->prefix) { stack[cnt++] = node; } diff --git a/lib/ns/client.c b/lib/ns/client.c index 00badb4ac56..41612224027 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -1358,7 +1358,7 @@ process_ecs(ns_client_t *client, isc_buffer_t *buf, size_t optlen) { } paddr = (uint8_t *)&caddr.type; - if (addrbytes != 0U) { + if (addrbytes > 0U) { memmove(paddr, isc_buffer_current(buf), addrbytes); isc_buffer_forward(buf, addrbytes); optlen -= addrbytes; -- 2.47.3