]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
address or suppress cppcheck warnings
authorMark Andrews <marka@isc.org>
Thu, 8 Aug 2019 03:52:44 +0000 (13:52 +1000)
committerMark Andrews <marka@isc.org>
Thu, 12 Sep 2019 09:27:28 +0000 (19:27 +1000)
(cherry picked from commit b59fe46e76ee3a4556f7c379b71045a99ba7cbb9)

51 files changed:
bin/dnssec/dnssec-dsfromkey.c
bin/named/config.c
bin/named/server.c
bin/tests/optional/nsecify.c
bin/tests/pkcs11/benchmarks/create.c
bin/tests/pkcs11/benchmarks/find.c
bin/tests/pkcs11/benchmarks/genrsa.c
bin/tests/pkcs11/benchmarks/login.c
bin/tests/pkcs11/benchmarks/privrsa.c
bin/tests/pkcs11/benchmarks/pubrsa.c
bin/tests/pkcs11/benchmarks/session.c
bin/tests/pkcs11/benchmarks/sha1.c
bin/tests/pkcs11/benchmarks/sign.c
bin/tests/pkcs11/benchmarks/verify.c
bin/tools/mdig.c
bin/win32/BINDInstall/AccountInfo.cpp
bin/win32/BINDInstall/BINDInstall.rc
bin/win32/BINDInstall/BINDInstallDlg.cpp
bin/win32/BINDInstall/DirBrowse.cpp
bin/win32/BINDInstall/VersionInfo.cpp
bin/win32/BINDInstall/resource.h
fuzz/dns_rdata_fromwire_text.c
lib/dns/dnssec.c
lib/dns/dst_api.c
lib/dns/ecdb.c
lib/dns/name.c
lib/dns/nsec.c
lib/dns/openssldh_link.c
lib/dns/opensslrsa_link.c
lib/dns/rbt.c
lib/dns/rcode.c
lib/dns/ttl.c
lib/dns/zone.c
lib/irs/win32/resconf.c
lib/isc/lex.c
lib/isc/ratelimiter.c
lib/isc/sockaddr.c
lib/isc/tests/hmac_test.c
lib/isc/tests/md_test.c
lib/isc/tests/queue_test.c
lib/isc/tests/random_test.c
lib/isc/tests/task_test.c
lib/isc/unix/resource.c
lib/isc/win32/file.c
lib/isc/win32/interfaceiter.c
lib/isc/win32/ntgroups.c
lib/isc/win32/socket.c
lib/isc/win32/time.c
lib/isccfg/namedconf.c
lib/isccfg/parser.c
lib/ns/client.c

index 9a47fb48b872bd4b45af1dbba9a782fd0e5c8c00..9f6b3870b3eca9793c3fc46a61f19b2f3b543135 100644 (file)
@@ -362,12 +362,14 @@ main(int argc, char **argv) {
 
        dns_rdata_init(&rdata);
 
-       if (argc == 1)
+       if (argc == 1) {
                usage();
+       }
 
        result = isc_mem_create(0, 0, &mctx);
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
                fatal("out of memory");
+       }
 
 #if USE_PKCS11
        pk11_result_register();
@@ -395,9 +397,10 @@ main(int argc, char **argv) {
                        both = false;
                        break;
                case 'C':
-                       if (lookaside != NULL)
+                       if (lookaside != NULL) {
                                fatal("lookaside and CDS are mutually"
                                      " exclusive");
+                       }
                        cds = true;
                        break;
                case 'c':
@@ -409,16 +412,18 @@ main(int argc, char **argv) {
                        /* fall through */
                case 'K':
                        dir = isc_commandline_argument;
-                       if (strlen(dir) == 0U)
+                       if (strlen(dir) == 0U) {
                                fatal("directory must be non-empty string");
+                       }
                        break;
                case 'f':
                        filename = isc_commandline_argument;
                        break;
                case 'l':
-                       if (cds)
+                       if (cds) {
                                fatal("lookaside and CDS are mutually"
                                      " exclusive");
+                       }
                        lookaside = isc_commandline_argument;
                        if (strlen(lookaside) == 0U)
                                fatal("lookaside must be a non-empty string");
@@ -432,16 +437,18 @@ main(int argc, char **argv) {
                        break;
                case 'v':
                        verbose = strtol(isc_commandline_argument, &endp, 0);
-                       if (*endp != '\0')
+                       if (*endp != '\0') {
                                fatal("-v must be followed by a number");
+                       }
                        break;
                case 'F':
                        /* Reserved for FIPS mode */
                        /* FALLTHROUGH */
                case '?':
-                       if (isc_commandline_option != '?')
+                       if (isc_commandline_option != '?') {
                                fprintf(stderr, "%s: invalid argument -%c\n",
                                        program, isc_commandline_option);
+                       }
                        /* FALLTHROUGH */
                case 'h':
                        /* Does not return. */
@@ -460,46 +467,56 @@ main(int argc, char **argv) {
 
        rdclass = strtoclass(classname);
 
-       if (usekeyset && filename != NULL)
+       if (usekeyset && filename != NULL) {
                fatal("cannot use both -s and -f");
+       }
 
        /* When not using -f, -A is implicit */
-       if (filename == NULL)
+       if (filename == NULL) {
                showall = true;
+       }
 
-       if (argc < isc_commandline_index + 1 && filename == NULL)
+       if (argc < isc_commandline_index + 1 && filename == NULL) {
                fatal("the key file name was not specified");
-       if (argc > isc_commandline_index + 1)
+       }
+       if (argc > isc_commandline_index + 1) {
                fatal("extraneous arguments");
+       }
 
        result = dst_lib_init(mctx, NULL);
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
                fatal("could not initialize dst: %s",
                      isc_result_totext(result));
+       }
 
        setup_logging(mctx, &log);
 
        dns_rdataset_init(&rdataset);
 
        if (usekeyset || filename != NULL) {
-               if (argc < isc_commandline_index + 1 && filename != NULL) {
+               if (argc < isc_commandline_index + 1) {
                        /* using zone name as the zone file name */
                        namestr = filename;
-               } else
+               } else {
                        namestr = argv[isc_commandline_index];
+               }
 
                result = initname(namestr);
-               if (result != ISC_R_SUCCESS)
+               if (result != ISC_R_SUCCESS) {
                        fatal("could not initialize name %s", namestr);
+               }
 
-               if (usekeyset)
+               if (usekeyset) {
                        result = loadkeyset(dir, &rdataset);
-               else
+               } else {
+                       INSIST(filename != NULL);
                        result = loadset(filename, &rdataset);
+               }
 
-               if (result != ISC_R_SUCCESS)
+               if (result != ISC_R_SUCCESS) {
                        fatal("could not load DNSKEY set: %s\n",
                              isc_result_totext(result));
+               }
 
                for (result = dns_rdataset_first(&rdataset);
                     result == ISC_R_SUCCESS;
@@ -507,16 +524,18 @@ main(int argc, char **argv) {
                        dns_rdata_init(&rdata);
                        dns_rdataset_current(&rdataset, &rdata);
 
-                       if (verbose > 2)
+                       if (verbose > 2) {
                                logkey(&rdata);
+                       }
 
                        if (both) {
                                emit(DNS_DSDIGEST_SHA1, showall, lookaside,
                                     cds, &rdata);
                                emit(DNS_DSDIGEST_SHA256, showall, lookaside,
                                     cds, &rdata);
-                       } else
+                       } else {
                                emit(dtype, showall, lookaside, cds, &rdata);
+                       }
                }
        } else {
                unsigned char key_buf[DST_KEY_MAXSIZE];
@@ -529,8 +548,9 @@ main(int argc, char **argv) {
                             &rdata);
                        emit(DNS_DSDIGEST_SHA256, showall, lookaside, cds,
                             &rdata);
-               } else
+               } else {
                        emit(dtype, showall, lookaside, cds, &rdata);
+               }
        }
 
        if (dns_rdataset_isassociated(&rdataset))
@@ -538,14 +558,16 @@ main(int argc, char **argv) {
        cleanup_logging(&log);
        dst_lib_destroy();
        dns_name_destroy();
-       if (verbose > 10)
+       if (verbose > 10) {
                isc_mem_stats(mctx, stdout);
+       }
        isc_mem_destroy(&mctx);
 
        fflush(stdout);
        if (ferror(stdout)) {
                fprintf(stderr, "write error\n");
                return (1);
-       } else
+       } else {
                return (0);
+       }
 }
