Commit 44fa4d20 authored by Mark Andrews's avatar Mark Andrews
Browse files

Merge branch '1043-cppcheck-detected-code-issues' into 'master'

Resolve "cppcheck-detected code issues"

Closes #1043

See merge request !2239
parents 30b6e93a b59fe46e
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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;
}
}
......
......@@ -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) {
......
......@@ -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++) {
......
......@@ -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"
......
......@@ -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) {
......
......@@ -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;
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment