tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strtonum(3) from OpenBSD?



David Laight wrote:
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.

Using the standard, it's not.
GNU libc sets ERANGE if the conversion overflows, I see no reason why we could not do similar.

Thanks

Roy


Home | Main Index | Thread Index | Old Index