[2/8] btrfs-progs: do not modify the string in parse_range
diff mbox

Message ID 064ee1e727d13b169b530ec6bc7331b516d11139.1445011409.git.dsterba@suse.com
State New
Headers show

Commit Message

David Sterba Oct. 16, 2015, 4:17 p.m. UTC
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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Patch
diff mbox

diff --git a/cmds-balance.c b/cmds-balance.c
index 798b533aa7d6..0a1bf0cd0699 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -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;
 	}