Fix uninitialized variables, and use -O so gcc starts checking for them
authorChris Mason <chris.mason@oracle.com>
Thu, 1 May 2008 14:22:47 +0000 (10:22 -0400)
committerDavid Woodhouse <dwmw2@hera.kernel.org>
Thu, 1 May 2008 14:22:47 +0000 (10:22 -0400)
Gcc only sends warnings for uninitialized variables when you compile with -O,
and there were a couple of bugs sprinkled in the code.  The biggest was the
alloc_start variable for mkfs, which can cause strange things to happen.

(thanks to Gabor Micsko for helping to find this)

Makefile
btrfs-vol.c
mkfs.c
utils.c

index 7100852..287ce5a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 CC=gcc
 AM_CFLAGS = -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2
-CFLAGS = -g -Werror
+CFLAGS = -g -Werror -Os
 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
          root-tree.o dir-item.o hash.o file-item.o inode-item.o \
          inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \
index 0cc2e97..9eddd78 100644 (file)
@@ -71,9 +71,9 @@ int main(int ac, char **av)
        char *mnt = NULL;
        int ret;
        int option_index = 0;
-       int cmd;
+       int cmd = 0;
        int fd;
-       int devfd;
+       int devfd = 0;
        DIR *dirstream;
        struct btrfs_ioctl_vol_args args;
        u64 dev_block_count = 0;
diff --git a/mkfs.c b/mkfs.c
index c02627f..740cc81 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -308,7 +308,7 @@ int main(int ac, char **av)
        u64 block_count = 0;
        u64 dev_block_count = 0;
        u64 blocks[6];
-       u64 alloc_start;
+       u64 alloc_start = 0;
        u64 metadata_profile = BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP;
        u64 data_profile = BTRFS_BLOCK_GROUP_RAID0;
        u32 leafsize = getpagesize();
diff --git a/utils.c b/utils.c
index 2fa3c96..44a5dc6 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -645,7 +645,7 @@ int btrfs_register_one_device(char *fname)
 
 int btrfs_scan_one_dir(char *dirname, int run_ioctl)
 {
-       DIR *dirp;
+       DIR *dirp = NULL;
        struct dirent *dirent;
        struct pending_dir *pending;
        struct stat st;
@@ -734,7 +734,8 @@ again:
        ret = 0;
 fail:
        free(pending);
-       closedir(dirp);
+       if (dirp)
+               closedir(dirp);
        return ret;
 }