Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 287378
b: refs/heads/master
c: 690d137
h: refs/heads/master
v: v3
  • Loading branch information
David Howells authored and Linus Torvalds committed Feb 9, 2012
1 parent 4fd38f7 commit 2baef3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d65b4e98d7ea3038b767b70fe8be959b2913f16d
refs/heads/master: 690d137f448d4c4da9001871e6569d5636f116c7
18 changes: 13 additions & 5 deletions trunk/lib/kstrtox.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
*
* Don't you dare use this function.
*/
unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res)
unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
{
unsigned long long res;
unsigned int rv;
int overflow;

*res = 0;
res = 0;
rv = 0;
overflow = 0;
while (*s) {
Expand All @@ -64,12 +65,19 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long

if (val >= base)
break;
if (*res > div_u64(ULLONG_MAX - val, base))
overflow = 1;
*res = *res * base + val;
/*
* Check for overflow only if we are within range of
* it in the max base we support (16)
*/
if (unlikely(res & (~0ull << 60))) {
if (res > div_u64(ULLONG_MAX - val, base))
overflow = 1;
}
res = res * base + val;
rv++;
s++;
}
*p = res;
if (overflow)
rv |= KSTRTOX_OVERFLOW;
return rv;
Expand Down

0 comments on commit 2baef3b

Please sign in to comment.