From: Karel Zak Date: Mon, 13 May 2019 14:15:58 +0000 (+0200) Subject: lib/strutils: parse_size() fix frac with zeros X-Git-Tag: v2.34-rc2~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=482e0a07544501ece40314d045b4c70ba9546295;p=thirdparty%2Futil-linux.git 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 --- diff --git a/lib/strutils.c b/lib/strutils.c index 369d501591..327bf37bcf 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 */