]> 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 07:59:28 +0000 (17:59 +1000)
52 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/tests/tkey_test.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 b598d91d0e0a12949d5cbe379fa9255f023a7a09..610d23e36d952c2bd324445315e0b7ae19b6425e 100644 (file)
@@ -464,7 +464,7 @@ main(int argc, char **argv) {
        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 {
@@ -479,6 +479,7 @@ main(int argc, char **argv) {
                if (usekeyset) {
                        result = loadkeyset(dir, &rdataset);
                } else {
+                       INSIST(filename != NULL);
                        result = loadset(filename, &rdataset);
                }
 
index 0e44c5d639b7e5bc29472fa088977ae73efc44a2..48c84b2d98497a91b929a4140c2f1a7dbcbf05f6 100644 (file)
@@ -854,6 +854,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 5f9fdd21e21f6899b94fe31414382092f851d795..4a5c7ee7959dc92c9867c23f69031c37b8af3134 100644 (file)
@@ -10610,17 +10610,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:
@@ -10634,8 +10638,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",
@@ -10647,43 +10652,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));
@@ -10702,8 +10716,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));
@@ -10711,26 +10726,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);
 }
 
@@ -15258,13 +15278,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 8a7f9128123baffb18110a3ae86e516f2c90e843..784be63696e052f55499f369b3c84bfefdb0d18b 100644 (file)
@@ -26,6 +26,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 e169a377f3c78513c29fdcb7dd89e7c0205cca12..3348b3428ce565e44e8f74adb8a3eeb4bdea05af 100644 (file)
@@ -73,10 +73,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 fb49f1f9e8a7d86eda0679131dcf613b8d9465dd..1231c41bcdaec5d7dc48333fdd2afef46081cc06 100644 (file)
@@ -72,10 +72,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 2e71d9f43e54b70f9013e8ea09ce92c9add96c58..c89c47cc22c4f98f95e2bed891510bc272b65d24 100644 (file)
@@ -73,10 +73,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 af19be6b1f126b2c5218f84eefecd69b14385759..64a80bb289cebb8ea267b1cb1ec36931a72c501a 100644 (file)
@@ -73,10 +73,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 1998c9d04687d7f8f88f06f9be8703f290097190..181075efa83147521851a7ccef97713cb6cc5113 100644 (file)
@@ -73,10 +73,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 6ef29a01d8765ed2d83992fc61105dcec04747f8..6edf643b165013d9b53ae278b77527630bec594c 100644 (file)
@@ -73,10 +73,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 de502f5099b2ed87937e0d08d949446e42aa1b7f..41f37204ae20013476f51bfe016a1cc361b7f5f0 100644 (file)
@@ -73,10 +73,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 9b53ba2eed5c1faf1cd3f062155f4b606ae288a7..9a73ce1c3d424ea027e84c02621861fca06bff73 100644 (file)
@@ -73,10 +73,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 aea715238fc7de6bcf5e63a1099369796f1b2749..f76722686659ac2f762556ce7ab8b6cd27efc86a 100644 (file)
@@ -73,10 +73,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 c6207cbe0dfce1d5d86a3d3b376421e0738afea0..11d2549ca7877db0de518e361358ba4f32243d8f 100644 (file)
@@ -73,10 +73,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
@@ -280,7 +280,7 @@ main(int argc, char *argv[]) {
                        fprintf(stderr,
                                "C_DestroyObject: Error = 0x%.8lX\n",
                                rv);
-                       errflg = 1;
+                       error = 1;
                }
        }
 
