]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
fix: adjust parse_size() to the unsigned size variable
authorLukasz Dorau <lukasz.dorau@intel.com>
Fri, 14 Sep 2012 14:12:45 +0000 (16:12 +0200)
committerNeilBrown <neilb@suse.de>
Thu, 20 Sep 2012 02:27:17 +0000 (12:27 +1000)
An error in parse_size() should be reported by 0, not -1,
because -1 is changed to the max value of unsigned long long
during calculations of size (e.g. at mdadm.c:412).

A negative value of size should be reported as error
(e.g. size equal -1 has been changed to the max value of
unsigned long long so far).

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.h
util.c

diff --git a/mdadm.h b/mdadm.h
index 9feccc6005e8210aba5fb872f2d61e5ba421e93f..f202ffa67c145bbf4e9e147ed9f4a755526b7893 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1156,7 +1156,7 @@ extern unsigned long bitmap_sectors(struct bitmap_super_s *bsb);
 extern int md_get_version(int fd);
 extern int get_linux_version(void);
 extern int mdadm_version(char *version);
-extern long long parse_size(char *size);
+extern unsigned long long parse_size(char *size);
 extern int parse_uuid(char *str, int uuid[4]);
 extern int parse_layout_10(char *layout);
 extern int parse_layout_faulty(char *layout);
diff --git a/util.c b/util.c
index a92a663bf23ffb4f74d77bdd4cbaa1fe59a6457c..c63a232c919931063beb51b131e6c036eec695e7 100644 (file)
--- a/util.c
+++ b/util.c
@@ -188,13 +188,13 @@ int mdadm_version(char *version)
        return (a*1000000)+(b*1000)+c;
 }
 
-long long parse_size(char *size)
+unsigned long long parse_size(char *size)
 {
        /* parse 'size' which should be a number optionally
         * followed by 'K', 'M', or 'G'.
         * Without a suffix, K is assumed.
         * Number returned is in sectors (half-K)
-        * -1 returned on error.
+        * 0 returned on error.
         */
        char *c;
        long long s = strtoll(size, &c, 10);
@@ -214,9 +214,10 @@ long long parse_size(char *size)
                        s *= 1024 * 1024 * 2;
                        break;
                }
-       }
+       } else
+               s = 0;
        if (*c)
-               s = -1;
+               s = 0;
        return s;
 }