diff mbox series

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

Message ID 20241128135041.8737-1-alexandru.elisei@arm.com (mailing list archive)
State New
Headers show
Series [kvmtool] builtin-run: Allow octal and hex numbers for -m/--mem | expand

Commit Message

Alexandru Elisei Nov. 28, 2024, 1:50 p.m. UTC
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@arm.com>
---
 builtin-run.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

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)