util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] fdisk: rename read_int_sx() and some related variables
@ 2012-01-16  5:36 Francesco Cosoleto
  2012-01-16  5:36 ` [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix Francesco Cosoleto
  2012-01-16 21:11 ` [PATCH 1/2] fdisk: rename read_int_sx() and some related variables Karel Zak
  0 siblings, 2 replies; 4+ messages in thread
From: Francesco Cosoleto @ 2012-01-16  5:36 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |   42 +++++++++++++++++++++---------------------
 1 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 8c143c3..764798d 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1298,10 +1298,10 @@ read_hex(struct systypes *sys)
 }
 
 static unsigned int
-read_int_sx(unsigned int low, unsigned int dflt, unsigned int high,
-	 unsigned int base, char *mesg, int *suffix)
+read_int_with_suffix(unsigned int low, unsigned int dflt, unsigned int high,
+	 unsigned int base, char *mesg, int *is_suffix_used)
 {
-	unsigned int i;
+	unsigned int res;
 	int default_ok = 1;
 	static char *ms = NULL;
 	static size_t mslen = 0;
@@ -1334,7 +1334,7 @@ read_int_sx(unsigned int low, unsigned int dflt, unsigned int high,
 			int absolute = 0;
 			int suflen;
 
-			i = atoi(line_ptr+1);
+			res = atoi(line_ptr + 1);
 
 			while (isdigit(*++line_ptr))
 				use_default = 0;
@@ -1353,7 +1353,7 @@ read_int_sx(unsigned int low, unsigned int dflt, unsigned int high,
 				 * Cylinders
 				 */
 				if (!display_in_cyl_units)
-					i *= heads * sectors;
+					res *= heads * sectors;
 			} else if (*line_ptr &&
 				   *(line_ptr + 1) == 'B' &&
 				   *(line_ptr + 2) == '\0') {
@@ -1391,36 +1391,36 @@ read_int_sx(unsigned int low, unsigned int dflt, unsigned int high,
 				continue;
 			}
 
-			if (absolute && i) {
+			if (absolute && res) {
 				unsigned long long bytes;
 				unsigned long unit;
 
-				bytes = (unsigned long long) i * absolute;
+				bytes = (unsigned long long) res * absolute;
 				unit = sector_size * units_per_sector;
 				bytes += unit/2;	/* round */
 				bytes /= unit;
-				i = bytes;
-				if (suffix)
-					*suffix = absolute;
+				res = bytes;
+				if (is_suffix_used)
+					*is_suffix_used = absolute;
 			}
 			if (minus)
-				i = -i;
-			i += base;
+				res = -res;
+			res += base;
 		} else {
-			i = atoi(line_ptr);
+			res = atoi(line_ptr);
 			while (isdigit(*line_ptr)) {
 				line_ptr++;
 				use_default = 0;
 			}
 		}
 		if (use_default)
-			printf(_("Using default value %u\n"), i = dflt);
-		if (i >= low && i <= high)
+			printf(_("Using default value %u\n"), res = dflt);
+		if (res >= low && res <= high)
 			break;
 		else
 			printf(_("Value out of range.\n"));
 	}
-	return i;
+	return res;
 }
 
 /*
@@ -1434,7 +1434,7 @@ unsigned int
 read_int(unsigned int low, unsigned int dflt, unsigned int high,
 	 unsigned int base, char *mesg)
 {
-	return read_int_sx(low, dflt, high, base, mesg, NULL);
+	return read_int_with_suffix(low, dflt, high, base, mesg, NULL);
 }
 
 
@@ -2336,21 +2336,21 @@ add_partition(int n, int sys) {
 	if (cround(start) == cround(limit)) {
 		stop = limit;
 	} else {
-		int sx = 0;
+		int is_suffix_used = 0;
 
 		snprintf(mesg, sizeof(mesg),
 			_("Last %1$s, +%2$s or +size{K,M,G}"),
 			 str_units(SINGULAR), str_units(PLURAL));
 
-		stop = read_int_sx(cround(start), cround(limit), cround(limit),
-				cround(start), mesg, &sx);
+		stop = read_int_with_suffix(cround(start), cround(limit), cround(limit),
+				cround(start), mesg, &is_suffix_used);
 		if (display_in_cyl_units) {
 			stop = stop * units_per_sector - 1;
 			if (stop >limit)
 				stop = limit;
 		}
 
-		if (sx && alignment_required) {
+		if (is_suffix_used && alignment_required) {
 			/* the last sector has not been exactly requested (but
 			 * defined by +size{K,M,G} convention), so be smart
 			 * and align the end of the partition. The next
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix
  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
  2012-01-16 21:12   ` Karel Zak
  2012-01-16 21:11 ` [PATCH 1/2] fdisk: rename read_int_sx() and some related variables Karel Zak
  1 sibling, 1 reply; 4+ messages in thread
From: Francesco Cosoleto @ 2012-01-16  5:36 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] fdisk: rename read_int_sx() and some related variables
  2012-01-16  5:36 [PATCH 1/2] fdisk: rename read_int_sx() and some related variables Francesco Cosoleto
  2012-01-16  5:36 ` [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix Francesco Cosoleto
@ 2012-01-16 21:11 ` Karel Zak
  1 sibling, 0 replies; 4+ messages in thread
From: Karel Zak @ 2012-01-16 21:11 UTC (permalink / raw)
  To: Francesco Cosoleto; +Cc: util-linux

On Mon, Jan 16, 2012 at 06:36:12AM +0100, Francesco Cosoleto wrote:
>  fdisk/fdisk.c |   42 +++++++++++++++++++++---------------------
>  1 files changed, 21 insertions(+), 21 deletions(-)

 Applied, thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix
  2012-01-16  5:36 ` [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix Francesco Cosoleto
@ 2012-01-16 21:12   ` Karel Zak
  0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2012-01-16 21:12 UTC (permalink / raw)
  To: Francesco Cosoleto; +Cc: util-linux

On Mon, Jan 16, 2012 at 06:36:13AM +0100, Francesco Cosoleto wrote:
> 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>

 Applied. Thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-16 21:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-16  5:36 [PATCH 1/2] fdisk: rename read_int_sx() and some related variables Francesco Cosoleto
2012-01-16  5:36 ` [PATCH 2/2] fdisk: fix last sector dialog bug after an incorrect input with suffix Francesco Cosoleto
2012-01-16 21:12   ` Karel Zak
2012-01-16 21:11 ` [PATCH 1/2] fdisk: rename read_int_sx() and some related variables Karel Zak

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).