From 482e0a07544501ece40314d045b4c70ba9546295 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 13 May 2019 16:15:58 +0200 Subject: lib/strutils: parse_size() fix frac with zeros Fix 0.001G as well as accept 0.000G as valid number. Signed-off-by: Karel Zak --- lib/strutils.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/strutils.c b/lib/strutils.c index 369d50159..327bf37bc 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -122,13 +122,18 @@ check_suffix: for (p = fstr; *p == '0'; p++) frac_zeros++; - errno = 0, end = NULL; - frac = strtoumax(fstr, &end, 0); - if (end == fstr || - (errno != 0 && (frac == UINTMAX_MAX || frac == 0))) { - rc = errno ? -errno : -EINVAL; - goto err; - } + fstr = p; + if (isdigit(*fstr)) { + errno = 0, end = NULL; + frac = strtoumax(fstr, &end, 0); + if (end == fstr || + (errno != 0 && (frac == UINTMAX_MAX || frac == 0))) { + rc = errno ? -errno : -EINVAL; + goto err; + } + } else + end = (char *) p; + if (frac && (!end || !*end)) { rc = -EINVAL; goto err; /* without suffix, but with frac */ -- cgit v1.2.3-55-g7522