summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2019-05-13 16:15:58 +0200
committerKarel Zak2019-05-13 16:15:58 +0200
commit482e0a07544501ece40314d045b4c70ba9546295 (patch)
tree6ffd874b2464ba9a82619c578a7384613de5be61 /lib
parentfstrim: affect only warnings by --quiet (diff)
downloadkernel-qcow2-util-linux-482e0a07544501ece40314d045b4c70ba9546295.tar.gz
kernel-qcow2-util-linux-482e0a07544501ece40314d045b4c70ba9546295.tar.xz
kernel-qcow2-util-linux-482e0a07544501ece40314d045b4c70ba9546295.zip
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 <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/strutils.c19
1 files changed, 12 insertions, 7 deletions
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 */