From: Francesco Cosoleto <cosoleto@gmail.com>
To: util-linux@vger.kernel.org
Cc: Francesco Cosoleto <cosoleto@gmail.com>
Subject: [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix
Date: Mon, 16 Jan 2012 06:36:13 +0100 [thread overview]
Message-ID: <1326692173-11791-2-git-send-email-cosoleto@gmail.com> (raw)
In-Reply-To: <1326692173-11791-1-git-send-email-cosoleto@gmail.com>
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 | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 764798d..cb67fd3 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -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;
}
--
1.7.7
next prev parent reply other threads:[~2012-01-16 5:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-16 5:36 [PATCH 1/2] fdisk: rename read_int_sx() and some related variables Francesco Cosoleto
2012-01-16 5:36 ` Francesco Cosoleto [this message]
2012-01-16 21:12 ` [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix Karel Zak
2012-01-16 21:11 ` [PATCH 1/2] fdisk: rename read_int_sx() and some related variables Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1326692173-11791-2-git-send-email-cosoleto@gmail.com \
--to=cosoleto@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).