index 2cb1d615b00e8b8898eaa28a0f54220b4ae959b4..706d4181d883be79e6f7b3b6c1d1837b15993f7a 100644 (file)
@@ -883,6 +883,7 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list,
        if (stack != NULL)
                isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
 
+       INSIST(dscpcount == addrcount);
        INSIST(keycount == addrcount);
        INSIST(keycount == dscpcount);
 
index a572f7a0dae2aa2edd29eb80e0478a75cbc4e7bd..9a3915c56acf11a1bbcb0df76deecc3c8326fd02 100644 (file)
@@ -10745,17 +10745,21 @@ dumpdone(void *arg, isc_result_t result) {
        char buf[1024+32];
        const dns_master_style_t *style;
 
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
                goto cleanup;
-       if (dctx->mdctx != NULL)
+       }
+       if (dctx->mdctx != NULL) {
                dns_dumpctx_detach(&dctx->mdctx);
+       }
        if (dctx->view == NULL) {
                dctx->view = ISC_LIST_HEAD(dctx->viewlist);
-               if (dctx->view == NULL)
+               if (dctx->view == NULL) {
                        goto done;
+               }
                INSIST(dctx->zone == NULL);
-       } else
+       } else {
                goto resume;
+       }
  nextview:
        fprintf(dctx->fp, ";\n; Start view %s\n;\n", dctx->view->view->name);
  resume:
@@ -10769,8 +10773,9 @@ dumpdone(void *arg, isc_result_t result) {
        {
                style = &dns_master_style_cache;
                /* start cache dump */
-               if (dctx->view->view->cachedb != NULL)
+               if (dctx->view->view->cachedb != NULL) {
                        dns_db_attach(dctx->view->view->cachedb, &dctx->cache);
+               }
                if (dctx->cache != NULL) {
                        fprintf(dctx->fp,
                                ";\n; Cache dump of view '%s' (cache %s)\n;\n",
@@ -10782,43 +10787,52 @@ dumpdone(void *arg, isc_result_t result) {
                                                            dctx->task,
                                                            dumpdone, dctx,
                                                            &dctx->mdctx);
-                       if (result == DNS_R_CONTINUE)
+                       if (result == DNS_R_CONTINUE) {
                                return;
-                       if (result == ISC_R_NOTIMPLEMENTED)
+                       }
+                       if (result == ISC_R_NOTIMPLEMENTED) {
                                fprintf(dctx->fp, "; %s\n",
                                        dns_result_totext(result));
-                       else if (result != ISC_R_SUCCESS)
+                       } else if (result != ISC_R_SUCCESS) {
                                goto cleanup;
+                       }
                }
        }
 
        if ((dctx->dumpadb || dctx->dumpbad || dctx->dumpfail) &&
-           dctx->cache == NULL && dctx->view->view->cachedb != NULL)
+           dctx->cache == NULL && dctx->view->view->cachedb != NULL) {
                dns_db_attach(dctx->view->view->cachedb, &dctx->cache);
+       }
 
        if (dctx->cache != NULL) {
-               if (dctx->dumpadb)
+               if (dctx->dumpadb) {
                        dns_adb_dump(dctx->view->view->adb, dctx->fp);
-               if (dctx->dumpbad)
+               }
+               if (dctx->dumpbad) {
                        dns_resolver_printbadcache(dctx->view->view->resolver,
                                                   dctx->fp);
-               if (dctx->dumpfail)
+               }
+               if (dctx->dumpfail) {
                        dns_badcache_print(dctx->view->view->failcache,
                                           "SERVFAIL cache", dctx->fp);
+               }
                dns_db_detach(&dctx->cache);
        }
        if (dctx->dumpzones) {
                style = &dns_master_style_full;
  nextzone:
-               if (dctx->version != NULL)
+               if (dctx->version != NULL) {
                        dns_db_closeversion(dctx->db, &dctx->version,
                                            false);
-               if (dctx->db != NULL)
+               }
+               if (dctx->db != NULL) {
                        dns_db_detach(&dctx->db);
-               if (dctx->zone == NULL)
+               }
+               if (dctx->zone == NULL) {
                        dctx->zone = ISC_LIST_HEAD(dctx->view->zonelist);
-               else
+               } else {
                        dctx->zone = ISC_LIST_NEXT(dctx->zone, link);
+               }
                if (dctx->zone != NULL) {
                        /* start zone dump */
                        dns_zone_name(dctx->zone->zone, buf, sizeof(buf));
@@ -10837,8 +10851,9 @@ dumpdone(void *arg, isc_result_t result) {
                                                            dctx->task,
                                                            dumpdone, dctx,
                                                            &dctx->mdctx);
-                       if (result == DNS_R_CONTINUE)
+                       if (result == DNS_R_CONTINUE) {
                                return;
+                       }
                        if (result == ISC_R_NOTIMPLEMENTED) {
                                fprintf(dctx->fp, "; %s\n",
                                        dns_result_totext(result));
@@ -10846,26 +10861,31 @@ dumpdone(void *arg, isc_result_t result) {
                                POST(result);
                                goto nextzone;
                        }
-                       if (result != ISC_R_SUCCESS)
+                       if (result != ISC_R_SUCCESS) {
                                goto cleanup;
+                       }
                }
        }
-       if (dctx->view != NULL)
+       if (dctx->view != NULL) {
                dctx->view = ISC_LIST_NEXT(dctx->view, link);
-       if (dctx->view != NULL)
-               goto nextview;
+               if (dctx->view != NULL) {
+                       goto nextview;
+               }
+       }
  done:
        fprintf(dctx->fp, "; Dump complete\n");
        result = isc_stdio_flush(dctx->fp);
-       if (result == ISC_R_SUCCESS)
+       if (result == ISC_R_SUCCESS) {
                isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
                              NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
                              "dumpdb complete");
+       }
  cleanup:
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
                isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
                              NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
                              "dumpdb failed: %s", dns_result_totext(result));
+       }
        dumpcontext_destroy(dctx);
 }
 
