Date: Mon, 13 Nov 1995 15:09:55 +1100 From: Bruce Evans <bde@zeta.org.au> To: freebsd-bugs@freebsd.org, tege@matematik.su.se Subject: Re: strtouq broken in FreeBSD 2.0.5 Message-ID: <199511130409.PAA04625@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
>This program demonstrates that strtouq doesn't work right. >As a matter of fact, it seems to have more than one problem, since >other things fail when a non-zero base argument is passed. >The author of strtouq should learn to test his/her code. >#include <sys/types.h> >#include <stdlib.h> >#include <limits.h> >main () >{ > unsigned long long rs = strtouq ("12345678910", 0, 0); > printf ("%qx\n", rs); >} This seems to be a bug in gcc. Doesn't the author of gcc test his/her code? :-) main () { unsigned long qbase = 10; unsigned long long cutoff = ((unsigned long long)0 - 1) / qbase; printf ("%qd\n", cutoff); } Output from `gcc -O -S z.c' under FreeBSD. .file "z.c" gcc2_compiled.: ___gnu_compiled_c: .text LC0: .ascii "%qd\12\0" .align 2 .globl _main .type _main,@function _main: pushl %ebp movl %esp,%ebp call ___main pushl $0 pushl $10 pushl $0 // <== should be -1 pushl $-1 call ___udivdi3 addl $16,%esp pushl %edx pushl %eax pushl $LC0 call _printf leave ret Lfe1: .size _main,Lfe1-_main This is for gcc-2.6.3 under FreeBSD. gcc-2.5.8 under Linux and gcc-2.7.0 under FreeBSD produce the correct code. I think the complicated definition of UQUAD_MAX is to work around bugs in older versions of gcc. But <machine/limits.h> shouldn't depend on typedefs or even use casts. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199511130409.PAA04625>