From owner-freebsd-current Wed May 15 11: 3:59 2002 Delivered-To: freebsd-current@freebsd.org Received: from mail.musha.org (daemon.musha.org [218.44.187.2]) by hub.freebsd.org (Postfix) with ESMTP id 0FE7D37BBA1; Wed, 15 May 2002 11:02:57 -0700 (PDT) Received: from archon.local.idaemons.org (archon.local.idaemons.org [192.168.1.32]) by mail.musha.org (Postfix) with ESMTP id E18D24D800; Thu, 16 May 2002 02:42:32 +0900 (JST) Date: Thu, 16 May 2002 02:42:34 +0900 Message-ID: <86sn4t8fzp.wl@archon.local.idaemons.org> From: "Akinori MUSHA" To: audit@FreeBSD.org Cc: current@FreeBSD.org Subject: moused(8): char signed-ness problem with gcc 3.1 User-Agent: Wanderlust/2.9.11 (Unchained Melody) SEMI/1.14.3 (Ushinoya) LIMIT/1.14.7 (Fujiidera) APEL/10.3 MULE XEmacs/21.1 (patch 14) (Cuyahoga Valley) (i386--freebsd) Organization: Associated I. Daemons X-PGP-Public-Key: finger knu@FreeBSD.org X-PGP-Fingerprint: 081D 099C 1705 861D 4B70 B04A 920B EFC7 9FD9 E1EE MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I observed gcc 2.95.4 and gcc 3.1 interpret (or maybe optimize) the following code differently (CFLAGS=-O): int main(void) { unsigned char i = 127; printf("%d\n", ((char)(i << 1)) / 2); return 0; } gcc 2.95.4 says it's -1, whereas gcc 3.1 says it's 127. On FreeBSD char should be signed, so I suspect it's a (optimization) bug of gcc 3.1 which should be fixed. Or we'll have to do a mass audit of the whole src tree to check and fix the similar expressions. In any case, this behavior makes moused(8) return a stupid value of 127 when you roll the mouse wheel up under ps/2-sysmouse-intellimouse protocol. Attached is a patch that makes the whole expression look more logical and works around the above behavior at the same time. -- / /__ __ Akinori.org / MUSHA.org / ) ) ) ) / FreeBSD.org / Ruby-lang.org Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp "Somewhere out of a memory.. of lighted streets on quiet nights.." Index: moused.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/moused/moused.c,v retrieving revision 1.55 diff -u -r1.55 moused.c --- moused.c 28 Apr 2002 11:59:30 -0000 1.55 +++ moused.c 15 May 2002 17:16:40 -0000 @@ -1972,7 +1972,7 @@ act->dx = (char)(pBuf[1]) + (char)(pBuf[3]); act->dy = - ((char)(pBuf[2]) + (char)(pBuf[4])); if (rodent.level == 1) { - act->dz = ((char)(pBuf[5] << 1) + (char)(pBuf[6] << 1))/2; + act->dz = ((char)(pBuf[5] << 1) + (char)(pBuf[6] << 1)) >> 1; act->button |= ((~pBuf[7] & MOUSE_SYS_EXTBUTTONS) << 3); } break; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message