[PATCH v2] lib: Improve _parse_integer_fixup_radix base 16 detection

Andy Shevchenko andy.shevchenko at gmail.com
Tue Mar 3 10:37:34 CET 2020


On Mon, Mar 2, 2020 at 10:36 AM Michal Simek <michal.simek at xilinx.com> wrote:
>
> 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 patch is checking all chars to make sure that they are not 'a' or
> up. If they are base needs to be in hex.

...

> +                       for (i = 0; ; i++) {
> +                               char var = s[i];
> +
> +                               if (var == '\0')
> +                                       break;
> +
> +                               if ((var >= 'a' && var <= 'f') ||
> +                                   (var >= 'A' && var <= 'F')) {
> +                                       *base = 16;
> +                                       break;
> +                               }
> +                       }

int i = 0;
char var;

do {
  var = tolower(s[i++]);
  if (...) {
   *base = 16;
   break;
  }
} while (var);

or alike?

...

>         }

> +

Is this relevant?

>         if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
>                 s += 2;
>         return s;

-- 
With Best Regards,
Andy Shevchenko


More information about the U-Boot mailing list