Use (arith) 1 << ... when getting the sign bit.
authorGeorge Koehler <xkernigh@netscape.net>
Sun, 29 Oct 2017 21:45:10 +0000 (17:45 -0400)
committerGeorge Koehler <xkernigh@netscape.net>
Sun, 29 Oct 2017 21:45:10 +0000 (17:45 -0400)
commit59b3c105632a6067998ad36631b3eba9b2165219
tree10e850de869074d83abcf271a29c06fa3983bbfc
parentd36807b395ddb3a77702ff76487e83fc42db1b89
Use (arith) 1 << ... when getting the sign bit.

This prevents an overflow reported by @hexcoder- in
https://github.com/davidgiven/ack/issues/56

lang/cem/cpp.ansi/LLlex.c used a plain 1 << ... and caused an overflow
on machines where sizeof(int) < sizeof(long).  Using 1L << ... would
work for now but might fail later if arith became long long.

C doesn't specify whether negative integers use 2's complement or some
other format.  Therefore, (arith) 1 << ... has an undefined value.  It
should still work because the value is some integer where the sign bit
is set and all other bits are clear.

(unsigned arith) 1 << ... would also get the sign bit, but casting it
from unsigned back to signed would make the same undefined value.

(arith) -1 << ... would assume 2's complement.
lang/cem/cpp.ansi/LLlex.c
lang/cem/cpp.ansi/arith.h
lang/cem/cpp.ansi/ch3bin.c
lang/m2/comp/cstoper.c
lang/m2/comp/type.c