mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 23:24:38 +00:00
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>
This commit is contained in:
parent
352f86bf86
commit
0486497e2b
1 changed files with 14 additions and 1 deletions
15
lib/strto.c
15
lib/strto.c
|
@ -22,9 +22,22 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
|
||||||
*base = 16;
|
*base = 16;
|
||||||
else
|
else
|
||||||
*base = 8;
|
*base = 8;
|
||||||
} else
|
} else {
|
||||||
|
int i = 0;
|
||||||
|
char var;
|
||||||
|
|
||||||
*base = 10;
|
*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')
|
if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
|
||||||
s += 2;
|
s += 2;
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in a new issue