]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: fix reassigned values before old ones has been used [cppcheck]
authorSami Kerola <kerolasa@iki.fi>
Sun, 28 May 2017 09:21:48 +0000 (10:21 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 14 Jun 2017 10:19:20 +0000 (12:19 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
17 files changed:
disk-utils/cfdisk.c
libblkid/src/devno.c
libblkid/src/probe.c
libfdisk/src/gpt.c
libfdisk/src/script.c
libmount/src/btrfs.c
libmount/src/cache.c
libmount/src/context.c
libmount/src/context_umount.c
libmount/src/optstr.c
libmount/src/tab_diff.c
libmount/src/tab_update.c
libsmartcols/src/column.c
misc-utils/findmnt-verify.c
misc-utils/findmnt.c
sys-utils/losetup.c
sys-utils/swapon.c

index 37f998babb742dea1e7200b89fd97da683481373..efff1b8252fc7264ba344b41ba58af4e5656ed8a 100644 (file)
@@ -323,7 +323,7 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
 {
        struct fdisk_partition *pa;
        struct fdisk_label *lb;
-       struct fdisk_iter *itr = NULL;
+       struct fdisk_iter *itr;
        struct libscols_table *table = NULL;
        struct libscols_iter *s_itr = NULL;
        char *res = NULL;
index 71eb4a5334e402f420f199f9dc04149550a00451..8882cddad8818d9862721d49fff80ac3319bfacd 100644 (file)
@@ -225,7 +225,7 @@ static char *scandev_devno_to_devpath(dev_t devno)
  */
 char *blkid_devno_to_devname(dev_t devno)
 {
-       char *path = NULL;
+       char *path;
        char buf[PATH_MAX];
 
        path = sysfs_devno_to_devpath(devno, buf, sizeof(buf));
index 7eaceac6d99a348c918f345165d515563877314f..77c46ccccc4158c00b5ffd117dac88fbb7fefbf7 100644 (file)
@@ -206,7 +206,7 @@ blkid_probe blkid_clone_probe(blkid_probe parent)
  */
 blkid_probe blkid_new_probe_from_filename(const char *filename)
 {
-       int fd = -1;
+       int fd;
        blkid_probe pr = NULL;
 
        fd = open(filename, O_RDONLY|O_CLOEXEC);
index d18d4cab430cd432a59d07093583e99a38655d8f..40d0912ecf81490483a7f044be03e8d58a8e6a60 100644 (file)
@@ -1925,7 +1925,7 @@ fail:
 static int gpt_write_pmbr(struct fdisk_context *cxt)
 {
        off_t offset;
-       struct gpt_legacy_mbr *pmbr = NULL;
+       struct gpt_legacy_mbr *pmbr;
 
        assert(cxt);
        assert(cxt->firstsector);
index 198e9edb91b0e19e915911586f2c236b0861b031..be325bc09b7a93cd4267ac3c659710aac84b947a 100644 (file)
@@ -1528,7 +1528,7 @@ static int test_apply(struct fdisk_test *ts, int argc, char *argv[])
 {
        char *devname = argv[1], *scriptname = argv[2];
        struct fdisk_context *cxt;
-       struct fdisk_script *dp = NULL;
+       struct fdisk_script *dp;
        struct fdisk_table *tb = NULL;
        struct fdisk_iter *itr = NULL;
        struct fdisk_partition *pa = NULL;
index c387fadd52ac7954664fc581986291c7f0707c92..e6e8aebff061474689d2c1126f4996768f1d75e3 100644 (file)
@@ -101,7 +101,7 @@ uint64_t btrfs_get_default_subvol_id(const char *path)
 {
        int iocret;
        int fd;
-       DIR *dirstream = NULL;
+       DIR *dirstream;
        struct btrfs_ioctl_search_args args;
        struct btrfs_ioctl_search_key *sk = &args.key;
        struct btrfs_ioctl_search_header *sh;
index 6ff997140e06500d6b6b26bbb6991fb844a652a3..b52ca809801a9ca1f7fe2c485b978b1ea91287b8 100644 (file)
@@ -489,9 +489,9 @@ char *mnt_get_fstype(const char *devname, int *ambi, struct libmnt_cache *cache)
 static char *canonicalize_path_and_cache(const char *path,
                                                struct libmnt_cache *cache)
 {
-       char *p = NULL;
-       char *key = NULL;
-       char *value = NULL;
+       char *p;
+       char *key;
+       char *value;
 
        DBG(CACHE, ul_debugobj(cache, "canonicalize path %s", path));
        p = canonicalize_path(path);
index 5725ab1ad78ff3150d7003cf951768ef6c8c3828..fdbb025857771766dd3d5daf6d99d0bf738767e8 100644 (file)
@@ -1965,7 +1965,7 @@ static int apply_table(struct libmnt_context *cxt, struct libmnt_table *tb,
                     int direction)
 {
        struct libmnt_fs *fs = NULL;
-       const char *src = NULL, *tgt = NULL;
+       const char *src, *tgt;
        int rc;
 
        assert(cxt);
index e0b7bda112bad410c1f6fa71c246cdcc27294cf9..37fdf26680e67296f397832759850c6286efe2c8 100644 (file)
@@ -485,7 +485,7 @@ static int evaluate_permissions(struct libmnt_context *cxt)
         */
        if (u_flags & (MNT_MS_USER | MNT_MS_OWNER | MNT_MS_GROUP)) {
 
-               char *curr_user = NULL;
+               char *curr_user;
                char *mtab_user = NULL;
                size_t sz;
 
index 4b9622ed5a113b3d3655779b19f9c8c645280dee..8248f0dee8c26245691c7c87e953336195c8b869 100644 (file)
@@ -382,7 +382,7 @@ insert_value(char **str, char *pos, const char *substr, char **next)
        size_t strsz = strlen(*str);
        size_t possz = strlen(pos);
        size_t posoff;
-       char *p = NULL;
+       char *p;
        int sep;
 
        /* is it necessary to prepend '=' before the substring ? */
index 7cf9e57ef769c1f5924f511408e67943f19fac2f..6caaa2a2d1dd11643e7c8ccd4aeaceca05806e5e 100644 (file)
@@ -305,8 +305,8 @@ done:
 
 static int test_diff(struct libmnt_test *ts, int argc, char *argv[])
 {
-       struct libmnt_table *tb_old = NULL, *tb_new = NULL;
-       struct libmnt_tabdiff *diff = NULL;
+       struct libmnt_table *tb_old, *tb_new;
+       struct libmnt_tabdiff *diff;
        struct libmnt_iter *itr;
        struct libmnt_fs *old, *new;
        int rc = -1, change;
index d85cb89da5636bab1085ea787a4ae4ba5e174e03..52e1dd4443460251a2163bdf0d25d4d8a06134f7 100644 (file)
@@ -291,7 +291,7 @@ static int utab_new_entry(struct libmnt_update *upd, struct libmnt_fs *fs,
                          unsigned long mountflags)
 {
        int rc = 0;
-       const char *o = NULL, *a = NULL;
+       const char *o, *a;
        char *u = NULL;
 
        assert(fs);
index 1d32879603652683651ece19ba3595ef600f3729..ce1ed7e220e07b4c5079eb70fce900d24db09b34 100644 (file)
@@ -293,7 +293,7 @@ size_t scols_wrapnl_chunksize(const struct libscols_column *cl __attribute__((un
        size_t sum = 0;
 
        while (data && *data) {
-               const char *p = data;
+               const char *p;
                size_t sz;
 
                p = strchr(data, '\n');
index e3fb391d4e463c90235d258f537f80d9830cd3fc..b32901d6631813306c6c29ff63527e8ad03758ab 100644 (file)
@@ -472,7 +472,7 @@ static int verify_filesystem(struct verify_context *vfy)
 int verify_table(struct libmnt_table *tb)
 {
        struct verify_context vfy = { .nerrors = 0 };
-       struct libmnt_iter *itr = NULL;
+       struct libmnt_iter *itr;
        int rc = 0;             /* overall return code (alloc errors, etc.) */
        int check_order = is_listall_mode();
        static int has_read_fs = 0;
index 86b6b9aa1d00d08c349e17db1f1e59348e0accec..93c0e90efb881105e3020d59c056ad7fce585008 100644 (file)
@@ -873,7 +873,7 @@ static void cache_set_targets(struct libmnt_cache *tmp)
 static int tab_is_tree(struct libmnt_table *tb)
 {
        struct libmnt_fs *fs = NULL;
-       struct libmnt_iter *itr = NULL;
+       struct libmnt_iter *itr;
        int rc = 0;
 
        itr = mnt_new_iter(MNT_ITER_BACKWARD);
@@ -892,7 +892,7 @@ static int tab_is_tree(struct libmnt_table *tb)
 static int tab_is_kernel(struct libmnt_table *tb)
 {
        struct libmnt_fs *fs = NULL;
-       struct libmnt_iter *itr = NULL;
+       struct libmnt_iter *itr;
 
        itr = mnt_new_iter(MNT_ITER_BACKWARD);
        if (!itr)
@@ -1008,7 +1008,7 @@ again:
 static int add_matching_lines(struct libmnt_table *tb,
                              struct libscols_table *table, int direction)
 {
-       struct libmnt_iter *itr = NULL;
+       struct libmnt_iter *itr;
        struct libmnt_fs *fs;
        int nlines = 0, rc = -1;
 
@@ -1068,7 +1068,7 @@ static int poll_table(struct libmnt_table *tb, const char *tabfile,
        FILE *f = NULL;
        int rc = -1;
        struct libmnt_iter *itr = NULL;
-       struct libmnt_table *tb_new = NULL;
+       struct libmnt_table *tb_new;
        struct libmnt_tabdiff *diff = NULL;
        struct pollfd fds[1];
 
index 8a9bdf55d3da9601985bdc4d6147cd2748a3caa1..e0676c9fd67d80e023759f2d2b31fc4b764ac609 100644 (file)
@@ -113,7 +113,7 @@ static int printf_loopdev(struct loopdev_cxt *lc)
        uint64_t x;
        dev_t dev = 0;
        ino_t ino = 0;
-       char *fname = NULL;
+       char *fname;
        uint32_t type;
 
        fname = loopcxt_get_backing_file(lc);
index f4ca781d8da46fbc7c33691df4775763d5c61162..6bd057dd2f24e44764a0c942e5e6ded868a69c22 100644 (file)
@@ -501,7 +501,7 @@ static void swap_get_info(struct swap_device *dev, const char *hdr)
 static int swapon_checks(const struct swapon_ctl *ctl, struct swap_device *dev)
 {
        struct stat st;
-       int fd = -1, sig;
+       int fd, sig;
        char *hdr = NULL;
        unsigned long long devsize = 0;
        int permMask;