@@ -15396,13 +15416,14 @@ named_server_servestale(named_server_t *server, isc_lex_t *lex,
        /* Look for the optional class name. */
        classtxt = next_token(lex, text);
        if (classtxt != NULL) {
+               isc_textregion_t r;
+
                /* Look for the optional view name. */
                viewtxt = next_token(lex, text);
-       }
-
-       if (classtxt != NULL) {
-               isc_textregion_t r;
 
+               /*
+                * If 'classtext' is not a valid class then it us a view name.
+                */
                r.base = classtxt;
                r.length = strlen(classtxt);
                result = dns_rdataclass_fromtext(&rdclass, &r);
index 08c8bd4ce8b6473ec56b51a24ef6e369496d3180..5d0545aa97f31f7ec35fa9e7dd44b4aa9d73c2c7 100644 (file)
@@ -28,6 +28,9 @@
 
 static isc_mem_t *mctx = NULL;
 
+ISC_PLATFORM_NORETURN_PRE static inline void
+fatal(const char *message) ISC_PLATFORM_NORETURN_POST;
+
 static inline void
 fatal(const char *message) {
        fprintf(stderr, "%s\n", message);
index cf343dc35c80a78e1037a608398c3952298b5fc7..44d677ecc981d619b48c729b13828b6b24e78a19 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index 79e8c00d9d43335f50bf6b3569fb333096fd978e..ffec229ac49d7afd274cc2aec1d8e887bf1ef066 100644 (file)
@@ -74,10 +74,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index fd2f682c89108fea9069aa5708b499b3dab0e8c5..96146bb2205762d10ab17b2b984957bfe6e88eee 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index 13085e6975051b149a456082b007cee874444c2b..c654fd460c739c76012bdf6074d90ccbc8fe4c32 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index c3f2d16e181dea3545cde8be96f06c2afef3401a..79b1eadcc88e2903e3e1c40361d23926d8c5bae3 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index c7423ac7130b01f676f30e134aed7a1884ae516d..8adc9b7faf7572bb21231227702bc43c80a01b90 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index a070c3f4fcdedbc5e409a7e5a069e6dfe1a9bad2..d442a19cd0e6e4db36ee7549fc886795cbb18eaa 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index 7b1d7cd9ae322f7f6b1a54705cd4c3cfb173a7a5..f932e60ec5da4ed67d31ea5acba639340920f2c6 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index 522f26ffe3c81677da408d25028d81a5f61f1acb..29a5a8a866e90140f3a880625bb1279a770bae5d 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
index da0f3aa5b1c4328537b26079ec97e8cf54989216..4a9295e47218a86de2be1d3cd3b2598b9229c209 100644 (file)
@@ -75,10 +75,10 @@ clock_gettime(int32_t id, struct timespec *tp)
        UNUSED(id);
 
        result = gettimeofday(&tv, NULL);
-       if (result)
-               return (result);
-       tp->tv_sec = tv.tv_sec;
-       tp->tv_nsec = (long) tv.tv_usec * 1000;
+       if (result == 0) {
+               tp->tv_sec = tv.tv_sec;
+               tp->tv_nsec = (long) tv.tv_usec * 1000;
+       }
        return (result);
 }
 #endif
@@ -282,7 +282,7 @@ main(int argc, char *argv[]) {
                        fprintf(stderr,
                                "C_DestroyObject: Error = 0x%.8lX\n",
                                rv);
-                       errflg = 1;
+                       error = 1;
                }
        }
 
index 810dd06e6a1a3729961016edcf9d5d54b9d7edb9..6d99592262826c4431e30ec7aa2fa2fc8dba6089 100644 (file)
@@ -903,7 +903,6 @@ save_opt(struct query *query, char *code, char *value) {
 
 static isc_result_t
 parse_netprefix(isc_sockaddr_t **sap, const char *value) {
-       isc_result_t result = ISC_R_SUCCESS;
        isc_sockaddr_t *sa = NULL;
        struct in_addr in4;
        struct in6_addr in6;
@@ -917,6 +916,7 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) {
 
        slash = strchr(buf, '/');
        if (slash != NULL) {
+               isc_result_t result;
                *slash = '\0';
                result = isc_parse_uint32(&netmask, slash + 1, 10);
                if (result != ISC_R_SUCCESS) {
index 73357a834d27b526b38ec7fe3d9238502a527f76..99d9afa7f0cab18dbe3ae461736ec6a8f8693526 100644 (file)
@@ -215,15 +215,20 @@ CreateServiceAccount(char *name, char *password) {
        ui.usri1_flags = UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD |
                         UF_SCRIPT;
        ui.usri1_script_path = NULL;
+
        /*
         * Call the NetUserAdd function, specifying level 1.
         */
        nStatus = NetUserAdd(NULL, dwLevel, (LPBYTE)&ui, &dwError);
-
-       if (nStatus != NERR_Success)
+       if (nStatus != NERR_Success) {
                return (FALSE);
+       }
 
        retstat = AddPrivilegeToAcccount(name, SE_SERVICE_LOGON_PRIV);
+       if (retstat != RTN_OK) {
+               return (FALSE);
+       }
+
        return (TRUE);
 }
 
@@ -239,9 +244,10 @@ AddPrivilegeToAcccount(LPTSTR name, LPWSTR PrivilegeName) {
        /*
         * Open the policy on the target machine.
         */
-       if ((Status = OpenPolicy(NULL, POLICY_ALL_ACCESS, &PolicyHandle))
-               != STATUS_SUCCESS)
+       Status = OpenPolicy(NULL, POLICY_ALL_ACCESS, &PolicyHandle);
+       if (Status != STATUS_SUCCESS) {
                return (RTN_ERROR);
+       }
 
        /*
         * Let's see if the account exists. Return if not
@@ -258,13 +264,14 @@ AddPrivilegeToAcccount(LPTSTR name, LPWSTR PrivilegeName) {
        }
 
        err = LsaNtStatusToWinError(SetPrivilegeOnAccount(PolicyHandle,
-               pSid, PrivilegeName, TRUE));
+                                   pSid, PrivilegeName, TRUE));
 
        LsaClose(PolicyHandle);
-       if (err == ERROR_SUCCESS)
+       if (err == ERROR_SUCCESS) {
                return (RTN_OK);
-       else
+       } else {
                return (err);
+       }
 }
 
 void
@@ -393,7 +400,6 @@ GetPrivilegesOnAccount(LSA_HANDLE PolicyHandle, PSID AccountSid,
        NTSTATUS Status;
        LSA_UNICODE_STRING *UserRights;
        ULONG CountOfRights;
-       unsigned int retlen = 0;
        DWORD i, j;
        int found;
 
@@ -404,6 +410,7 @@ GetPrivilegesOnAccount(LSA_HANDLE PolicyHandle, PSID AccountSid,
                return (Status);
 
        for (i = 0; i < CountOfRights; i++) {
+               unsigned int retlen;
                found = -1;
                retlen = UserRights[i].Length/sizeof(wchar_t);
                for (j = 0; j < *PrivCount; j++) {
index be9550bbaaacc126556e849a8dd0149d23b13aa1..96fe44fd6a82d9e8ab72d9f1512eac2481fc5252 100644 (file)
@@ -267,6 +267,7 @@ BEGIN
     IDS_UNINSTALL_MESSAGE   "Unregister Messages..."
     IDS_ERR_OPEN_SCM        "Could not open Service Control Manager\n(%s)"
     IDS_ERR_OPEN_SERVICE    "Could not open BIND Service\n(%s)"
+    IDS_ERR_START_SERVICE   "Could not start BIND Service\n(%s)"
     IDS_ERR_STOP_SERVICE    "Could not stop BIND Service\n(%s)"
     IDS_ERR_NONCRIT_FILE    "An error occurred while copying non-critical file %s\n(%s)\nDo you wish to continue?"
     IDS_ERR_COPY_FILE       "An error occurred while copying file %s\n(%s)\nInstallation will be terminated"
index 2e904b0f86fa8198b966016c0a6ee87d9c4a2634..050313659ab67b6dae2251b8b099adab21fc57c8 100644 (file)
@@ -215,6 +215,7 @@ CBINDInstallDlg::CBINDInstallDlg(CWnd* pParent /*=NULL*/)
        char winsys[MAX_PATH];
 
        //{{AFX_DATA_INIT(CBINDInstallDlg)
+       /* cppcheck-suppress useInitializationList */
        m_targetDir = _T("");
        m_version = _T("");
        m_toolsOnly = FALSE;
@@ -1089,7 +1090,6 @@ CBINDInstallDlg::UpdateService(CString StartName) {
                        SERVICE_ERROR_NORMAL, pathBuffer, NULL, NULL, NULL,
                        StartName, m_accountPassword, BIND_DISPLAY_NAME)
                        != TRUE) {
-                       DWORD err = GetLastError();
                        MsgBox(IDS_ERR_UPDATE_SERVICE, GetErrMessage());
                }
        }
@@ -1314,6 +1314,9 @@ void CBINDInstallDlg::StopBINDService() {
        }
 
        BOOL rc = ControlService(hBINDSvc, SERVICE_CONTROL_STOP, &svcStatus);
+       if (!rc) {
+               MsgBox(IDS_ERR_STOP_SERVICE, GetErrMessage());
+       }
 }
 
 /*
@@ -1328,30 +1331,38 @@ void CBINDInstallDlg::StartBINDService() {
        }
 
        SC_HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME,
-                                     SERVICE_ALL_ACCESS);
+                                        SERVICE_ALL_ACCESS);
        if (!hBINDSvc) {
                MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
        }
        BOOL rc = StartService(hBINDSvc, 0, NULL);
+       if (!rc) {
+               MsgBox(IDS_ERR_START_SERVICE, GetErrMessage());
+       }
 }
 
 /*
  * Check to see if the BIND service is running or not
  */
-BOOL CBINDInstallDlg::CheckBINDService() {
+BOOL
+CBINDInstallDlg::CheckBINDService() {
        SERVICE_STATUS svcStatus;
 
        SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
        if (hSCManager) {
                SC_HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME,
-                                             SERVICE_ALL_ACCESS);
+                                                SERVICE_ALL_ACCESS);
                if (hBINDSvc) {
                        BOOL rc = ControlService(hBINDSvc,
-                                 SERVICE_CONTROL_INTERROGATE, &svcStatus);
-                       if (!rc)
+                                                SERVICE_CONTROL_INTERROGATE,
+                                                &svcStatus);
+                       if (!rc) {
+                               /* cppcheck-suppress unreadVariable */
                                DWORD err = GetLastError();
+                       }
 
-                       return (svcStatus.dwCurrentState == SERVICE_RUNNING);
+                       return (rc &&
+                               svcStatus.dwCurrentState == SERVICE_RUNNING);
                }
        }
        return (FALSE);
@@ -1560,14 +1571,16 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) {
                return;
        }
 
