Re: [PATCH] Re: sscanf("-1", "%d", &i) fails, returns 0

From: Randy.Dunlap (rddunlap@osdl.org)
Date: Fri Nov 08 2002 - 17:09:09 EST


On Fri, 8 Nov 2002, Linus Torvalds wrote:

|
| On Fri, 8 Nov 2002, Randy.Dunlap wrote:
| ?
| > Sure, it looks cleaner that way, although gcc has already put <*dig>
| > in a local register; i.e., it's not pulled from memory for each test.
| > Here's a (tested) version that does that.
|
| Why do you have that "dig" pointer at all? It's not really used.
|
| Why not just do
|
| + char digit;
| ...
|
| + digit = str;
| + if (digit == '-')
| + digit = str[1];
|
|
| (and maybe it should also test for whether signed stuff is even alloed or
| not, ie maybe the test should be "if (is_sign && digit == '-')" instead)

OK, I've cleaned it up as suggested...

-- 
~Randy

--- ./lib/vsprintf.c%signed Mon Nov 4 14:30:49 2002 +++ ./lib/vsprintf.c Fri Nov 8 13:54:33 2002 @@ -517,6 +517,7 @@ { const char *str = buf; char *next; + char digit; int num = 0; int qualifier; int base; @@ -638,12 +639,16 @@ while (isspace(*str)) str++;

- if (!*str - || (base == 16 && !isxdigit(*str)) - || (base == 10 && !isdigit(*str)) - || (base == 8 && (!isdigit(*str) || *str > '7')) - || (base == 0 && !isdigit(*str))) - break; + digit = *str; + if (is_sign && digit == '-') + digit = *(str + 1); + + if (!digit + || (base == 16 && !isxdigit(digit)) + || (base == 10 && !isdigit(digit)) + || (base == 8 && (!isdigit(digit) || digit > '7')) + || (base == 0 && !isdigit(digit))) + break;

switch(qualifier) { case 'h':

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Nov 15 2002 - 22:00:16 EST