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

From: Andreas Schwab (schwab@suse.de)
Date: Mon Nov 11 2002 - 09:38:15 EST


"Randy.Dunlap" <rddunlap@osdl.org> writes:

|> On Sun, 10 Nov 2002, Henning P. Schmiedehausen wrote:
|>
|> | "Randy.Dunlap" <rddunlap@osdl.org> writes:
|> |
|> | >+ digit = *str;
|> | >+ if (is_sign && digit == '-')
|> | >+ digit = *(str + 1);
|> |
|> | If signed is not allowed and you get a "-", you're in an error case
|> | again...
|>
|> Yes, and a 0 value is returned.
|> IOW, asking for an unsigned number (in the format string)
|> and getting "-123" does return 0.

Not in C. According to the standard scanf is supposed to convert the
value to unsinged and return that.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
-
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:22 EST