-       hr = SHGetPathFromIDList(itemList, commonPath);
-       pMalloc->Free(itemList);
-
-       if (create) {
-               ProgramGroupCreate(commonPath);
+       if (SHGetPathFromIDList(itemList, commonPath)) {
+               if (create) {
+                       ProgramGroupCreate(commonPath);
+               } else {
+                       ProgramGroupRemove(commonPath);
+               }
        } else {
-               ProgramGroupRemove(commonPath);
+               MessageBox("SHGetPathFromIDList failed");
        }
+       pMalloc->Free(itemList);
 }
 
 CString CBINDInstallDlg::DestDir(int destination) {
index 758dc605735fb8ea7e69e4bd113a43573e011914..9692b5b0f97990e687ccb54e1d4fea5bdc3dc1f6 100644 (file)
@@ -46,6 +46,7 @@ CDirBrowse::CDirBrowse(CString initialDir, CWnd* pParent /*=NULL*/)
        //{{AFX_DATA_INIT(CDirBrowse)
                // NOTE: the ClassWizard will add member initialization here
        //}}AFX_DATA_INIT
+       /* cppcheck-suppress useInitializationList */
        m_selectedDir = initialDir;
 }
 
index e83348fa2a2ead076f7edd14fdf4d0a4e6b7b416..ddad36b706ebc58569d6c15d52571e80d37ea6f0 100644 (file)
@@ -79,8 +79,6 @@ CVersionInfo::CVersionInfo(CString filename)
                // And finally the version info is ours
                m_fixedInfo = (VS_FIXEDFILEINFO *)viBlob;
 
-               UINT blobLen = 0;
-
                // If we got here, all is good
        }
        m_isValid = TRUE;
index b176fe0930587e557c72efa4be8a13986b2d8368..6551205f5477656bde5760fd10853c3dcec848fd 100644 (file)
@@ -91,6 +91,7 @@
 #define IDC_ACCOUNT_PASSWORD            1031
 #define IDC_ACCOUNT_PASSWORD_CONFIRM    1032
 #define IDC_TOOLS_ONLY                 1033
+#define IDS_ERR_START_SERVICE          1034
 
 // Next default values for new objects
 // 
index 628c71ed27248b0255cd1bfe38c3a444c4e2c4dc..3cb304ca816998c0f18008aee39e41b5468d1028 100644 (file)
@@ -38,14 +38,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
 
 static void
 nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...) {
-       va_list ap;
 
        UNUSED(cb);
        UNUSED(fmt);
-       UNUSED(ap);
 }
 
-int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+int
+LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
        char totext[1024];
        dns_compress_t cctx;
        dns_decompress_t dctx;
index 437778460bc90f7c8e9be8f711cdc8709fd6b782..efe4353b51f9edcf66e70a14659226d87b7798bb 100644 (file)
@@ -1781,7 +1781,7 @@ make_dnskey(dst_key_t *key, unsigned char *buf, int bufsize,
 }
 
 static isc_result_t
