btrfs-progs: do not modify the string in parse_range
authorDavid Sterba <dsterba@suse.com>
Fri, 16 Oct 2015 12:51:20 +0000 (14:51 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 2 Nov 2015 08:35:03 +0000 (09:35 +0100)
It's passed as const but we modify it through 'dots'. This would break
parsing the string multiple times.

Signed-off-by: David Sterba <dsterba@suse.com>
cmds-balance.c

index c1219be..d7f8148 100644 (file)
@@ -101,6 +101,7 @@ static int parse_u64(const char *str, u64 *result)
 static int parse_range(const char *range, u64 *start, u64 *end)
 {
        char *dots;
+       char *endptr;
        const char *rest;
        int skipped = 0;
 
@@ -109,20 +110,21 @@ static int parse_range(const char *range, u64 *start, u64 *end)
                return 1;
 
        rest = dots + 2;
-       *dots = 0;
 
        if (!*rest) {
                *end = (u64)-1;
                skipped++;
        } else {
-               if (parse_u64(rest, end))
+               *end = strtoull(rest, &endptr, 10);
+               if (*endptr)
                        return 1;
        }
        if (dots == range) {
                *start = 0;
                skipped++;
        } else {
-               if (parse_u64(range, start))
+               *end = strtoull(range, &endptr, 10);
+               if (*endptr != 0 && *endptr != '.')
                        return 1;
        }