From owner-freebsd-bugs Sun Nov 12 20:14:05 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id UAA09493 for bugs-outgoing; Sun, 12 Nov 1995 20:14:05 -0800 Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id UAA09478 for ; Sun, 12 Nov 1995 20:13:59 -0800 Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.9/8.6.9) id PAA04625; Mon, 13 Nov 1995 15:09:55 +1100 Date: Mon, 13 Nov 1995 15:09:55 +1100 From: Bruce Evans Message-Id: <199511130409.PAA04625@godzilla.zeta.org.au> To: freebsd-bugs@freebsd.org, tege@matematik.su.se Subject: Re: strtouq broken in FreeBSD 2.0.5 Sender: owner-bugs@freebsd.org Precedence: bulk >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 >#include >#include >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 shouldn't depend on typedefs or even use casts. Bruce