From: Eric Bollengier Date: Wed, 5 Oct 2022 13:06:06 +0000 (+0200) Subject: Fix warnings reported by cppcheck X-Git-Tag: Beta-15.0.0~421 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97c2d585c633b8b32d306ff162a2b9177e1031c2;p=thirdparty%2Fbacula.git Fix warnings reported by cppcheck - shadows outer variable in stored/ansi_label.c - Fix variable initialization warning in prepare.h - Fix warning in stored/autochanger.c - Fix warning in console/console.c --- diff --git a/bacula/src/console/authenticate.c b/bacula/src/console/authenticate.c index d568a33d1..f4f7341f9 100644 --- a/bacula/src/console/authenticate.c +++ b/bacula/src/console/authenticate.c @@ -159,7 +159,6 @@ bool ConsoleAuthenticate::ClientAuthenticate(CONRES *cons, const char *password) char *data = msg.c_str(); POOL_MEM buf(PM_MESSAGE); char *input; - char *passwd; // the command is encoded as a first char of the message switch (dir->msg[0]){ @@ -187,8 +186,7 @@ bool ConsoleAuthenticate::ClientAuthenticate(CONRES *cons, const char *password) pm_strcpy(buf, NULL); } #else - passwd = getpass(data); - bstrncpy(buf.c_str(), passwd, buf.size()); + bstrncpy(buf.c_str(), getpass(data), buf.size()); #endif #if defined(DEVELOPER) } else { diff --git a/bacula/src/console/bbconsjson.c b/bacula/src/console/bbconsjson.c index 088cfa9c0..33f1acdc3 100644 --- a/bacula/src/console/bbconsjson.c +++ b/bacula/src/console/bbconsjson.c @@ -311,7 +311,7 @@ static void dump_json(display_filter *filter) sz = get_resource_size(resinx + r_first); if (sz < 0) { - Dmsg1(0, "Unknown resource type %d\n", resinx); + Dmsg1(10, "Unknown resource type %d\n", resinx); continue; } diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index e0a8c183b..7d15a4822 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -73,8 +73,6 @@ extern "C" void got_sigtin(int sig); /* Static variables */ static char *configfile = NULL; static BSOCK *UA_sock = NULL; -static DIRRES *dir = NULL; -static CONRES *cons = NULL; static FILE *output = stdout; static bool teeout = false; /* output to output and stdout */ static bool teein = false; /* input to output and stdout */ @@ -82,7 +80,6 @@ static bool stop = false; static bool no_conio = false; static int timeout = 0; static int argc; -static int numdir; static POOLMEM *args; static char *argk[MAX_CMD_ARGS]; static char *argv[MAX_CMD_ARGS]; @@ -997,7 +994,7 @@ static bool select_director(const char *director, const char *console, { int numcon=0, numdir=0; int i=0, item=0; - BSOCK *UA_sock; + BSOCK *UA; DIRRES *dir = NULL; CONRES *cons = NULL; @@ -1034,7 +1031,7 @@ static bool select_director(const char *director, const char *console, } if (dir == NULL) { /* prompt for director */ - UA_sock = new_bsock(); + UA = new_bsock(); try_again: sendit(_("Available Directors:\n")); LockRes(); @@ -1045,23 +1042,23 @@ try_again: } UnlockRes(); if (get_cmd(stdin, _("Select Director by entering a number: "), - UA_sock, 600) < 0) + UA, 600) < 0) { (void)WSACleanup(); /* Cleanup Windows sockets */ return 0; } - if (!is_a_number(UA_sock->msg)) { + if (!is_a_number(UA->msg)) { senditf(_("%s is not a number. You must enter a number between " "1 and %d\n"), - UA_sock->msg, numdir); + UA->msg, numdir); goto try_again; } - item = atoi(UA_sock->msg); + item = atoi(UA->msg); if (item < 0 || item > numdir) { senditf(_("You must enter a number between 1 and %d\n"), numdir); goto try_again; } - free_bsock(UA_sock); + free_bsock(UA); LockRes(); for (i=0; imsg, 1, sizeof_pool_memory(UA_sock->msg) - 1, fp); + int i = fread(UA_sock->msg, 1, sizeof_pool_memory(UA_sock->msg) - 1, fp); if (i > 0) { UA_sock->msg[i] = 0; UA_sock->msglen = i; diff --git a/bacula/src/dird/bdirjson.c b/bacula/src/dird/bdirjson.c index 5fe97f8a1..0654609c7 100644 --- a/bacula/src/dird/bdirjson.c +++ b/bacula/src/dird/bdirjson.c @@ -942,7 +942,7 @@ static void dump_json(display_filter *filter) sz = get_resource_size(resinx + r_first); if (sz < 0) { - Dmsg1(0, "Unknown resource type %d\n", resinx); + Dmsg1(10, "Unknown resource type %d\n", resinx); continue; } diff --git a/bacula/src/dird/malware.c b/bacula/src/dird/malware.c index 3430935dc..69fd8f47a 100644 --- a/bacula/src/dird/malware.c +++ b/bacula/src/dird/malware.c @@ -24,7 +24,7 @@ #include "bacula.h" #include "dird.h" -#define dbglvl 0 +#define dbglvl 50 /* Get hash type from the string length */ static const char *hash_get_type(int len) @@ -35,7 +35,7 @@ static const char *hash_get_type(int len) case 65: return "SHA256"; default: - Dmsg1(0, "Unknown hash len %d\n", len); + Dmsg1(dbglvl, "Unknown hash len %d\n", len); return NULL; } } diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 8d7c31f48..c3810efd0 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -563,9 +563,7 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op) pr->MaxVols = pool->max_volumes; pr->NumVols = 0; } else { /* update pool */ - if (pr->MaxVols != pool->max_volumes) { - pr->MaxVols = pool->max_volumes; - } + pr->MaxVols = pool->max_volumes; if (pr->MaxVols != 0 && pr->MaxVols < pr->NumVols) { pr->MaxVols = pr->NumVols; } @@ -580,10 +578,8 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op) pr->MaxVolJobs = pool->MaxVolJobs; pr->MaxVolFiles = pool->MaxVolFiles; pr->MaxVolBytes = pool->MaxVolBytes; - pr->MaxPoolBytes = pool->MaxPoolBytes; pr->AutoPrune = pool->AutoPrune; pr->ActionOnPurge = pool->action_on_purge; - pr->Recycle = pool->Recycle; pr->MaxPoolBytes = pool->MaxPoolBytes; if (pool->label_format) { bstrncpy(pr->LabelFormat, pool->label_format, sizeof(pr->LabelFormat)); diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index 6cb83f055..99d261290 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -543,10 +543,16 @@ static bool bvfs_parse_arg_version(UAContext *ua, bool *copies) { bool fnid_found=false; - *fnid=0; *client=NULL; - *versions=false; - *copies=false; + if (copies) { + *copies=false; + } + if (fnid) { + *fnid=0; + } + if (versions) { + *versions=false; + } for (int i=1; iargc; i++) { if (fnid && strcasecmp(ua->argk[i], NT_("fnid")) == 0) { diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index fb1a0fd2f..075378c2c 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -863,7 +863,7 @@ int truncate_cmd(UAContext *ua, const char *cmd) drive, sd); } } else { - Dmsg1(0, "Can't find MediaId=%lu\n", mr.MediaId); + Dmsg1(10, "Can't find MediaId=%lu\n", mr.MediaId); } } diff --git a/bacula/src/dird/ua_tree.c b/bacula/src/dird/ua_tree.c index d30631796..5b2e224af 100644 --- a/bacula/src/dird/ua_tree.c +++ b/bacula/src/dird/ua_tree.c @@ -238,7 +238,7 @@ int insert_tree_handler(void *ctx, int num_fields, char **row) "skipping new parts. Current sequence is %d\n"), row[1], node->delta_seq); - Dmsg3(0, "Something is wrong with Delta, skip it " + Dmsg3(50, "Something is wrong with Delta, skip it " "fname=%s d1=%d d2=%d\n", row[1], node->delta_seq, delta_seq); } return 0; diff --git a/bacula/src/filed/bfdjson.c b/bacula/src/filed/bfdjson.c index ed3bf962f..55519dce3 100644 --- a/bacula/src/filed/bfdjson.c +++ b/bacula/src/filed/bfdjson.c @@ -416,7 +416,7 @@ static void dump_json(display_filter *filter) sz = get_resource_size(resinx + r_first); if (sz < 0) { - Dmsg1(0, "Unknown resource type %d\n", resinx); + Dmsg1(10, "Unknown resource type %d\n", resinx); continue; } diff --git a/bacula/src/filed/fd_snapshot.c b/bacula/src/filed/fd_snapshot.c index e39384578..b990f847c 100644 --- a/bacula/src/filed/fd_snapshot.c +++ b/bacula/src/filed/fd_snapshot.c @@ -654,7 +654,7 @@ public: if (chk_dbglvl(DT_SNAPSHOT|100)) { for (i = 0; env[i] ; i++) { - Dmsg1(0, "%s\n", env[i]); + Dmsg1(DT_SNAPSHOT|100, "%s\n", env[i]); } } diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 25800af59..8d9917d63 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -845,7 +845,7 @@ static int proxy_cmd(JCR *jcr) OK = !jcr->is_canceled(); break; case -1: - Dmsg1(0, "Bad call to select ERR=%d\n", errno); + Dmsg1(10, "Bad call to select ERR=%d\n", errno); OK = false; break; default: diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 057350fa9..6dc552de4 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -327,7 +327,7 @@ static inline bool pop_delayed_data_streams(r_ctx &rctx) default: Jmsg(jcr, M_WARNING, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"), rds->stream); - Dmsg2(0, "Unknown stream=%d data=%s\n", rds->stream, rds->content); + Dmsg2(50, "Unknown stream=%d data=%s\n", rds->stream, rds->content); break; } if (rds->content) { @@ -1103,7 +1103,7 @@ void do_restore(JCR *jcr) } Jmsg(jcr, M_WARNING, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"), rctx.stream); - Dmsg2(0, "Unknown stream=%d data=%s\n", rctx.stream, bmsg->rbuf); + Dmsg2(50, "Unknown stream=%d data=%s\n", rctx.stream, bmsg->rbuf); break; } /* end switch(stream) */ diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 1f01a0d9a..19f7a9d70 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -1366,12 +1366,12 @@ int copyfile(const char *src, const char *dst) berrno be; fd_src = open(src, O_RDONLY); if (fd_src < 0) { - Dmsg2(0, "Unable to open %s ERR=%s\n", src, be.bstrerror(errno)); + Dmsg2(10, "Unable to open %s ERR=%s\n", src, be.bstrerror(errno)); goto bail_out; } fd_dst = open(dst, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd_dst < 0) { - Dmsg2(0, "Unable to open %s ERR=%s\n", dst, be.bstrerror(errno)); + Dmsg2(10, "Unable to open %s ERR=%s\n", dst, be.bstrerror(errno)); goto bail_out; } @@ -1384,7 +1384,7 @@ int copyfile(const char *src, const char *dst) len -= lenw; out_ptr += lenw; } else if (errno != EINTR) { - Dmsg3(0, "Unable to write %d bytes in %s. ERR=%s\n", len, dst, be.bstrerror(errno)); + Dmsg3(10, "Unable to write %d bytes in %s. ERR=%s\n", len, dst, be.bstrerror(errno)); goto bail_out; } } while (len > 0); @@ -1393,7 +1393,7 @@ int copyfile(const char *src, const char *dst) if (len == 0) { close(fd_src); if (close(fd_dst) < 0) { - Dmsg2(0, "Unable to close %s properly. ERR=%s\n", dst, be.bstrerror(errno)); + Dmsg2(10, "Unable to close %s properly. ERR=%s\n", dst, be.bstrerror(errno)); return -1; } /* Success! */ diff --git a/bacula/src/lib/events.c b/bacula/src/lib/events.c index fb0e4e38a..29bbd74d9 100644 --- a/bacula/src/lib/events.c +++ b/bacula/src/lib/events.c @@ -82,7 +82,7 @@ bool EVENTS_DBR::scan_line(const char *line) { if (scan_string(line, "Events: code=%127s daemon=%127s ref=%llx type=%127s source=%127s text=", EventsCode, EventsDaemon, &EventsRef, EventsType, EventsSource) != 5) { - Dmsg1(0, "Malformed Audit message [%s]\n", line); + Dmsg1(50, "Malformed Audit message [%s]\n", line); return false; /* invalid format */ } unbash_spaces(EventsSource); diff --git a/bacula/src/lib/runscript.c b/bacula/src/lib/runscript.c index 4e8d1ae1f..22e5b6a6a 100644 --- a/bacula/src/lib/runscript.c +++ b/bacula/src/lib/runscript.c @@ -153,7 +153,7 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) } if ((script->when & SCRIPT_AtJobCompletion) && (when & SCRIPT_AtJobCompletion)) { - Dmsg1(0, "AtJobCompletion jobstatus=%c\n", jcr->JobStatus); + Dmsg1(200, "AtJobCompletion jobstatus=%c\n", jcr->JobStatus); if ((script->on_success && (jcr->JobStatus == JS_Terminated || jcr->JobStatus == JS_Warnings)) || (script->on_failure && diff --git a/bacula/src/stored/ansi_label.c b/bacula/src/stored/ansi_label.c index 48f1c03f0..b05fa0483 100644 --- a/bacula/src/stored/ansi_label.c +++ b/bacula/src/stored/ansi_label.c @@ -130,7 +130,7 @@ int read_ansi_ibm_label(DCR *dcr) free_volume(dev); /* Store new Volume name */ q = dev->VolHdr.VolumeName; - for (int i=0; *p != ' ' && i < 6; i++) { + for (int j=0; *p != ' ' && j < 6; j++) { *q++ = *p++; } *q = 0; diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index c1002e1f4..da0cc65c3 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -363,7 +363,6 @@ bool unload_autochanger(DCR *dcr, int loaded) DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; const char *old_vol_name; - int slot; uint32_t timeout = dcr->device->max_changer_wait; bool ok = true; @@ -398,6 +397,7 @@ bool unload_autochanger(DCR *dcr, int loaded) if (loaded > 0) { POOL_MEM results(PM_MESSAGE); POOLMEM *changer = get_pool_memory(PM_FNAME); + int slot; Jmsg(jcr, M_INFO, 0, _("3307 Issuing autochanger \"unload Volume %s, Slot %d, Drive %d\" command.\n"), old_vol_name, loaded, dev->drive_index); @@ -450,7 +450,6 @@ static bool unload_other_drive(DCR *dcr, int slot, bool writing) DEVRES *device; int retries = 0; /* wait for device retries */ int loaded; - int i; if (!changer || !changer->device) { return false; @@ -471,7 +470,7 @@ static bool unload_other_drive(DCR *dcr, int slot, bool writing) * The above fails to loop through all devices. It is * probably a compiler bug. */ - for (i=0; i < changer->device->size(); i++) { + for (int i=0; i < changer->device->size(); i++) { device = (DEVRES *)changer->device->get(i); dev = device->dev; if (!dev) { @@ -755,7 +754,7 @@ void edit_device_codes(DCR *dcr, POOLMEM **omsg, const char *imsg, const char *c str = NPRT(dcr->device->control_name); break; case 'd': - sprintf(add, "%d", dcr->dev->drive_index); + sprintf(add, "%u", dcr->dev->drive_index); str = add; break; case 'o': diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index b2d7eb2af..194e3a127 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -319,7 +319,7 @@ static bool sd_testnetwork_cmd(JCR *jcr) if (scan_string(fd->msg, "testnetwork bytes=%lld rtt=%lld bw=%lld", &nb, &nbrtt, &bandwidth) != 3) { if (scan_string(fd->msg, "testnetwork bytes=%lld", &nb) != 1) { - Dmsg1(0, "Invalid command %s\n", fd->msg); + Dmsg1(50, "Invalid command %s\n", fd->msg); return false; } } diff --git a/bacula/src/stored/prepare.h b/bacula/src/stored/prepare.h index 0d24ecfd6..c710f87c8 100644 --- a/bacula/src/stored/prepare.h +++ b/bacula/src/stored/prepare.h @@ -79,6 +79,8 @@ public: working(NULL), statp(), /* will be zero initialized */ xtrabackupconf(NULL), + backup_binary(NULL), + stream_binary(NULL), bpipe(NULL) { };