From 4813a5210f6fb979d8f7a592f71a2f9c4d3db179 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 9 Feb 2019 09:34:52 +0000 Subject: various: fix 'uninitialized when used' warnings [clang] This change fixes "warning: variable 'var' may be uninitialized when used here [-Wconditional-uninitialized]" warnings reported in various files. Signed-off-by: Sami Kerola --- disk-utils/mkfs.minix.c | 2 +- disk-utils/sfdisk.c | 2 +- libblkid/src/partitions/dos.c | 2 +- libblkid/src/partitions/partitions.c | 2 +- libblkid/src/superblocks/ddf_raid.c | 2 +- libblkid/src/superblocks/hfs.c | 2 +- libblkid/src/superblocks/zfs.c | 2 +- libfdisk/src/dos.c | 2 +- libfdisk/src/table.c | 2 +- misc-utils/logger.c | 2 +- misc-utils/uuidd.c | 3 ++- misc-utils/uuidparse.c | 2 +- sys-utils/hwclock.c | 2 +- sys-utils/readprofile.c | 2 +- sys-utils/setarch.c | 2 +- 15 files changed, 16 insertions(+), 15 deletions(-) diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c index 54c47da7e..8e6811f49 100644 --- a/disk-utils/mkfs.minix.c +++ b/disk-utils/mkfs.minix.c @@ -685,7 +685,7 @@ static int find_super_magic(const struct fs_control *ctl) static void determine_device_blocks(struct fs_control *ctl, const struct stat *statbuf) { - unsigned long long dev_blocks; + unsigned long long dev_blocks = 0; if (S_ISBLK(statbuf->st_mode)) { int sectorsize; diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 52ccc5251..2427cef5b 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -1724,7 +1724,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) nparts = fdisk_table_get_nents(tb); if (nparts) { - size_t cur_partno; + size_t cur_partno = (size_t) -1; struct fdisk_partition *pa = fdisk_table_get_partition(tb, nparts - 1); assert(pa); diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c index 659ca9a16..6c1b519f7 100644 --- a/libblkid/src/partitions/dos.c +++ b/libblkid/src/partitions/dos.c @@ -55,7 +55,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab, while (1) { struct dos_partition *p, *p0; - uint32_t start, size; + uint32_t start = 0, size; if (++ct_nodata > 100) return BLKID_PROBE_OK; diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c index b5f393b99..299454765 100644 --- a/libblkid/src/partitions/partitions.c +++ b/libblkid/src/partitions/partitions.c @@ -1010,7 +1010,7 @@ blkid_partition blkid_partlist_get_partition_by_partno(blkid_partlist ls, int n) blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno) { struct path_cxt *pc; - uint64_t start, size; + uint64_t start = 0, size; int i, rc, partno = 0; DBG(LOWPROBE, ul_debug("trying to convert devno 0x%llx to partition", diff --git a/libblkid/src/superblocks/ddf_raid.c b/libblkid/src/superblocks/ddf_raid.c index fc2c39d3e..0b82e73eb 100644 --- a/libblkid/src/superblocks/ddf_raid.c +++ b/libblkid/src/superblocks/ddf_raid.c @@ -78,7 +78,7 @@ static int probe_ddf(blkid_probe pr, size_t i; struct ddf_header *ddf = NULL; char version[DDF_REV_LENGTH + 1]; - uint64_t off, lba; + uint64_t off = 0, lba; if (pr->size < 0x30000) return 1; diff --git a/libblkid/src/superblocks/hfs.c b/libblkid/src/superblocks/hfs.c index 7b0117405..6f170a3cd 100644 --- a/libblkid/src/superblocks/hfs.c +++ b/libblkid/src/superblocks/hfs.c @@ -191,7 +191,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag) unsigned int off = 0; unsigned int blocksize; unsigned int cat_block; - unsigned int ext_block_start; + unsigned int ext_block_start = 0; unsigned int ext_block_count; unsigned int record_count; unsigned int leaf_node_head; diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c index 1292b303b..4d4b46d55 100644 --- a/libblkid/src/superblocks/zfs.c +++ b/libblkid/src/superblocks/zfs.c @@ -218,7 +218,7 @@ static int probe_zfs(blkid_probe pr, const struct blkid_idmag *mag __attribute__((__unused__))) { int swab_endian = 0; - struct zfs_uberblock *ub; + struct zfs_uberblock *ub = NULL; loff_t offset = 0, ub_offset = 0; int label_no, found = 0, found_in_label; void *label; diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 2e46aca70..8e9678da3 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -1708,7 +1708,7 @@ static int dos_add_partition(struct fdisk_context *cxt, } else { char hint[BUFSIZ]; struct fdisk_ask *ask; - int c; + int c = 0; /* the default layout for scripts is to create primary partitions */ if (cxt->script || !fdisk_has_dialogs(cxt)) { diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index 99a669ca2..1f9d5a28a 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -728,7 +728,7 @@ int fdisk_diff_tables(struct fdisk_table *a, struct fdisk_table *b, struct fdisk_iter *itr, struct fdisk_partition **res, int *change) { - struct fdisk_partition *pa, *pb; + struct fdisk_partition *pa = NULL, *pb; int rc = 1; assert(itr); diff --git a/misc-utils/logger.c b/misc-utils/logger.c index 10b307ef9..394a477db 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -237,7 +237,7 @@ static int pencode(char *s) static int unix_socket(struct logger_ctl *ctl, const char *path, int *socket_type) { - int fd, i, type = -1; + int fd = -1, i, type = -1; static struct sockaddr_un s_addr; /* AF_UNIX address of local logger */ if (strlen(path) >= sizeof(s_addr.sun_path)) diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index e0be809dd..0382bac47 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -313,7 +313,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path, uuid_t uu; char reply_buf[1024], *cp; char op, str[UUID_STR_LEN]; - int i, ns, len, num; + int i, ns, len; + int num; /* intentionally uninitialized */ int s = 0; int fd_pidfile = -1; int ret; diff --git a/misc-utils/uuidparse.c b/misc-utils/uuidparse.c index 777f9db5e..6a13f2a2b 100644 --- a/misc-utils/uuidparse.c +++ b/misc-utils/uuidparse.c @@ -144,7 +144,7 @@ static void fill_table_row(struct libscols_table *tb, char const *const uuid) size_t i; uuid_t buf; int invalid = 0; - int variant, type; + int variant = -1, type = -1; assert(tb); assert(uuid); diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index d9acbaf7d..5f4c014fc 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -954,7 +954,7 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time, const struct timeval startup_time, struct adjtime *adjtime) { /* The time at which we read the Hardware Clock */ - struct timeval read_time; + struct timeval read_time = { 0 }; /* * The Hardware Clock gives us a valid time, or at * least something close enough to fool mktime(). diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c index 75a623bc9..ca0037529 100644 --- a/sys-utils/readprofile.c +++ b/sys-utils/readprofile.c @@ -136,7 +136,7 @@ int main(int argc, char **argv) unsigned long long add0 = 0; unsigned int step; unsigned int *buf, total, fn_len; - unsigned long long fn_add, next_add; /* current and next address */ + unsigned long long fn_add = 0, next_add; /* current and next address */ char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */ char mode[8]; int c; diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c index 703c36d86..31016f7f1 100644 --- a/sys-utils/setarch.c +++ b/sys-utils/setarch.c @@ -266,7 +266,7 @@ int main(int argc, char *argv[]) int verbose = 0; int archwrapper; int c; - struct arch_domain *doms, *target; + struct arch_domain *doms, *target = NULL; unsigned long pers_value = 0; char *shell = NULL, *shell_arg = NULL; -- cgit v1.2.3-55-g7522