Message ID | c350fb69d39bf3edc2a0f5f762898c9a73e1fe62.1584690565.git.michal.simek@xilinx.com |
---|---|
State | Accepted |
Commit | 0486497e2b5f4d36fa968a1a60fea358cbf70b65 |
Headers | show |
Series | [v3] lib: Improve _parse_integer_fixup_radix base 16 detection | expand |
diff --git a/lib/strto.c b/lib/strto.c index 55ff9f7437d5..1ac2b09c725c 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -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;