[PATCH v2] lib: Improve _parse_integer_fixup_radix base 16 detection

Andy Shevchenko andy.shevchenko at gmail.com
Tue Mar 3 15:52:32 CET 2020


On Tue, Mar 3, 2020 at 2:03 PM Michal Simek <michal.simek at xilinx.com> wrote:
> On 03. 03. 20 10:37, Andy Shevchenko wrote:
> > 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.

Hold on!

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

Actually your code and commit message are unaligned. In the code you
stop on the *first* hex character without checking the rest.

-- 
With Best Regards,
Andy Shevchenko


More information about the U-Boot mailing list