[PATCH kvmtool] builtin-run: Allow octal and hex numbers for -m/--mem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is no reason why -m/--mem should not allow the user to express the
desired memory size in octal or hexadecimal, especially when it's as easy
as changing the strtoull() 'base' parameter to 0, as per man 3 strtoull.

Before:

  $ ./lkvm run -m 0x200 -k Image

would fail with the error message:

  Fatal: Invalid RAM size: 0x200

And now that works as expected.

Before:

  $ ./lkvm run -m 01000 -k Image

would create a VM with 1000MB of memory, when it's known that numbers
that start with a 0 are in base 8. With this patch, that's interpreted
correctly as 512 in base 8.

Note that this is a change in behaviour, but writing decimal numbers with
leading zeros is very uncommon, and it is this author's humble opinion that
there are no kvmtool users that do this.

Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx>
---
 builtin-run.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin-run.c b/builtin-run.c
index c26184ea7fc0..ebff9d5da49d 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -108,7 +108,7 @@ static u64 parse_mem_option(const char *nptr, char **next)
 	u64 val;
 
 	errno = 0;
-	val = strtoull(nptr, next, 10);
+	val = strtoull(nptr, next, 0);
 	if (errno == ERANGE)
 		die("Memory too large: %s", nptr);
 	if (*next == nptr)
-- 
2.45.1





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux