|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] x86/hvmloader: adjust strtoll() to parse hex numbers without 0x prefix
commit 3453aa3f8626fd70ef29cd13961f240618c755c2
Author: Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Wed Jul 23 16:55:06 2025 +0200
Commit: Roger Pau Monne <roger.pau@xxxxxxxxxx>
CommitDate: Thu Jul 24 13:11:23 2025 +0200
x86/hvmloader: adjust strtoll() to parse hex numbers without 0x prefix
The current strtoll() implementation in hvmloader requires hex number to be
prefixed with 0x, otherwise strtoll() won't parse them correctly even when
calling the function with base == 16.
Fix this by not unconditionally setting the base to 10 when the string is
not 0 prefixed, this also allows parsing octal numbers not 0 prefixed.
While there also handle '0X' as a valid hex number prefix, together with
'0x'.
No functional change intended to the existing call sites.
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
tools/firmware/hvmloader/util.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index 31b4411db7..e651342681 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -206,20 +206,18 @@ strtoll(const char *s, char **end, int base)
if ( *s == '\0' ) goto out;
- if ( *s == '0' ) {
+ if ( (base == 0 || base == 16) && *s == '0' ) {
s++;
if ( *s == '\0' ) goto out;
- if ( *s == 'x' ) {
- if ( base != 0 && base != 16) goto out;
+ if ( *s == 'x' || *s == 'X' ) {
base = 16;
s++;
} else {
- if ( base != 0 && base != 8) goto out;
+ if ( base != 0 ) goto out;
base = 8;
}
- } else {
- if (base != 0 && base != 10) goto out;
+ } else if ( base == 0 ) {
base = 10;
}
--
generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |