Btrfs-progs: make pretty_sizes take u64 instead of a double
authorJosef Bacik <jbacik@fusionio.com>
Tue, 22 Oct 2013 14:10:21 +0000 (10:10 -0400)
committerChris Mason <chris.mason@fusionio.com>
Thu, 24 Oct 2013 09:57:44 +0000 (05:57 -0400)
This got changed to a double but all the callers still use a u64, which causes
us to segfault sometimes because of some weird C voodoo that I had to have
explained to me.  Apparently because we're using a double the compiler will use
the floating point registers to hold our argument which ends up not being
aligned properly if you don't actually give it a double so it will cause
problems for other things, in our case it was screwing up str_bytes so it was
larger than the actual size of the str.  This patch fixes the segfault.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
utils.c
utils.h

diff --git a/utils.c b/utils.c
index d241044..5bedd97 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1213,7 +1213,7 @@ out:
 }
 
 static char *size_strs[] = { "", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"};
-int pretty_size_snprintf(double size, char *str, size_t str_bytes)
+int pretty_size_snprintf(u64 size, char *str, size_t str_bytes)
 {
        int num_divs = 0;
        float fraction;
diff --git a/utils.h b/utils.h
index 4d0db1d..6f4b10c 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -57,7 +57,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size,
 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
                                 int super_offset);
 
-int pretty_size_snprintf(double size, char *str, size_t str_bytes);
+int pretty_size_snprintf(u64 size, char *str, size_t str_bytes);
 #define pretty_size(size)                                              \
        ({                                                              \
                static __thread char _str[24];                          \