-publish(dns_rdata_t *rdata, dns_diff_t *diff, dns_name_t *origin,
+addrdata(dns_rdata_t *rdata, dns_diff_t *diff, const dns_name_t *origin,
        dns_ttl_t ttl, isc_mem_t *mctx)
 {
        isc_result_t result;
@@ -1796,7 +1796,7 @@ publish(dns_rdata_t *rdata, dns_diff_t *diff, dns_name_t *origin,
 }
 
 static isc_result_t
-delrdata(dns_rdata_t *rdata, dns_diff_t *diff, dns_name_t *origin,
+delrdata(dns_rdata_t *rdata, dns_diff_t *diff, const dns_name_t *origin,
         dns_ttl_t ttl, isc_mem_t *mctx)
 {
        isc_result_t result;
@@ -1816,7 +1816,6 @@ publish_key(dns_diff_t *diff, dns_dnsseckey_t *key, const dns_name_t *origin,
            void (*report)(const char *, ...))
 {
        isc_result_t result;
-       dns_difftuple_t *tuple = NULL;
        unsigned char buf[DST_KEY_MAXSIZE];
        char keystr[DST_KEY_FORMATSIZE];
        dns_rdata_t dnskey = DNS_RDATA_INIT;
@@ -1840,10 +1839,7 @@ publish_key(dns_diff_t *diff, dns_dnsseckey_t *key, const dns_name_t *origin,
        }
 
        /* publish key */
-       RETERR(dns_difftuple_create(mctx, DNS_DIFFOP_ADD, origin, ttl,
-                                   &dnskey, &tuple));
-       dns_diff_appendminimal(diff, &tuple);
-       result = ISC_R_SUCCESS;
+       result = addrdata(&dnskey, diff, origin, ttl, mctx);
 
  failure:
        return (result);
@@ -1855,7 +1851,6 @@ remove_key(dns_diff_t *diff, dns_dnsseckey_t *key, const dns_name_t *origin,
          void (*report)(const char *, ...))
 {
        isc_result_t result;
-       dns_difftuple_t *tuple = NULL;
        unsigned char buf[DST_KEY_MAXSIZE];
        dns_rdata_t dnskey = DNS_RDATA_INIT;
        char alg[80];
@@ -1865,10 +1860,7 @@ remove_key(dns_diff_t *diff, dns_dnsseckey_t *key, const dns_name_t *origin,
               reason, dst_key_id(key->key), alg);
 
        RETERR(make_dnskey(key->key, buf, sizeof(buf), &dnskey));
-       RETERR(dns_difftuple_create(mctx, DNS_DIFFOP_DEL, origin, ttl, &dnskey,
-                                   &tuple));
-       dns_diff_appendminimal(diff, &tuple);
-       result = ISC_R_SUCCESS;
+       result = delrdata(&dnskey, diff, origin, ttl, mctx);
 
  failure:
        return (result);
@@ -1941,16 +1933,22 @@ dns_dnssec_syncupdate(dns_dnsseckeylist_t *keys, dns_dnsseckeylist_t *rmkeys,
                if (syncpublish(key->key, now)) {
                        if (!dns_rdataset_isassociated(cdnskey) ||
                            !exists(cdnskey, &cdnskeyrdata))
-                               RETERR(publish(&cdnskeyrdata, diff, origin,
-                                              ttl, mctx));
+                       {
+                               RETERR(addrdata(&cdnskeyrdata, diff, origin,
+                                               ttl, mctx));
+                       }
                        if (!dns_rdataset_isassociated(cds) ||
                            !exists(cds, &cdsrdata1))
-                               RETERR(publish(&cdsrdata1, diff, origin,
-                                              ttl, mctx));
+                       {
+                               RETERR(addrdata(&cdsrdata1, diff, origin,
+                                               ttl, mctx));
+                       }
                        if (!dns_rdataset_isassociated(cds) ||
                            !exists(cds, &cdsrdata2))
-                               RETERR(publish(&cdsrdata2, diff, origin,
-                                              ttl, mctx));
+                       {
+                               RETERR(addrdata(&cdsrdata2, diff, origin,
+                                               ttl, mctx));
+                       }
                }
 
                if (dns_rdataset_isassociated(cds) &&
index 948697358feb90efb6adb4c159f713d9e4744ced..e1d2141ef6045f41165d6ab0b222820cb3593039 100644 (file)
@@ -393,7 +393,7 @@ dst_key_tofile(const dst_key_t *key, int type, const char *directory) {
            (key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY)
                return (key->func->tofile(key, directory));
        else
-               return (ISC_R_SUCCESS);
+               return (ret);
 }
 
 void
index 10e0dfebfaaa6d41d5100614c12365fb7bb92808..796962f67d0b8388a174c012669fd2fe0e0c1135 100644 (file)
@@ -771,7 +771,9 @@ rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp) {
        REQUIRE(iteratorp != NULL);
        REQUIRE(DNS_RDATASETITER_VALID(*iteratorp));
 
+       /* cppcheck-suppress unreadVariable */
        u.rdatasetiterator = *iteratorp;
+       *iteratorp = NULL;
 
        mctx = u.ecdbiterator->common.db->mctx;
        u.ecdbiterator->common.magic = 0;
@@ -780,8 +782,6 @@ rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp) {
                          &u.ecdbiterator->common.node);
        isc_mem_put(mctx, u.ecdbiterator,
                    sizeof(ecdb_rdatasetiter_t));
-
-       *iteratorp = NULL;
 }
 
 static isc_result_t
index afc81d07a414310b84a68020e020a0f0614d740e..89c719a91f6b4e06000e9c4a2f107cccabd3899b 100644 (file)
@@ -2378,15 +2378,10 @@ dns_name_format(const dns_name_t *name, char *cp, unsigned int size) {
        isc_buffer_init(&buf, cp, size - 1);
        result = dns_name_totext(name, true, &buf);
        if (result == ISC_R_SUCCESS) {
-               /*
-                * Null terminate.
-                */
-               isc_region_t r;
-               isc_buffer_usedregion(&buf, &r);
-               ((char *) r.base)[r.length] = '\0';
-
-       } else
+               isc_buffer_putuint8(&buf, (uint8_t)'\0');
+       } else {
                snprintf(cp, size, "<unknown>");
+       }
 }
 
 /*
index cd3188622037c3ffc24465efadaaf37b7c57ecb6..1f0e8a4f9841f8b396c5eaef97207582ce2299c5 100644 (file)
@@ -108,6 +108,8 @@ dns_nsec_buildrdata(dns_db_t *db, dns_dbversion_t *version,
        unsigned int max_type;
        dns_rdatasetiter_t *rdsiter;
 
+       REQUIRE(target != NULL);
+
        memset(buffer, 0, DNS_NSEC_BUFFERSIZE);
        dns_name_toregion(target, &r);
        memmove(buffer, r.base, r.length);
index 3567d3d4472261dd72f9d898aaf4e3edefb4a753..c93f8127b1ad838bce98d77ccfb22127ae7e6e0f 100644 (file)
@@ -245,6 +245,7 @@ progress_cb(int p, int n, BN_GENCB *cb) {
 
        UNUSED(n);
 
+       /* cppcheck-suppress unreadVariable */
        u.dptr = BN_GENCB_get_arg(cb);
        if (u.fptr != NULL)
                u.fptr(p);
@@ -305,6 +306,7 @@ openssldh_generate(dst_key_t *key, int generator, void (*callback)(int)) {
                if (callback == NULL) {
                        BN_GENCB_set_old(cb, NULL, NULL);
                } else {
+                       /* cppcheck-suppress unreadVariable */
                        u.fptr = callback;
                        BN_GENCB_set(cb, &progress_cb, u.dptr);
                }
index 8425b86dfd6912d43569bf92e1739ec962877813..7e7d7e6a973584a3222ea043b5524d756dae6f31 100644 (file)
@@ -428,6 +428,7 @@ progress_cb(int p, int n, BN_GENCB *cb) {
 
        UNUSED(n);
 
+       /* cppcheck-suppress unreadVariable */
        u.dptr = BN_GENCB_get_arg(cb);
        if (u.fptr != NULL)
                u.fptr(p);
@@ -496,6 +497,7 @@ opensslrsa_generate(dst_key_t *key, int exp, void (*callback)(int)) {
        if (callback == NULL) {
                BN_GENCB_set_old(cb, NULL, NULL);
        } else {
+               /* cppcheck-suppress unreadVariable */
                u.fptr = callback;
                BN_GENCB_set(cb, &progress_cb, u.dptr);
        }
index bb7c46d1eb1726ac3789fd8bb21005d8ccb48648..dc2e8c76d446daa7e1bf283289825a3de6295505 100644 (file)
@@ -2962,6 +2962,12 @@ dns_rbt_indent(FILE *f, int depth) {
 
 void
 dns_rbt_printnodeinfo(dns_rbtnode_t *n, FILE *f) {
+
+       if (n == NULL) {
+               fprintf(f, "Null node\n");
+               return;
+       }
+
        fprintf(f, "Node info for nodename: ");
        printnodename(n, true, f);
        fprintf(f, "\n");
@@ -2981,7 +2987,7 @@ dns_rbt_printnodeinfo(dns_rbtnode_t *n, FILE *f) {
        fprintf(f, "Right: %p\n", n->right);
        fprintf(f, "Left: %p\n", n->left);
        fprintf(f, "Down: %p\n", n->down);
-       fprintf(f, "daTa: %p\n", n->data);
+       fprintf(f, "Data: %p\n", n->data);
 }
 
 static void
@@ -3014,8 +3020,12 @@ print_text_helper(dns_rbtnode_t *root, dns_rbtnode_t *parent,
 
        if (root != NULL) {
                printnodename(root, true, f);
+               /*
+                * Don't use IS_RED(root) as it tests for 'root != NULL'
+                * and cppcheck produces false positives.
+                */
                fprintf(f, " (%s, %s", direction,
-                       IS_RED(root) ? "RED" : "BLACK");
+                       COLOR(root) == RED ? "RED" : "BLACK");
 
                if ((! IS_ROOT(root) && PARENT(root) != parent) ||
                    (  IS_ROOT(root) && depth > 0 &&
@@ -3039,13 +3049,22 @@ print_text_helper(dns_rbtnode_t *root, dns_rbtnode_t *parent,
 
                depth++;
 
-               if (IS_RED(root) && IS_RED(LEFT(root)))
+               /*
+                * Don't use IS_RED(root) as it tests for 'root != NULL'
+                * and cppcheck produces false positives.
+                */
+               if (COLOR(root) == RED && IS_RED(LEFT(root))) {
                        fprintf(f, "** Red/Red color violation on left\n");
+               }
                print_text_helper(LEFT(root), root, depth, "left",
                                          data_printer, f);
 
-               if (IS_RED(root) && IS_RED(RIGHT(root)))
+               /*
+                * Don't use IS_RED(root) as cppcheck produces false positives.
+                */
+               if (COLOR(root) == RED && IS_RED(RIGHT(root))) {
                        fprintf(f, "** Red/Red color violation on right\n");
+               }
                print_text_helper(RIGHT(root), root, depth, "right",
                                          data_printer, f);
 
index 832303a19b6d96d218ee2637f017bd148d9c5ab9..5807a30716438cbc014908dea8fa0e53cd02e683 100644 (file)
@@ -363,8 +363,10 @@ dns_secalg_format(dns_secalg_t alg, char *cp, unsigned int size) {
        result = dns_secalg_totext(alg, &b);
        isc_buffer_usedregion(&b, &r);
        r.base[r.length] = 0;
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
+               /* cppcheck-suppress unreadVariable */
                r.base[0] = 0;
+       }
 }
 
 isc_result_t
@@ -393,7 +395,10 @@ dns_keyflags_fromtext(dns_keyflags_t *flagsp, isc_textregion_t *source)
 {
        isc_result_t result;
        char *text, *end;
-       unsigned int value, mask;
+       unsigned int value = 0;
+#ifdef notyet
+       unsigned int mask = 0;
+#endif
 
        result = maybe_numeric(&value, source, 0xffff, true);
        if (result == ISC_R_SUCCESS) {
@@ -405,7 +410,6 @@ dns_keyflags_fromtext(dns_keyflags_t *flagsp, isc_textregion_t *source)
 
        text = source->base;
        end = source->base + source->length;
-       value = mask = 0;
 
        while (text < end) {
                struct keyflag *p;
@@ -425,8 +429,8 @@ dns_keyflags_fromtext(dns_keyflags_t *flagsp, isc_textregion_t *source)
 #ifdef notyet
                if ((mask & p->mask) != 0)
                        warn("overlapping key flags");
-#endif
                mask |= p->mask;
+#endif
                text += len;
                if (delim != NULL)
                        text++; /* Skip "|" */
@@ -459,8 +463,10 @@ dns_dsdigest_format(dns_dsdigest_t typ, char *cp, unsigned int size) {
        result = dns_dsdigest_totext(typ, &b);
        isc_buffer_usedregion(&b, &r);
        r.base[r.length] = 0;
-       if (result != ISC_R_SUCCESS)
+       if (result != ISC_R_SUCCESS) {
+               /* cppcheck-suppress unreadVariable */
                r.base[0] = 0;
+       }
 }
 
 /*
index c30d54af6b048613055b1b455fc05f4ceccef2b3..0c545e258166606ffcb3940a4806d17a5d892985 100644 (file)
@@ -123,6 +123,7 @@ dns_ttl_totext(uint32_t src, bool verbose,
                 * here because region.base is type unsigned char *.
                 */
                isc_buffer_usedregion(target, &region);
+               /* cppcheck-suppress unreadVariable */
                region.base[region.length - 1] =
                        toupper(region.base[region.length - 1]);
        }
index cb4cae20915696fe0ca803c1c1384b7cd46dd348..e856486bbe5effe508422d3ff248842a2d05f53c 100644 (file)
@@ -6186,17 +6186,17 @@ dns_zone_maintenance(dns_zone_t *zone) {
 
 static inline bool
 was_dumping(dns_zone_t *zone) {
-       bool dumping;
 
        REQUIRE(LOCKED_ZONE(zone));
 
-       dumping = DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING);
-       DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_DUMPING);
-       if (!dumping) {
-               DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NEEDDUMP);
-               isc_time_settoepoch(&zone->dumptime);
+       if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING)) {
+               return (true);
        }
-       return (dumping);
+
+       DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_DUMPING);
+       DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NEEDDUMP);
+       isc_time_settoepoch(&zone->dumptime);
+       return (false);
 }
 
 /*%
index 45d3629bf12fdcf474621bdc4290690d920a301a..2b3eac2e8fe69d6acbc9ce6bfb68f5b7f5cf6a44 100644 (file)
@@ -32,7 +32,6 @@ isc_result_t
 get_win32_searchlist(irs_resconf_t *conf) {
        isc_result_t result = ISC_R_SUCCESS;
        HKEY hKey;
-       BOOL keyFound = TRUE;
        char searchlist[MAX_PATH];
        DWORD searchlen = MAX_PATH;
        LSTATUS status;
index ca5fe6d160bf1739e5a4d471fd2a382b8578c29f..ed1e32ce616f6d5553b5956556154ab5aa0a6a85 100644 (file)
@@ -855,7 +855,6 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
                        FATAL_ERROR(__FILE__, __LINE__,
                                    "Unexpected state %d",
                                    state);
-                       ISC_UNREACHABLE();
                }
 
        } while (!done);
index cd8755a5e9ffc88538e884dc54704a0adfa1468b..79ec4cb13bc81e2cf383c2da37c5a403eb1760c2 100644 (file)
@@ -198,7 +198,6 @@ isc_ratelimiter_dequeue(isc_ratelimiter_t *rl, isc_event_t *event) {
 
 static void
 ratelimiter_tick(isc_task_t *task, isc_event_t *event) {
-       isc_result_t result = ISC_R_SUCCESS;
        isc_ratelimiter_t *rl = (isc_ratelimiter_t *)event->ev_arg;
        isc_event_t *p;
        uint32_t pertic;
@@ -218,6 +217,7 @@ ratelimiter_tick(isc_task_t *task, isc_event_t *event) {
                         */
                        ISC_LIST_UNLINK(rl->pending, p, ev_ratelink);
                } else {
+                       isc_result_t result;
                        /*
                         * No work left to do.  Stop the timer so that we don't
                         * waste resources by having it fire periodically.
index bb28291aab34a6fb850ec7927da3859e04a79550..6e904b7be1e8a2bcac6d9259f03157fbb72b16ca 100644 (file)
@@ -166,6 +166,7 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) {
         */
        isc_buffer_availableregion(target, &avail);
        INSIST(avail.length >= 1);
+       /* cppcheck-suppress unreadVariable */
        avail.base[0] = '\0';
 
        return (ISC_R_SUCCESS);
index bffe817cdb0e2868271b5285bdc07165f18cff97..e3b2e1d7c876989f32bb6311e685dcec5310d8ff 100644 (file)
@@ -172,8 +172,10 @@ isc_hmac_update_test(void **state) {
 static void
 isc_hmac_reset_test(void **state) {
        isc_hmac_t *hmac = *state;
+#if 0
        unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused));
        unsigned int digestlen __attribute((unused));
+#endif
 
        assert_non_null(hmac);
 
index 5ec2c873f9badd67da5da8ad779fde59631054ef..e23862227964237483d58bcf3ba0cced59ef01d4 100644 (file)
@@ -159,8 +159,10 @@ isc_md_update_test(void **state) {
 static void
 isc_md_reset_test(void **state) {
        isc_md_t *md = *state;
+#if 0
        unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused));
        unsigned int digestlen __attribute((unused));
+#endif
 
        assert_non_null(md);
 
index ddd72ffbb74a91edb293bd01bb9dd855f129639d..4518abefaaaf56a7871008c186c8b01a40862415 100644 (file)
@@ -139,6 +139,8 @@ queue_valid(void **state) {
        assert_non_null(p);
        assert_int_equal(p->value, 5);
 
+       assert_null(queue.head);
+       assert_null(queue.tail);
        assert_true(ISC_QUEUE_EMPTY(queue));
 
        ISC_QUEUE_DESTROY(queue);
index 5d74503bbc3ea46192579ae46541918141212ca4..8dfca855f6e9b22196beb127766748ac19b604d6 100644 (file)
@@ -545,6 +545,7 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
 
        /* Preconditions (section 2.2.7 in NIST SP 800-22) */
        assert_true(numbits >= 100);
+       /* cppcheck-suppress constArgument */
        assert_true(mbits >= 20);
        assert_true((double) mbits > (0.01 * numbits));
        assert_true(numblocks < 100);
index f8bbd5a4e213ee092183f972d317b5edc6d61e09..64a85e4d6de787a84cb3149e08e1384f463b9d0f 100644 (file)
@@ -423,6 +423,8 @@ basic_cb(isc_task_t *task, isc_event_t *event) {
                j += 100;
        }
 
+       UNUSED(j);
+
        if (verbose) {
                print_message("# task %s\n", (char *)event->ev_arg);
        }
index b3567ef9c0f002b5f80f7a19351331ddc16e064f..47d9301a58932bc8b44e1d179bdbc8e9a6dffbab 100644 (file)
@@ -167,6 +167,7 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) {
                        return (ISC_R_SUCCESS);
        }
 #endif
+       /* cppcheck-suppress duplicateCondition */
        if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
                if (getrlimit(unixresource, &rl) == 0) {
                        rl.rlim_cur = rl.rlim_max;
index 76662f35a9ea6f37a69c419c65da8dd60a2d495b..e87fe51832bb5b313e6984f77f16db396ee47e44 100644 (file)
@@ -355,7 +355,6 @@ isc_file_template(const char *path, const char *templet, char *buf,
 isc_result_t
 isc_file_renameunique(const char *file, char *templet) {
        int fd;
-       int res = 0;
        isc_result_t result = ISC_R_SUCCESS;
 
        REQUIRE(file != NULL);
@@ -368,6 +367,7 @@ isc_file_renameunique(const char *file, char *templet) {
                close(fd);
 
        if (result == ISC_R_SUCCESS) {
+               int res;
                res = isc_file_safemovefile(file, templet);
                if (res != 0) {
                        result = isc__errno2result(errno);
index 6884221b30adf98e13fd7ce67700269b65a3f488..6873183f837df6990a20311b4cca7ee2356312ba 100644 (file)
@@ -290,8 +290,6 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
  ioctl_failure:
        if (iter->buf4 != NULL)
                isc_mem_put(mctx, iter->buf4, iter->buf4size);
-
- alloc_failure:
        if (iter->socket != INVALID_SOCKET)
                (void) closesocket(iter->socket);
 
index 217243cad86fe8e889cb2d2684a9f9665ada2125..0f23786226c6ad8929b9d73331855c05fae71e44 100644 (file)
 
 #define MAX_NAME_LENGTH 256
 
+#define CHECK(op) \
+       do { result = (op); if (result != ISC_R_SUCCESS) { goto cleanup; } } while (0)
+
 isc_result_t
 isc_ntsecurity_getaccountgroups(char *username, char **GroupList,
                                unsigned int maxgroups,
-                               unsigned int *totalGroups) {
+                               unsigned int *totalGroups)
+{
        LPGROUP_USERS_INFO_0 pTmpBuf;
        LPLOCALGROUP_USERS_INFO_0 pTmpLBuf;
        DWORD i;
@@ -58,10 +62,15 @@ isc_ntsecurity_getaccountgroups(char *username, char **GroupList,
        NET_API_STATUS nStatus;
        size_t retlen;
        wchar_t user[MAX_NAME_LENGTH];
+       isc_result_t result;
+
+       *totalGroups = 0;
 
        retlen = mbstowcs(user, username, MAX_NAME_LENGTH);
+       if (retlen == (size_t) (-1)) {
+               return (ISC_R_FAILURE);
+       }
 
-       *totalGroups = 0;
        /*
         * Call the NetUserGetLocalGroups function
         * specifying information level 0.
@@ -70,24 +79,22 @@ isc_ntsecurity_getaccountgroups(char *username, char **GroupList,
         * function should also return the names of the local
         * groups in which the user is indirectly a member.
         */
-       nStatus = NetUserGetLocalGroups(NULL,
-                                  user,
-                                  dwLevel,
-                                  dwFlags,
-                                  (LPBYTE *) &pBuf,
-                                  dwPrefMaxLen,
-                                  &dwEntriesRead,
-                                  &dwTotalEntries);
+       nStatus = NetUserGetLocalGroups(NULL, user, dwLevel, dwFlags,
+                                       (LPBYTE *) &pBuf, dwPrefMaxLen,
+                                       &dwEntriesRead, &dwTotalEntries);
        /*
         * See if the call succeeds,
         */
        if (nStatus != NERR_Success) {
-               if (nStatus == ERROR_ACCESS_DENIED)
+               if (nStatus == ERROR_ACCESS_DENIED) {
                        return (ISC_R_NOPERM);
-               if (nStatus == ERROR_MORE_DATA)
+               }
+               if (nStatus == ERROR_MORE_DATA) {
                        return (ISC_R_NOSPACE);
-               if (nStatus == NERR_UserNotFound)
+               }
+               if (nStatus == NERR_UserNotFound) {
                        dwEntriesRead = 0;
+               }
        }
 
        if (pBuf != NULL) {
@@ -98,24 +105,32 @@ isc_ntsecurity_getaccountgroups(char *username, char **GroupList,
                 for (i = 0;
                     (i < dwEntriesRead && *totalGroups < maxgroups); i++) {
                        assert(pTmpLBuf != NULL);
-                       if (pTmpLBuf == NULL)
+                       if (pTmpLBuf == NULL) {
                                break;
+                       }
                        retlen = wcslen(pTmpLBuf->lgrui0_name);
                        GroupList[*totalGroups] = (char *) malloc(retlen +1);
-                       if (GroupList[*totalGroups] == NULL)
-                               return (ISC_R_NOMEMORY);
+                       if (GroupList[*totalGroups] == NULL) {
+                               CHECK(ISC_R_NOMEMORY);
+                       }
 
                        retlen = wcstombs(GroupList[*totalGroups],
-                                pTmpLBuf->lgrui0_name, retlen);
+                                         pTmpLBuf->lgrui0_name, retlen);
+                       if (retlen == (size_t) (-1)) {
+                               free(GroupList[*totalGroups]);
+                               CHECK(ISC_R_FAILURE);
+                       }
                        GroupList[*totalGroups][retlen] = '\0';
-                       if (strcmp(GroupList[*totalGroups], "None") == 0)
+                       if (strcmp(GroupList[*totalGroups], "None") == 0) {
                                free(GroupList[*totalGroups]);
-                       else
+                       } else {
                                (*totalGroups)++;
+                       }
                        pTmpLBuf++;
                }
        }
        /* Free the allocated memory. */
+       /* cppcheck-suppress duplicateCondition */
        if (pBuf != NULL)
                NetApiBufferFree(pBuf);
 
@@ -123,23 +138,22 @@ isc_ntsecurity_getaccountgroups(char *username, char **GroupList,
        /*
         * Call the NetUserGetGroups function, specifying level 0.
         */
-       nStatus = NetUserGetGroups(NULL,
-                             user,
-                             dwLevel,
-                             (LPBYTE*)&pgrpBuf,
-                             dwPrefMaxLen,
-                             &dwEntriesRead,
-                             &dwTotalEntries);
+       nStatus = NetUserGetGroups(NULL, user, dwLevel,
+                                 (LPBYTE*)&pgrpBuf, dwPrefMaxLen,
+                                  &dwEntriesRead, &dwTotalEntries);
        /*
         * See if the call succeeds,
         */
        if (nStatus != NERR_Success) {
-               if (nStatus == ERROR_ACCESS_DENIED)
+               if (nStatus == ERROR_ACCESS_DENIED) {
                        return (ISC_R_NOPERM);
-               if (nStatus == ERROR_MORE_DATA)
+               }
+               if (nStatus == ERROR_MORE_DATA) {
                        return (ISC_R_NOSPACE);
-               if (nStatus == NERR_UserNotFound)
+               }
+               if (nStatus == NERR_UserNotFound) {
                        dwEntriesRead = 0;
+               }
        }
 
        if (pgrpBuf != NULL) {
@@ -151,28 +165,43 @@ isc_ntsecurity_getaccountgroups(char *username, char **GroupList,
                     (i < dwEntriesRead && *totalGroups < maxgroups); i++) {
                        assert(pTmpBuf != NULL);
 
-                       if (pTmpBuf == NULL)
+                       if (pTmpBuf == NULL) {
                                break;
+                       }
                        retlen = wcslen(pTmpBuf->grui0_name);
                        GroupList[*totalGroups] = (char *) malloc(retlen +1);
-                       if (GroupList[*totalGroups] == NULL)
-                               return (ISC_R_NOMEMORY);
+                       if (GroupList[*totalGroups] == NULL) {
+                               CHECK(ISC_R_NOMEMORY);
+                       }
 
                        retlen = wcstombs(GroupList[*totalGroups],
                                 pTmpBuf->grui0_name, retlen);
+                       if (retlen == (size_t) (-1)) {
+                               free(GroupList[*totalGroups]);
+                               CHECK(ISC_R_FAILURE);
+                       }
                        GroupList[*totalGroups][retlen] = '\0';
-                       if (strcmp(GroupList[*totalGroups], "None") == 0)
+                       if (strcmp(GroupList[*totalGroups], "None") == 0) {
                                free(GroupList[*totalGroups]);
-                       else
+                       } else {
                                (*totalGroups)++;
+                       }
                        pTmpBuf++;
                }
        }
        /*
         * Free the allocated memory.
         */
-       if (pgrpBuf != NULL)
+       /* cppcheck-suppress duplicateCondition */
+       if (pgrpBuf != NULL) {
                NetApiBufferFree(pgrpBuf);
+       }
 
        return (ISC_R_SUCCESS);
+
+ cleanup:
+       while (--(*totalGroups) > 0) {
+               free(GroupList[*totalGroups]);
+       }
+       return (result);
 }
index 7554e8cb65caa85ee08bb74dc70964b9df2fc24a..1145767667327e92aa8125ef4eaee7d0be7fd1d5 100644 (file)
@@ -1327,9 +1327,9 @@ use_min_mtu(isc_socket_t *sock) {
 
 static isc_result_t
 allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type,
-               isc_socket_t **socketp) {
+               isc_socket_t **socketp)
+{
        isc_socket_t *sock;
-       isc_result_t result;
 
        sock = isc_mem_get(manager->mctx, sizeof(*sock));
 
@@ -1385,13 +1385,6 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type,
        *socketp = sock;
 
        return (ISC_R_SUCCESS);
-
- error:
-       if (sock->recvbuf.base != NULL)
-               isc_mem_put(manager->mctx, sock->recvbuf.base, sock->recvbuf.len);
-       isc_mem_put(manager->mctx, sock, sizeof(*sock));
-
-       return (result);
 }
 
 /*
@@ -2318,7 +2311,6 @@ restart_accept(isc_socket_t *parent, IoCompletionInfo *lpo)
 static isc_threadresult_t WINAPI
 SocketIoThread(LPVOID ThreadContext) {
        isc_socketmgr_t *manager = ThreadContext;
-       BOOL bSuccess = FALSE;
        DWORD nbytes;
        IoCompletionInfo *lpo = NULL;
        isc_socket_t *sock = NULL;
@@ -2348,6 +2340,8 @@ SocketIoThread(LPVOID ThreadContext) {
         * Loop forever waiting on I/O Completions and then processing them
         */
        while (TRUE) {
+               BOOL bSuccess;
+
                wait_again:
                bSuccess = GetQueuedCompletionStatus(manager->hIoCompletionPort,
                                                     &nbytes,
@@ -3506,6 +3500,7 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
                _set_state(sock, SOCK_CLOSED);
        }
        how &= ~ISC_SOCKCANCEL_CONNECT;
+       UNUSED(how);
 
        maybe_free_socket(&sock, __LINE__);
 }
index 21c3aa878e3a7bf342f3ffc7ff7ca04db33d74ae..0af312bda33e2d3ef94f5191137e96cfd3d076df 100644 (file)
@@ -90,7 +90,9 @@ isc_time_set(isc_time_t *t, unsigned int seconds, unsigned int nanoseconds) {
        i1.LowPart = temp.dwLowDateTime;
        i1.HighPart = temp.dwHighDateTime;
 
+       /* cppcheck-suppress unreadVariable */
        i1.QuadPart += (unsigned __int64)nanoseconds/100;
+       /* cppcheck-suppress unreadVariable */
        i1.QuadPart += (unsigned __int64)seconds*10000000;
 
        t->absolute.dwLowDateTime = i1.LowPart;
@@ -140,6 +142,7 @@ isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
        if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval)
                return (ISC_R_RANGE);
 
+       /* cppcheck-suppress unreadVariable */
        i1.QuadPart += i->interval;
 
        t->absolute.dwLowDateTime  = i1.LowPart;
@@ -168,6 +171,7 @@ isc_time_add(const isc_time_t *t, const isc_interval_t *i, isc_time_t *result)
        if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval)
                return (ISC_R_RANGE);
 
+       /* cppcheck-suppress unreadVariable */
        i1.QuadPart += i->interval;
 
        result->absolute.dwLowDateTime = i1.LowPart;
@@ -189,6 +193,7 @@ isc_time_subtract(const isc_time_t *t, const isc_interval_t *i,
        if (i1.QuadPart < (unsigned __int64) i->interval)
                return (ISC_R_RANGE);
 
+       /* cppcheck-suppress unreadVariable */
        i1.QuadPart -= i->interval;
 
        result->absolute.dwLowDateTime = i1.LowPart;
@@ -204,9 +209,13 @@ isc_time_microdiff(const isc_time_t *t1, const isc_time_t *t2) {
 
        REQUIRE(t1 != NULL && t2 != NULL);
 
+       /* cppcheck-suppress unreadVariable */
        i1.LowPart  = t1->absolute.dwLowDateTime;
+       /* cppcheck-suppress unreadVariable */
        i1.HighPart = t1->absolute.dwHighDateTime;
+       /* cppcheck-suppress unreadVariable */
        i2.LowPart  = t2->absolute.dwLowDateTime;
+       /* cppcheck-suppress unreadVariable */
        i2.HighPart = t2->absolute.dwHighDateTime;
 
        if (i1.QuadPart <= i2.QuadPart)
@@ -229,9 +238,13 @@ isc_time_seconds(const isc_time_t *t) {
 
        SystemTimeToFileTime(&epoch1970, &temp);
 
+       /* cppcheck-suppress unreadVariable */
        i1.LowPart  = t->absolute.dwLowDateTime;
+       /* cppcheck-suppress unreadVariable */
        i1.HighPart = t->absolute.dwHighDateTime;
+       /* cppcheck-suppress unreadVariable */
        i2.LowPart  = temp.dwLowDateTime;
+       /* cppcheck-suppress unreadVariable */
        i2.HighPart = temp.dwHighDateTime;
 
        i3 = (i1.QuadPart - i2.QuadPart) / 10000000;
index a5724fed7eeda5f9dd72499f3838be66c74aa59e..35340739d630e66d410354c7e63bfd5d861fe1a3 100644 (file)
@@ -2596,8 +2596,9 @@ parse_unitstring(char *str, isc_resourcevalue_t *valuep) {
        default:
                return (ISC_R_FAILURE);
        }
-       if (value > UINT64_MAX / unit)
+       if (value > ((uint64_t)UINT64_MAX / unit)) {
                return (ISC_R_FAILURE);
+       }
        *valuep = value * unit;
        return (ISC_R_SUCCESS);
 }
index bdcfb3345d2b1ea9d1f8bc3d87b0f9da702aeaa8..e3a4ddd9eb37695df0b88f66421effb14db6dd81 100644 (file)
@@ -2220,7 +2220,6 @@ print_symval(cfg_printer_t *pctx, const char *name, cfg_obj_t *obj) {
 
 void
 cfg_print_mapbody(cfg_printer_t *pctx, const cfg_obj_t *obj) {
-       isc_result_t result = ISC_R_SUCCESS;
        const cfg_clausedef_t * const *clauseset;
 
        REQUIRE(pctx != NULL);
@@ -2236,6 +2235,7 @@ cfg_print_mapbody(cfg_printer_t *pctx, const cfg_obj_t *obj) {
                for (clause = *clauseset;
                     clause->name != NULL;
                     clause++) {
+                       isc_result_t result;
                        result = isc_symtab_lookup(obj->value.map.symtab,
                                                   clause->name, 0, &symval);
                        if (result == ISC_R_SUCCESS) {
index 2be462a5180efd98d18bcb69baccf32ab03fc229..0efe59a13c34b49827f7d5780f4a2b68cfd6b1b4 100644 (file)
@@ -545,11 +545,10 @@ exit_check(ns_client_t *client) {
 
                if (client->nreads > 0) {
                        dns_tcpmsg_cancelread(&client->tcpmsg);
-               }
-
-               /* Still waiting for read cancel completion. */
-               if (client->nreads > 0) {
-                       return (true);
+                       /* Still waiting for read cancel completion? */
+                       if (client->nreads > 0) {
+                               return (true);
+                       }
                }
 
                if (client->tcpmsg_valid) {
@@ -640,22 +639,20 @@ exit_check(ns_client_t *client) {
                if (client->naccepts > 0) {
                        isc_socket_cancel(client->tcplistener, client->task,
                                          ISC_SOCKCANCEL_ACCEPT);
-               }
-
-               /* Still waiting for accept cancel completion. */
-               if (client->naccepts > 0) {
-                       return (true);
+                       /* Still waiting for accept cancel completion? */
+                       if (client->naccepts > 0) {
+                               return (true);
+                       }
                }
 
                /* Accept cancel is complete. */
                if (client->nrecvs > 0) {
                        isc_socket_cancel(client->udpsocket, client->task,
                                          ISC_SOCKCANCEL_RECV);
-               }
-
-               /* Still waiting for recv cancel completion. */
-               if (client->nrecvs > 0) {
-                       return (true);
+                       /* Still waiting for recv cancel completion? */
+                       if (client->nrecvs > 0) {
+                               return (true);
+                       }
                }
 
                /* Still waiting for control event to be delivered */
@@ -1077,7 +1074,6 @@ client_sendpkg(ns_client_t *client, isc_buffer_t *buffer) {
        isc_netaddr_t netaddr;
        int match;
        unsigned int sockflags = ISC_SOCKFLAG_IMMEDIATE;
-       isc_dscp_t dispdscp = -1;
 
        if (TCP_CLIENT(client)) {
                sock = client->tcpsocket;
@@ -1107,9 +1103,10 @@ client_sendpkg(ns_client_t *client, isc_buffer_t *buffer) {
                pktinfo = NULL;
 
        if (client->dispatch != NULL) {
-               dispdscp = dns_dispatch_getdscp(client->dispatch);
-               if (dispdscp != -1)
-                       client->dscp = dispdscp;
+               isc_dscp_t dscp = dns_dispatch_getdscp(client->dispatch);
+               if (dscp != -1) {
+                       client->dscp = dscp;
+               }
        }
 
        if (client->dscp == -1) {
@@ -3857,7 +3854,7 @@ get_client(ns_clientmgr_t *manager, ns_interface_t *ifp,
        ev = &client->ctlevent;
        isc_task_send(client->task, &ev);
 
-       return (ISC_R_SUCCESS);
+       return (result);
 }
 
 static isc_result_t
@@ -3930,7 +3927,7 @@ get_worker(ns_clientmgr_t *manager, ns_interface_t *ifp, isc_socket_t *sock,
        ev = &client->ctlevent;
        isc_task_send(client->task, &ev);
 
-       return (ISC_R_SUCCESS);
+       return (result);
 }
 
 isc_result_t
@@ -3979,7 +3976,7 @@ ns__clientmgr_getclient(ns_clientmgr_t *manager, ns_interface_t *ifp,
 
        *clientp = client;
 
-       return (ISC_R_SUCCESS);
+       return (result);
 }
 
 isc_result_t
@@ -4096,6 +4093,8 @@ ns_client_logv(ns_client_t *client, isc_logcategory_t *category,
        const char *signer = "", *qname = "";
        dns_name_t *q = NULL;
 
+       REQUIRE(client != NULL);
+
        vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
 
        if (client->signer != NULL) {