Date: Wed, 2 Jul 1997 07:13:55 +1000 From: Bruce Evans <bde@zeta.org.au> To: bde@zeta.org.au, jkh@time.cdrom.com Cc: cvs-all@FreeBSD.ORG, cvs-committers@FreeBSD.ORG, cvs-lib@FreeBSD.ORG, jkh@FreeBSD.ORG Subject: Re: cvs commit: src/lib/libc/stdio scanf.3 vfscanf.c Message-ID: <199707012113.HAA03617@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
>> I had this patch in my "needs more work" basket. Its use of strtoq() and > >Well, maybe now that it's in the tree and open to wider scrutiny, >somebody can actually push David D. in the direction of greater >"undefined compatibility" :-) Of course, scanf() is as unsafe as gets() and should never be used. Even for ints, you can't rely on the value returned or tell whether there was an overflow. strtoq() seems to be (only) about 3 times slower than strtol(). Bruce --- #include <limits.h> #include <stdio.h> #include <stdlib.h> int main(void) { int i; volatile long l; volatile long long ll; sscanf("4294967296", "%d", &i); printf("this should be %d: %d\n", INT_MAX, i); printf("testing 10^6 strtol()'s of a small value \"123\"\n"); for (i = 0; i < 1000000; ++i) l = strtol("123", 0, 10); printf("testing 10^6 strtoq()'s of a small value \"4294967296\"\n"); for (i = 0; i < 1000000; ++i) l = strtol("4294967296", 0, 10); printf("testing 10^6 strtoq()'s of a small value \"123\"\n"); for (i = 0; i < 1000000; ++i) ll = strtoq("123", 0, 10); printf("testing 10^6 strtoq()'s of a small value \"4294967296\"\n"); for (i = 0; i < 1000000; ++i) ll = strtoq("4294967296", 0, 10); return 0; } ---
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199707012113.HAA03617>