]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
lib: Improve _parse_integer_fixup_radix base 16 detection
authorMichal Simek <michal.simek@xilinx.com>
Fri, 7 Feb 2020 12:04:10 +0000 (13:04 +0100)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 6 Apr 2020 10:52:45 +0000 (12:52 +0200)
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>
lib/strto.c

index 55ff9f7437d515d3a78aea4d8e23b01f2957322c..1ac2b09c725ca24c788b819f679fac9e772642c2 100644 (file)
@@ -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;