Fix gcc uninitialized variable warnings
authorBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 26 Aug 2010 16:58:04 +0000 (09:58 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 31 Aug 2010 15:38:43 +0000 (08:38 -0700)
Gcc -Wall warn: 'uninitialized variable'

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
24 files changed:
cmd/zdb/zdb.c
cmd/zfs/zfs_main.c
cmd/zpool/zpool_main.c
cmd/zpool/zpool_vdev.c
lib/libzfs/libzfs_dataset.c
lib/libzfs/libzfs_import.c
lib/libzfs/libzfs_util.c
module/nvpair/nvpair.c
module/zfs/arc.c
module/zfs/dmu.c
module/zfs/dmu_objset.c
module/zfs/dsl_dataset.c
module/zfs/lzjb.c
module/zfs/refcount.c
module/zfs/sa.c
module/zfs/spa.c
module/zfs/spa_misc.c
module/zfs/vdev_file.c
module/zfs/vdev_label.c
module/zfs/vdev_raidz.c
module/zfs/zap_leaf.c
module/zfs/zfs_byteswap.c
module/zfs/zfs_rlock.c
module/zfs/zil.c

index 1a458f6..459445b 100644 (file)
@@ -2888,7 +2888,7 @@ find_zpool(char **target, nvlist_t **configp, int dirc, char **dirv)
        nvlist_t *match = NULL;
        char *name = NULL;
        char *sepp = NULL;
-       char sep;
+       char sep = 0;
        int count = 0;
        importargs_t args = { 0 };
 
index 22426eb..9cb69c1 100644 (file)
@@ -671,7 +671,7 @@ zfs_do_create(int argc, char **argv)
 {
        zfs_type_t type = ZFS_TYPE_FILESYSTEM;
        zfs_handle_t *zhp = NULL;
-       uint64_t volsize;
+       uint64_t volsize = 0;
        int c;
        boolean_t noreserve = B_FALSE;
        boolean_t bflag = B_FALSE;
@@ -4060,7 +4060,7 @@ int
 main(int argc, char **argv)
 {
        int ret;
-       int i;
+       int i = 0;
        char *progname;
        char *cmdname;
 
@@ -4139,6 +4139,7 @@ main(int argc, char **argv)
                        (void) fprintf(stderr, gettext("unrecognized "
                            "command '%s'\n"), cmdname);
                        usage(B_FALSE);
+                       ret = 1;
                }
                libzfs_mnttab_cache(g_zfs, B_FALSE);
        }
index 85a51de..fa16836 100644 (file)
@@ -3269,7 +3269,7 @@ print_scan_status(pool_scan_stat_t *ps)
         */
        if (ps->pss_state == DSS_FINISHED) {
                uint64_t minutes_taken = (end - start) / 60;
-               char *fmt;
+               char *fmt = NULL;
 
                if (ps->pss_func == POOL_SCAN_SCRUB) {
                        fmt = gettext("scrub repaired %s in %lluh%um with "
@@ -4392,7 +4392,7 @@ int
 main(int argc, char **argv)
 {
        int ret;
-       int i;
+       int i = 0;
        char *cmdname;
 
        (void) setlocale(LC_ALL, "");
@@ -4450,6 +4450,7 @@ main(int argc, char **argv)
                (void) fprintf(stderr, gettext("unrecognized "
                    "command '%s'\n"), cmdname);
                usage(B_FALSE);
+               ret = 1;
        }
 
        libzfs_fini(g_zfs);
index 53c2e60..0c22490 100644 (file)
@@ -548,7 +548,7 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
        uint_t c, children;
        nvlist_t *nv;
        char *type;
-       replication_level_t lastrep, rep, *ret;
+       replication_level_t lastrep = { 0 }, rep, *ret;
        boolean_t dontreport;
 
        ret = safe_malloc(sizeof (replication_level_t));
index 32cdd63..a0146b4 100644 (file)
@@ -1362,7 +1362,7 @@ zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
        zfs_prop_t prop;
        boolean_t do_prefix;
        uint64_t idx;
-       int added_resv;
+       int added_resv = 0;
 
        (void) snprintf(errbuf, sizeof (errbuf),
            dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
@@ -2791,7 +2791,7 @@ zfs_create_ancestors(libzfs_handle_t *hdl, const char *path)
 {
        int prefix;
        char *path_copy;
-       int rc;
+       int rc = 0;
 
        if (check_parents(hdl, path, NULL, B_TRUE, &prefix) != 0)
                return (-1);
@@ -3348,8 +3348,8 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
        int err;
        zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 };
        boolean_t restore_resv = 0;
-       uint64_t old_volsize, new_volsize;
-       zfs_prop_t resv_prop;
+       uint64_t old_volsize = 0, new_volsize;
+       zfs_prop_t resv_prop = { 0 };
 
        assert(zhp->zfs_type == ZFS_TYPE_FILESYSTEM ||
            zhp->zfs_type == ZFS_TYPE_VOLUME);
@@ -3579,6 +3579,7 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive)
                            "child dataset with inherited mountpoint is used "
                            "in a non-global zone"));
                        (void) zfs_error(hdl, EZFS_ZONED, errbuf);
+                       ret = -1;
                        goto error;
                }
 
index 9629ab0..386ab00 100644 (file)
@@ -434,7 +434,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok)
        pool_entry_t *pe;
        vdev_entry_t *ve;
        config_entry_t *ce;
