]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix warnings reported by cppcheck
authorEric Bollengier <eric@baculasystems.com>
Wed, 5 Oct 2022 13:06:06 +0000 (15:06 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
 - 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

20 files changed:
bacula/src/console/authenticate.c
bacula/src/console/bbconsjson.c
bacula/src/console/console.c
bacula/src/dird/bdirjson.c
bacula/src/dird/malware.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_dotcmds.c
bacula/src/dird/ua_purge.c
bacula/src/dird/ua_tree.c
bacula/src/filed/bfdjson.c
bacula/src/filed/fd_snapshot.c
bacula/src/filed/job.c
bacula/src/filed/restore.c
bacula/src/lib/bsys.c
bacula/src/lib/events.c
bacula/src/lib/runscript.c
bacula/src/stored/ansi_label.c
bacula/src/stored/autochanger.c
bacula/src/stored/fd_cmds.c
bacula/src/stored/prepare.h

index d568a33d13855844d340e596a1f66ccdd92a6c25..f4f7341f92cf97de9cf0b06f99d8d416a8051e21 100644 (file)
@@ -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 {
index 088cfa9c059df5821785421da1299c3f04c4c691..33f1acdc36d23ecc358a02c98f5aaeaa63076f43 100644 (file)
@@ -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;
          }
 
index e0a8c183b756dbd9e9628e89c3adb3186997bce2..7d15a4822c20738b11263222a0161e4b205d96d3 100644 (file)
@@ -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; i<item; i++) {
          dir = (DIRRES *)GetNextRes(R_DIRECTOR, (RES *)dir);
@@ -1130,6 +1127,8 @@ int main(int argc, char *argv[])
    bool test_config = false;
    utime_t heart_beat;
    bool avoid_getpass = false;
+   DIRRES *dir = NULL;
+   CONRES *cons = NULL;
 
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
@@ -1473,10 +1472,10 @@ static int check_resources()
    bool OK = true;
    DIRRES *director;
    bool tls_needed;
+   int numdir = 0;
 
    LockRes();
 
-   numdir = 0;
    foreach_res(director, R_DIRECTOR) {
 
       numdir++;
@@ -1785,7 +1784,6 @@ static int sleepcmd(FILE *input, BSOCK *UA_sock)
  */
 static int putfilecmd(FILE *input, BSOCK *UA_sock)
 {
-   int i = 0;
    const char *key = "putfile";
    const char *fname;
    FILE *fp;
@@ -1814,7 +1812,7 @@ static int putfilecmd(FILE *input, BSOCK *UA_sock)
 
    /* Just read the file and send it to the director */
    while (!feof(fp)) {
-      i = fread(UA_sock->msg, 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;
index 5fe97f8a16d2fbdcb95423c668928fb1f14f9821..0654609c787bd364c8dfe74786584c0317ca4b56 100644 (file)
@@ -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;
          }
 
index 3430935dc520e0cd250108a4c4bde303acced4ea..69fd8f47a936e6b7b20c935aed3a2f9970f59312 100644 (file)
@@ -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;
    }
 }
index 8d7c31f48f501b2ae2d289860bc0e4b452d5ab14..c3810efd010226d60a0ac8086b68c82d8311ee9b 100644 (file)
@@ -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));
index 6cb83f05559a5b7b5334d21b7b3944b579a2c85b..99d261290a2614958d0ac8e17aebfec21c03ec7a 100644 (file)
@@ -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; i<ua->argc; i++) {
       if (fnid && strcasecmp(ua->argk[i], NT_("fnid")) == 0) {
index fb1a0fd2fb3a7f42d0e014b0e8177add0e84210f..075378c2ce0c10f6a1d574351597a4b2f6353c44 100644 (file)
@@ -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);
       }
    }
 
index d306317968c86896f61bab1fccc1018d4b82f922..5b2e224af6c671f37bc9cd6c9f10ae7f197e2a5f 100644 (file)
@@ -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;
index ed3bf962f61199f5f09181a5c22da768b6e8162a..55519dce32416f763f62a3e2a4e695b0fe692784 100644 (file)
@@ -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;
          }
 
index e393845781f30afff5cf759d99316a854d807dc1..b990f847c1f8016c177272b24dfe5a510eeee873 100644 (file)
@@ -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]);
          }
       }
 
index 25800af591e57adb9f1c46e89f712bd91b7600e2..8d9917d63578f78ec9a684f4025b7db7c0cf7d85 100644 (file)
@@ -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:
index 057350fa9b1535b311e45aebefe12beb62bb8e63..6dc552de4f91bbc8a2cd551f7ab73001ec0e5863 100644 (file)
@@ -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) */
 
index 1f01a0d9aa7cd5c08ff40bbf1f5a728f47c35106..19f7a9d70e9591a68b1707d646776da590b770fe 100644 (file)
@@ -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! */
index fb0e4e38a968a67b07f28a5df74addfcd382b96a..29bbd74d947916fc7dc34b16ae277ba3fd35f829 100644 (file)
@@ -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);
index 4e8d1ae1f3cb292d35e80d78b2eafd724edc44c0..22e5b6a6a4fc8de587495c1e37053745f082f33d 100644 (file)
@@ -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 &&
index 48f1c03f032e2ed65a757a84ddc2e6d2fff37ff4..b05fa04831a0fc543a5a782a57de5c80d92b97f2 100644 (file)
@@ -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;
index c1002e1f4fa0daa9a480f3134f7cf232a773cd14..da0cc65c3d90d493a5424050ed6270f144e4e01b 100644 (file)
@@ -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':
index b2d7eb2af31a3605e838be38c0dfa5001ea7ff38..194e3a127ffca56038485d6f25c18b265bfbf4c5 100644 (file)
@@ -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;
       }
    }
index 0d24ecfd6de57176b46f37b8dfe41a8ce28d0c3a..c710f87c8c1c848444120fb0bb34b114cd6ab109 100644 (file)
@@ -79,6 +79,8 @@ public:
       working(NULL),
       statp(),                  /* will be zero initialized */
       xtrabackupconf(NULL),
+      backup_binary(NULL),
+      stream_binary(NULL),
       bpipe(NULL)
       {
       };