index 29e2407705a7fd6055bed3997f31e19877cdd804..a4e6968bf8e4b8301ae2f91cc16d113d2b083436 100644 (file)
@@ -967,7 +967,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;
@@ -981,6 +980,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 7b001f21f704db9e36f64e054ac01ab860d5e0f4..425638abbffdc7353c045339a96ba2cde5c16dea 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 800271956ce5051fb3fccc886a5997087179df8b..1b18480fd5327bc0a9a223d0eb42d5d19153ce44 100644 (file)
@@ -1769,7 +1769,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;
@@ -1784,7 +1784,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;
@@ -1804,7 +1804,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;
@@ -1828,10 +1827,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);
@@ -1843,7 +1839,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];
@@ -1853,10 +1848,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);
@@ -1934,15 +1926,15 @@ dns_dnssec_syncupdate(dns_dnsseckeylist_t *keys, dns_dnsseckeylist_t *rmkeys,
                        if (!dns_rdataset_isassociated(cdnskey) ||
                            !exists(cdnskey, &cdnskeyrdata))
                        {
-                               RETERR(publish(&cdnskeyrdata, diff, origin,
-                                              ttl, mctx));
+                               RETERR(addrdata(&cdnskeyrdata, diff, origin,
+                                               ttl, mctx));
                        }
                        /* Only publish SHA-256 (SHA-1 is deprecated) */
                        if (!dns_rdataset_isassociated(cds) ||
                            !exists(cds, &cds_sha256))
                        {
-                               RETERR(publish(&cds_sha256, diff, origin,
-                                              ttl, mctx));
+                               RETERR(addrdata(&cds_sha256, diff, origin,
+                                               ttl, mctx));
                        }
                }
 
index 1d1f258e54355cc81135317b0c6cfd643ae7deae..e874639f8d087acfff68ddaadb6fe0470331d916 100644 (file)
@@ -389,7 +389,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 126091138c4f6223cf01f7f8028606a104c7c68d..3c1ddec1d00fb990e33a6aa055e4067199f5e434 100644 (file)
@@ -756,7 +756,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;
@@ -765,8 +767,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 6e169bfa90ea71161c800ca23c49093e610e493c..12dafa8e2aac23250b710fc7139a118e49309810 100644 (file)
@@ -2369,15 +2369,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 249504744265dc45644b2d8604b7f5c83f0011e0..e35745168dfb8e2b674a597fffb92a170ffb0265 100644 (file)
@@ -106,6 +106,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 04cff0b1ee904e07e5073a9bd83b4908dfc1d843..7f9c244c6a18e8af68a7bedeb6607bebcff11450 100644 (file)
@@ -243,6 +243,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);
@@ -303,6 +304,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 6503688dffb753241cc2d2694450491ed5eda240..ecf13c7625b11bd9eee809b69167f46ca4086ab6 100644 (file)
@@ -426,6 +426,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);
@@ -494,6 +495,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 70f81c47e592bc9ec4c0d67172f0fb9c3369e3e4..b0e5a2c6e62797c0bbde949293ea3ac64720e1be 100644 (file)
@@ -2948,6 +2948,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");
@@ -2967,7 +2973,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
@@ -3000,8 +3006,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 &&
@@ -3025,13 +3035,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 0ccda5c3ca0fa9acc4b0dad0a05f5978700dd029..7dc51ee2465805919a646b33d004b0f1329dca51 100644 (file)
@@ -360,8 +360,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
@@ -390,7 +392,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) {
@@ -402,7 +407,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;
@@ -422,8 +426,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 "|" */
@@ -456,8 +460,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 66a30b9f2954332d6dbc87be7d33debbf9d26811..5b0fb033dc820b0eaaa28ceaee9bf51e426ed126 100644 (file)
@@ -55,6 +55,7 @@ __wrap_isc__mem_get(isc_mem_t *mctx, size_t size)
        mock_assert(has_enough_memory, "mock isc_mem_get failed",
                    __FILE__, __LINE__);
 
+       /* cppcheck-suppress leakNoVarFunctionCall */
        return (malloc(size));
 }
 
