[PATCH v2] lib: Improve _parse_integer_fixup_radix base 16 detection

Michal Simek michal.simek at xilinx.com
Tue Mar 3 13:02:41 CET 2020


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.
> 
> ...
> 
>> +                       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?

not a problem with this.


> 
> ...
> 
>>         }
> 
>> +
> 
> Is this relevant?

it can be removed from this patch but I can't see any issue with it to
making code more readable.

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

M


More information about the U-Boot mailing list