]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
util: correctly parse shorter linux version numbers.
authorNeilBrown <neilb@suse.de>
Fri, 17 Jun 2011 12:49:24 +0000 (22:49 +1000)
committerNeilBrown <neilb@suse.de>
Fri, 17 Jun 2011 12:49:24 +0000 (22:49 +1000)
The next version of Linux might be 3.0.  If it is, get_linux_version
will fail.
So make it more robust.

Reported-by: Namhyung Kim <namhyung@gmail.com>
Reported-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
util.c

diff --git a/util.c b/util.c
index 10bbe56a4785b410ba7e243d84208015f42ccae3..55d171a0bc5e80a06deccaa7f704e571b0156f03 100644 (file)
--- a/util.c
+++ b/util.c
@@ -146,16 +146,16 @@ int get_linux_version()
 {
        struct utsname name;
        char *cp;
-       int a,b,c;
+       int a = 0, b = 0,c = 0;
        if (uname(&name) <0)
                return -1;
 
        cp = name.release;
        a = strtoul(cp, &cp, 10);
-       if (*cp != '.') return -1;
-       b = strtoul(cp+1, &cp, 10);
-       if (*cp != '.') return -1;
-       c = strtoul(cp+1, NULL, 10);
+       if (*cp == '.')
+               b = strtoul(cp+1, &cp, 10);
+       if (*cp == '.')
+               c = strtoul(cp+1, &cp, 10);
 
        return (a*1000000)+(b*1000)+c;
 }