-       nvlist_t *ret = NULL, *config = NULL, *tmp, *nvtop, *nvroot;
+       nvlist_t *ret = NULL, *config = NULL, *tmp = NULL, *nvtop, *nvroot;
        nvlist_t **spares, **l2cache;
        uint_t i, nspares, nl2cache;
        boolean_t config_seen;
index fbed42f..8277bdb 100644 (file)
@@ -956,7 +956,7 @@ zprop_print_one_property(const char *name, zprop_get_cbdata_t *cbp,
     const char *source, const char *recvd_value)
 {
        int i;
-       const char *str;
+       const char *str = NULL;
        char buf[128];
 
        /*
index c675684..282e0f8 100644 (file)
@@ -1611,10 +1611,10 @@ nvlist_lookup_nvpair_ei_sep(nvlist_t *nvl, const char *name, const char sep,
 {
        nvpair_t        *nvp;
        const char      *np;
-       char            *sepp;
+       char            *sepp=NULL;
        char            *idxp, *idxep;
        nvlist_t        **nva;
-       long            idx;
+       long            idx = 0;
        int             n;
 
        if (ip)
index 96c3fb7..1d7fd9e 100644 (file)
@@ -2678,7 +2678,7 @@ arc_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bp,
     uint32_t *arc_flags, const zbookmark_t *zb)
 {
        arc_buf_hdr_t *hdr;
-       arc_buf_t *buf;
+       arc_buf_t *buf = NULL;
        kmutex_t *hash_lock;
        zio_t *rzio;
        uint64_t guid = spa_guid(spa);
@@ -2760,7 +2760,7 @@ top:
                uint64_t size = BP_GET_LSIZE(bp);
                arc_callback_t  *acb;
                vdev_t *vd = NULL;
-               uint64_t addr;
+               daddr_t addr = -1;
                boolean_t devw = B_FALSE;
 
                if (hdr == NULL) {
@@ -3038,7 +3038,7 @@ arc_release(arc_buf_t *buf, void *tag)
        arc_buf_hdr_t *hdr;
        kmutex_t *hash_lock = NULL;
        l2arc_buf_hdr_t *l2hdr;
-       uint64_t buf_size;
+       uint64_t buf_size = 0;
 
        /*
         * It would be nice to assert that if it's DMU metadata (level >
@@ -4062,7 +4062,7 @@ l2arc_read_done(zio_t *zio)
 static list_t *
 l2arc_list_locked(int list_num, kmutex_t **lock)
 {
-       list_t *list;
+       list_t *list = NULL;
 
        ASSERT(list_num >= 0 && list_num <= 3);
 
@@ -4235,7 +4235,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
        list_t *list;
        uint64_t passed_sz, write_sz, buf_sz, headroom;
        void *buf_data;
-       kmutex_t *hash_lock, *list_lock;
+       kmutex_t *hash_lock, *list_lock = NULL;
        boolean_t have_lock, full;
        l2arc_write_callback_t *cb;
        zio_t *pio, *wzio;
index f2b3f2b..732742f 100644 (file)
@@ -355,7 +355,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
        uint32_t dbuf_flags;
        int err;
        zio_t *zio;
-       hrtime_t start;
+       hrtime_t start = 0;
 
        ASSERT(length <= DMU_MAX_ACCESS);
 
index b3a8302..2d06897 100644 (file)
@@ -1331,7 +1331,7 @@ dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx)
        objset_t *os = dn->dn_objset;
        void *data = NULL;
        dmu_buf_impl_t *db = NULL;
-       uint64_t *user, *group;
+       uint64_t *user = NULL, *group = NULL;
        int flags = dn->dn_id_flags;
        int error;
        boolean_t have_spill = B_FALSE;
index 34fd758..226e988 100644 (file)
@@ -387,7 +387,7 @@ dsl_dataset_get_ref(dsl_pool_t *dp, uint64_t dsobj, void *tag,
 
        ds = dmu_buf_get_user(dbuf);
        if (ds == NULL) {
-               dsl_dataset_t *winner;
+               dsl_dataset_t *winner = NULL;
 
                ds = kmem_zalloc(sizeof (dsl_dataset_t), KM_SLEEP);
                ds->ds_dbuf = dbuf;
index ab3de51..ad9e423 100644 (file)
@@ -50,7 +50,7 @@ lzjb_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
 {
        uchar_t *src = s_start;
        uchar_t *dst = d_start;
-       uchar_t *cpy, *copymap;
+       uchar_t *cpy, *copymap = NULL;
        int copymask = 1 << (NBBY - 1);
        int mlen, offset, hash;
        uint16_t *hp;
@@ -99,7 +99,7 @@ lzjb_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
        uchar_t *src = s_start;
        uchar_t *dst = d_start;
        uchar_t *d_end = (uchar_t *)d_start + d_len;
-       uchar_t *cpy, copymap;
+       uchar_t *cpy, copymap = 0;
        int copymask = 1 << (NBBY - 1);
 
        while (dst < d_end) {
index a659c07..a615546 100644 (file)
@@ -110,7 +110,7 @@ refcount_count(refcount_t *rc)
 int64_t
 refcount_add_many(refcount_t *rc, uint64_t number, void *holder)
 {
-       reference_t *ref;
+       reference_t *ref = NULL;
        int64_t count;
 
        if (reference_tracking_enable) {
index 4e71c40..37b815f 100644 (file)
@@ -642,7 +642,7 @@ sa_build_layouts(sa_handle_t *hdl, sa_bulk_attr_t *attr_desc, int attr_count,
        int buf_space;
        sa_attr_type_t *attrs, *attrs_start;
        int i, lot_count;
-       int hdrsize, spillhdrsize;
+       int hdrsize, spillhdrsize = 0;
        int used;
        dmu_object_type_t bonustype;
        sa_lot_t *lot;
@@ -813,7 +813,7 @@ sa_attr_table_setup(objset_t *os, sa_attr_reg_t *reg_attrs, int count)
 {
        sa_os_t *sa = os->os_sa;
        uint64_t sa_attr_count = 0;
-       uint64_t sa_reg_count;
+       uint64_t sa_reg_count = 0;
        int error = 0;
        uint64_t attr_value;
        sa_attr_table_t *tb;
@@ -1619,7 +1619,7 @@ sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
        sa_bulk_attr_t *attr_desc;
        void *old_data[2];
        int bonus_attr_count = 0;
-       int bonus_data_size, spill_data_size;
+       int bonus_data_size = 0, spill_data_size = 0;
        int spill_attr_count = 0;
        int error;
        uint16_t length;
index 0711102..d11f93d 100644 (file)
@@ -334,7 +334,7 @@ spa_prop_validate(spa_t *spa, nvlist_t *props)
 {
        nvpair_t *elem;
        int error = 0, reset_bootfs = 0;
-       uint64_t objnum;
+       uint64_t objnum = 0;
 
        elem = NULL;
        while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
@@ -1144,7 +1144,7 @@ spa_load_l2cache(spa_t *spa)
        uint_t nl2cache;
        int i, j, oldnvdevs;
        uint64_t guid;
-       vdev_t *vd, **oldvdevs, **newvdevs;
+       vdev_t *vd, **oldvdevs, **newvdevs = NULL;
        spa_aux_vdev_t *sav = &spa->spa_l2cache;
 
        ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
@@ -4019,7 +4019,7 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
        ASSERTV(vdev_t *rvd = spa->spa_root_vdev;)
        vdev_t *vd, *pvd, *cvd, *tvd;
        boolean_t unspare = B_FALSE;
-       uint64_t unspare_guid;
+       uint64_t unspare_guid = 0;
        char *vdpath;
        int c, t;
 
index cd8a6c8..32ef51d 100644 (file)
@@ -399,7 +399,7 @@ spa_lookup(const char *name)
        static spa_t search;    /* spa_t is large; don't allocate on stack */
        spa_t *spa;
        avl_index_t where;
-       char c;
+       char c = 0;
        char *cp;
 
        ASSERT(MUTEX_HELD(&spa_namespace_lock));
index 8c22aa5..f31389a 100644 (file)
@@ -143,7 +143,7 @@ vdev_file_io_start(zio_t *zio)
 {
        vdev_t *vd = zio->io_vd;
        vdev_file_t *vf = vd->vdev_tsd;
-       ssize_t resid;
+       ssize_t resid = 0;
 
        if (zio->io_type == ZIO_TYPE_IOCTL) {
                /* XXPOLICY */
index 8b40087..3774d71 100644 (file)
@@ -612,7 +612,7 @@ vdev_label_init(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason)
        char *buf;
        size_t buflen;
        int error;
-       uint64_t spare_guid, l2cache_guid;
+       uint64_t spare_guid = 0, l2cache_guid = 0;
        int flags = ZIO_FLAG_CONFIG_WRITER | ZIO_FLAG_CANFAIL;
        int c, l;
        vdev_t *pvd;
index af2de40..ef20542 100644 (file)
@@ -1189,7 +1189,7 @@ vdev_raidz_matrix_reconstruct(raidz_map_t *rm, int n, int nmissing,
        uint64_t ccount;
        uint8_t *dst[VDEV_RAIDZ_MAXPARITY];
        uint64_t dcount[VDEV_RAIDZ_MAXPARITY];
-       uint8_t log, val;
+       uint8_t log = 0, val;
        int ll;
        uint8_t *invlog[VDEV_RAIDZ_MAXPARITY];
        uint8_t *p, *pp;
@@ -1638,8 +1638,11 @@ raidz_checksum_verify(zio_t *zio)
 {
        zio_bad_cksum_t zbc;
        raidz_map_t *rm = zio->io_vsd;
+       int ret;
 
-       int ret = zio_checksum_error(zio, &zbc);
+       bzero(&zbc, sizeof (zio_bad_cksum_t));
+
+       ret = zio_checksum_error(zio, &zbc);
        if (ret != 0 && zbc.zbc_injected != 0)
                rm->rm_ecksuminjected = 1;
 
@@ -1862,7 +1865,7 @@ vdev_raidz_io_done(zio_t *zio)
        vdev_t *vd = zio->io_vd;
        vdev_t *cvd;
        raidz_map_t *rm = zio->io_vsd;
-       raidz_col_t *rc;
+       raidz_col_t *rc = NULL;
        int unexpected_errors = 0;
        int parity_errors = 0;
        int parity_untried = 0;
index 19a795d..b867ac4 100644 (file)
@@ -220,7 +220,7 @@ zap_leaf_array_create(zap_leaf_t *l, const char *buf,
        uint16_t chunk_head;
        uint16_t *chunkp = &chunk_head;
        int byten = 0;
-       uint64_t value;
+       uint64_t value = 0;
        int shift = (integer_size-1)*8;
        int len = num_integers;
 
index acf632b..6048eb1 100644 (file)
@@ -51,7 +51,7 @@ zfs_ace_byteswap(void *buf, size_t size, boolean_t zfs_layout)
 {
        caddr_t end;
        caddr_t ptr;
-       zfs_ace_t *zacep;
+       zfs_ace_t *zacep = NULL;
        ace_t *acep;
        uint16_t entry_type;
        size_t entry_size;
index 7fd8f60..4e3c176 100644 (file)
@@ -460,7 +460,7 @@ static void
 zfs_range_unlock_reader(znode_t *zp, rl_t *remove)
 {
        avl_tree_t *tree = &zp->z_range_avl;
-       rl_t *rl, *next;
+       rl_t *rl, *next = NULL;
        uint64_t len;
 
        /*
index 751806d..3c18d43 100644 (file)
@@ -296,6 +296,8 @@ zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
        char *lrbuf, *lrp;
        int error = 0;
 
+       bzero(&next_blk, sizeof(blkptr_t));
+
        /*
         * Old logs didn't record the maximum zh_claim_lr_seq.
         */
@@ -317,7 +319,7 @@ zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
        for (blk = zh->zh_log; !BP_IS_HOLE(&blk); blk = next_blk) {
                uint64_t blk_seq = blk.blk_cksum.zc_word[ZIL_ZC_SEQ];
                int reclen;
-               char *end;
+               char *end = NULL;
 
                if (blk_seq > claim_blk_seq)
                        break;