index 848ab0b7017f35945a79eab2f0e9415a841d29fc..ee33c00440375bf2073d3eec8757139f3b7f94a6 100644 (file)
@@ -121,6 +121,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 1904c26dc6fd0fbd33dbb8144d6bd9a22d242b42..49e5722528c9c28c0f61258c08007ccaff245bca 100644 (file)
@@ -6123,17 +6123,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 e1f4653ee02f57f1cdde44ea096f3d68d24aac93..902fa5fdd39b355f44caf92c95ecb4375e355187 100644 (file)
@@ -839,7 +839,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 5f2eab789180109d44f1f217dbe5a4078b79f109..cf97ad7b398d46b3a03d9fbdca3b0cd1f1d4ba06 100644 (file)
@@ -194,7 +194,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;
@@ -214,6 +213,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 832be1c2ce0e28811479ebe6c588c27b4cb38fbd..8dd3125aa305cbe5e1e6f418021bb12b6f191671 100644 (file)
@@ -164,6 +164,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 9e49baffcbdf74ab3a00da8649ff7800c458df76..b8d9a03d5ca8a98609ed4ab10ad192e2e196b4c7 100644 (file)
@@ -170,8 +170,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 672d2134ed242b14ee92d2ae98590458f7c5511c..6442b499c98ea0f9db5e63dbe372829c625e74e0 100644 (file)
@@ -157,8 +157,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 c60e1e27b976cc1639f977ca8929e03d8dbf45b1..89ed2d4e239adf6e5de2e11c87b23277f5c08fde 100644 (file)
@@ -137,6 +137,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 c3877d9655d59c1c5eb4194d62a80a72600d008b..dcad858398bcfa24c2365131c334de558df0bf93 100644 (file)
@@ -541,6 +541,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 a47eb9ba3691ad746d843370fb08d5ea46a46a41..0622a73d32d8b5cbc217ee5fb96562be01b116fa 100644 (file)
@@ -421,6 +421,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 1b8b945ef45b6b5a55126fab2d60463b9c1ced78..a00ae1256569b7ef07adf4459258a684dffe45c8 100644 (file)
@@ -164,6 +164,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 ad5ba506913071bb7a63ceaae1ae836b78a9afed..46992691c374261b6a2f6784f8a12f62ec8fcb58 100644 (file)
@@ -352,7 +352,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);
@@ -365,6 +364,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 10667faed7f4fd9384c1b424d4629e9300daeb3b..d8cbaa396e92cf721df67b5b8c26bf7d0126bacf 100644 (file)
@@ -278,8 +278,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 6f5e7ba830037f2c28488a0268d1a6b37bc9a1ec..850d076aea31648a298570455975573530b7b6e8 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;
@@ -56,10 +60,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.
@@ -68,24 +77,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) {
@@ -96,24 +103,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);
 
@@ -121,23 +136,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) {
@@ -149,28 +163,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 4ef5c031ec1ae9e5264ad5fee44b14e259f391f2..2226374ab9a8986a10b08127a08991f75feb92f4 100644 (file)
@@ -1334,9 +1334,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);
 }
 
 /*
@@ -2321,7 +2314,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;
@@ -2351,6 +2343,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,
@@ -3491,6 +3485,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 144ab6125245fe612edbd3815ed4291fe19617e8..acaed0d0f6fadb8b4c1d044e5c534fec549f309e 100644 (file)
@@ -87,7 +87,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;
@@ -137,6 +139,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;
@@ -165,6 +168,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;
@@ -186,6 +190,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;
@@ -201,9 +206,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)
@@ -226,9 +235,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 09877f69522b270f397460d010402c6295c8d1c7..b6c70e4bc6d75080f20aa2b8e8dfb03b3334374a 100644 (file)
@@ -2602,8 +2602,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 06b51340801fe45f0e9fa61c8c5c647687855bdf..699924c89996598660004eb959d4031e728e50e7 100644 (file)
@@ -2222,7 +2222,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);
@@ -2238,6 +2237,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 cac10a4c4d4f5b33fbaf5ba8b274b86ac44c647b..034b5bbf150e363e267acb878e68497a815fec1d 100644 (file)
@@ -543,11 +543,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) {
@@ -638,22 +637,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 */
@@ -1071,7 +1068,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;
@@ -1101,9 +1097,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) {
@@ -3792,7 +3789,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
@@ -3865,7 +3862,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
@@ -3914,7 +3911,7 @@ ns__clientmgr_getclient(ns_clientmgr_t *manager, ns_interface_t *ifp,
 
        *clientp = client;
 
-       return (ISC_R_SUCCESS);
+       return (result);
 }
 
 isc_result_t
@@ -4031,6 +4028,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) {