From owner-freebsd-bugs Sun May 11 02:20:05 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id CAA19883 for bugs-outgoing; Sun, 11 May 1997 02:20:05 -0700 (PDT) Received: (from gnats@localhost) by hub.freebsd.org (8.8.5/8.8.5) id CAA19857; Sun, 11 May 1997 02:20:02 -0700 (PDT) Date: Sun, 11 May 1997 02:20:02 -0700 (PDT) Message-Id: <199705110920.CAA19857@hub.freebsd.org> To: freebsd-bugs Cc: From: Bruce Evans Subject: Re: misc/3575: Eliminate spurious warning in /usr/src/lib/libc/stdlib/strtoq.c Reply-To: Bruce Evans Sender: owner-bugs@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk The following reply was made to PR misc/3575; it has been noted by GNATS. From: Bruce Evans To: FreeBSD-gnats-submit@freebsd.org, krw@tcn.net Cc: Subject: Re: misc/3575: Eliminate spurious warning in /usr/src/lib/libc/stdlib/strtoq.c Date: Sun, 11 May 1997 19:13:09 +1000 > During a make world the compilation of > > /usr/src/lib/libc/stdlib/strtoq.c > > produces a warning message > > > /usr/src/lib/libc/stdlib/strtoq.c:108: warning: integer overflow in expression This warning is a compiler bug (there is no overflow for unsigned types) and isn't easy to fix. Note that there is no warning for corresponding operation in strtol.c (the warning is for negating (u_quad_t)QUAD_MIN). >--- /usr/src/lib/libc/stdlib/strtoq.c Sat May 10 11:55:38 1997 >+++ strtoq.c Sat May 10 14:10:02 1997 >@@ -105,7 +105,7 @@ > * overflow. > */ > qbase = (unsigned)base; >- cutoff = neg ? -(u_quad_t)QUAD_MIN : QUAD_MAX; >+ cutoff = (u_quad_t)(neg ? QUAD_MIN : QUAD_MAX); > cutlim = cutoff % qbase; > cutoff /= qbase; > for (acc = 0, any = 0;; c = *s++) { This change would unimprove portabilty. E.g., for 64 bit 1's complement, QUAD_MIN is -0x7fffffffffffffffLL (which is represented as 0x8000000000000000). Conversion to u_quad_t gives 0x8000000000000001ULL. This must be negated (as in the original version) to give the correct cutoff of 0x7fffffffffffffffULL. For 1's complement the cutoff for the `neg' case can be expressed more naturally as (u_quad_t)(-QUAD_MIN). This fails for 2's complement due to overflow. I think the following expression works for 1's complement and 2's complement and avoids the compiler bug: cutoff = neg ? (u_quad_t)-(QUAD_MIN + 1) + 1 : QUAD_MAX; This depends on QUAD_MIN not being too different from -QUAD_MAX. It can be improved to: cutoff = neg ? (u_quad_t)-(QUAD_MIN + QUAD_MAX) + QUAD_MAX : QUAD_MAX; I think fixing the compiler would be easier :-). Bruce