summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Simek <michal.simek@xilinx.com>2020-02-07 15:04:10 +0300
committerMichal Simek <michal.simek@xilinx.com>2020-04-06 13:52:45 +0300
commit0486497e2b5f4d36fa968a1a60fea358cbf70b65 (patch)
tree09a7a0abdb8b1075f107e89419d39b1d1d9fa2b7
parent352f86bf8658ec32d9e64f2d1b9134be6f8555e5 (diff)
downloadu-boot-0486497e2b5f4d36fa968a1a60fea358cbf70b65.tar.xz
lib: Improve _parse_integer_fixup_radix base 16 detection
Base autodetection is failing for this case: if test 257 -gt 3ae; then echo first; else echo second; fi It is because base for 3ae is recognized by _parse_integer_fixup_radix() as 10. The code detects the first char which is not between 'a'/'A' or 'f'/'F' to change base from dec to hex. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>
-rw-r--r--lib/strto.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/strto.c b/lib/strto.c
index 55ff9f7437..1ac2b09c72 100644
--- a/lib/strto.c
+++ b/lib/strto.c
@@ -22,9 +22,22 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
*base = 16;
else
*base = 8;
- } else
+ } else {
+ int i = 0;
+ char var;
+
*base = 10;
+
+ do {
+ var = tolower(s[i++]);
+ if (var >= 'a' && var <= 'f') {
+ *base = 16;
+ break;
+ }
+ } while (var);
+ }
}
+
if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
s += 2;
return s;