🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1033

GCC 2.2.2's print-tree.c contains overflow in constant expression

#1033
From: Paul Eggert
Date: Tue, 01 Sep 1992 02:45
39 lines
1789 bytes
GCC 2.2.2's print-tree.c contains an expression of the form
`1 << (HOST_BITS_PER_INT - 1)', which contains an arithmetic overflow,
and thus runs afoul of compilers that check for integer overflow in
expressions.

The expression in question is used merely to turn off the top bit of a
numerator to avoid problems with taking remainders of negative numbers;
a simple fix is to use unsigned remainder instead.  Here is a patch.
Another fix would be to replace `1 << (HOST_BITS_PER_INT - 1)' with
`(unsigned) 1 << (HOST_BITS_PER_INT - 1)'.

Mon Aug 31 20:09:29 1992  Paul Eggert  (eggert@twinsun.com)

	* print-tree.c (print_node): Avoid 1 << (HOST_BITS_PER_INT - 1),
	which overflows.

===================================================================
RCS file: print-tree.c,v
retrieving revision 2.2
diff -c -r2.2 print-tree.c
*** print-tree.c	1992/04/27 16:54:16	2.2
--- print-tree.c	1992/08/31 20:09:29
***************
*** 193,199 ****
        return;
      }
  
!   hash = ((int) node & ~(1 << (HOST_BITS_PER_INT - 1))) % HASH_SIZE;
  
    /* If node is in the table, just mention its address.  */
    for (b = table[hash]; b; b = b->next)
--- 193,199 ----
        return;
      }
  
!   hash = (unsigned) node % HASH_SIZE;
  
    /* If node is in the table, just mention its address.  */
    for (b = table[hash]; b; b = b->next)
Technical Details
Message-ID: <9209010245.AA20183@farside.twinsun.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggert

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggert
From: eggert@twinsun.COM (Paul Eggert)
Subject: GCC 2.2.2's print-tree.c contains overflow in constant expression
Message-ID: <9209010245.AA20183@farside.twinsun.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 1 Sep 1992 02:45:22 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 40