[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: strtonum(3) from OpenBSD?
On Mon, Jun 29, 2009 at 11:41:04PM -0400, James K. Lowden wrote:
> I fail to see how sscanf(3) is more error prone than strtonum(). No
> matter what, you have to specify -- via the name or the format string --
> the format of the input and of the receiving buffer. At least with
> sscanf(3) that's *all* you have to do.
Correct use of sscanf() for a single integer is something like:
count = sscanf(inbuf, "%i%n", &int_val, &byte_count);
if (count != 2 || inbuf[byte_count] != 0)
/* Conversion error */
I'm not sure that it is possible to detect numeric overflow.
If you start using more complicated format strings, then you have to
be even more careful that the user-supplied input is correctly processed.
David Laight: david%l8s.co.uk@localhost
Main Index |
Thread Index |