Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 330087
b: refs/heads/master
c: 77dd3b0
h: refs/heads/master
i:
  330085: 05bb021
  330083: 27b153e
  330079: 3eb0cda
v: v3
  • Loading branch information
Alex Elder authored and Linus Torvalds committed Oct 5, 2012
1 parent 75853d3 commit 4bf0252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 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: 125c4c706b680c7831f0966ff873c1ad0354ec25
refs/heads/master: 77dd3b0bd17a0849b2f98b915ce3fc9247db1013
10 changes: 8 additions & 2 deletions trunk/lib/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,30 @@ int match_token(char *s, const match_table_t table, substring_t args[])
*
* Description: Given a &substring_t and a base, attempts to parse the substring
* as a number in that base. On success, sets @result to the integer represented
* by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
* by the string and returns 0. Returns -ENOMEM, -EINVAL, or -ERANGE on failure.
*/
static int match_number(substring_t *s, int *result, int base)
{
char *endp;
char *buf;
int ret;
long val;
size_t len = s->to - s->from;

buf = kmalloc(len + 1, GFP_KERNEL);
if (!buf)
return -ENOMEM;
memcpy(buf, s->from, len);
buf[len] = '\0';
*result = simple_strtol(buf, &endp, base);

ret = 0;
val = simple_strtol(buf, &endp, base);
if (endp == buf)
ret = -EINVAL;
else if (val < (long)INT_MIN || val > (long)INT_MAX)
ret = -ERANGE;
else
*result = (int) val;
kfree(buf);
return ret;
}
Expand Down

0 comments on commit 4bf0252

Please sign in to comment.