btrfs-progs: do not modify the string in parse_range

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>
This commit is contained in:
David Sterba 2015-10-16 14:51:20 +02:00
parent 9288d0bc23
commit 2b7f0192e8
1 changed files with 5 additions and 3 deletions

View 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;
}