]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: fix last sector dialog bug after an incorrect input with suffix
authorFrancesco Cosoleto <cosoleto@gmail.com>
Mon, 16 Jan 2012 05:36:13 +0000 (06:36 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Jan 2012 20:53:00 +0000 (21:53 +0100)
If user input in a last sector dialog was out of range and with suffix, and if
this was followed by accepting the default value, then the used last sector was
erroneously default - 1.

Reported-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
fdisk/fdisk.c

index 764798d17be409fe3319184f49df8f1fbc1233e4..cb67fd3eee666d9507dcaeb7c2b3bcc85a041d40 100644 (file)
@@ -1303,6 +1303,7 @@ read_int_with_suffix(unsigned int low, unsigned int dflt, unsigned int high,
 {
        unsigned int res;
        int default_ok = 1;
+       int absolute = 0;
        static char *ms = NULL;
        static size_t mslen = 0;
 
@@ -1331,9 +1332,9 @@ read_int_with_suffix(unsigned int low, unsigned int dflt, unsigned int high,
 
                if (*line_ptr == '+' || *line_ptr == '-') {
                        int minus = (*line_ptr == '-');
-                       int absolute = 0;
                        int suflen;
 
+                       absolute = 0;
                        res = atoi(line_ptr + 1);
 
                        while (isdigit(*++line_ptr))
@@ -1400,8 +1401,6 @@ read_int_with_suffix(unsigned int low, unsigned int dflt, unsigned int high,
                                bytes += unit/2;        /* round */
                                bytes /= unit;
                                res = bytes;
-                               if (is_suffix_used)
-                                       *is_suffix_used = absolute;
                        }
                        if (minus)
                                res = -res;
@@ -1413,13 +1412,17 @@ read_int_with_suffix(unsigned int low, unsigned int dflt, unsigned int high,
                                use_default = 0;
                        }
                }
-               if (use_default)
-                       printf(_("Using default value %u\n"), res = dflt);
+               if (use_default) {
+                       printf(_("Using default value %u\n"), dflt);
+                       return dflt;
+               }
                if (res >= low && res <= high)
                        break;
                else
                        printf(_("Value out of range.\n"));
        }
+       if (is_suffix_used)
+                       *is_suffix_used = absolute > 0;
        return res;
 }