[comp.sys.amiga.tech] Bug in Lattice C 5.04

Bits_of_Magic@cup.portal.com (09/05/90)

I found a major bug in Lattice C 5.04 for the IBM host, which is supposed
to be identical to the native version, but I guess not.  The bug:

LONG value;

switch (value) {
 case 0:
  DoSomething();
  break;
case 0x100000000
 DoFoo();
 break;
}

whether value is 0 or 100000000, DoSomething() executes.  When I looked at
a disassembly from OMD, it was clear that in the 2nd case, the code was
checking for equality to 0!  I am going to call Lattice about this,
and will post further afterwards.

Nicky Robinson
<bits_of_magic@cup.portal.com>

Bits_of_Magic@cup.portal.com (09/06/90)

In my previous post I said:

>I found a major bug in Lattice C 5.04 for the IBM host, which is supposed
>to be identical to the native version, but I guess not.  The bug:
>
>LONG value;
>
>switch (value) {
> case 0:
>  DoSomething();
>  break;
>case 0x100000000
> DoFoo();
> break;
>}
>
>whether value is 0 or 100000000, DoSomething() executes.  When I looked at
>a disassembly from OMD, it was clear that in the 2nd case, the code was
>checking for equality to 0!  I am going to call Lattice about this,
>and will post further afterwards.

Oops!  That 2nd case value should be 0x10000000 (instead of a 64 bit #!).
Somebody noted that technically a long constant should be followed by an
L, but since 32 bits is an integer in this compiler by default, it doesn't
require the L.  Also, when I found this bug, I was using system defined
constants.

I have since talked to Lattice and sent them the actual offending code.
They were very nice, but will no doubt try to charge $100 for the
upgrade with the fixed bug...  Interestingly I found 2 more minor bugs
today -- they have quit asking me for my serial number because I called
so much.

The other 2 bugs:
1) The built-in functions abs(), min(), and max() aren't protyped as built-
in functions in string.h.  You can do it yourself, so it isn't major.

2) The following code generates an argument type incorrect error:

void Foo(short);

short x,y;

Foo(x-y);

brians@hpcljms.HP.COM (Brian Sullivan) (09/06/90)

> I found a major bug in Lattice C 5.04 for the IBM host, which is supposed
> to be identical to the native version, but I guess not.  The bug:
> 
> LONG value;
> 
> switch (value) {
>  case 0:
>   DoSomething();
>   break;
> case 0x100000000
>  DoFoo();
>  break;
> }
> 
> whether value is 0 or 100000000, DoSomething() executes.  When I looked at
> a disassembly from OMD, it was clear that in the 2nd case, the code was
> checking for equality to 0!  I am going to call Lattice about this,
> and will post further afterwards.
> 
> Nicky Robinson
> <bits_of_magic@cup.portal.com>

   What do you really expect the compiler to do?  It should give you an
error message or warning  about "hex constant too large", but otherwise 
the compiler is simply doing what it should.  You hex constant 0x100000000, 
is too large to fit into a 32-bit storage container.  I suspect that the 
compiler parser is scaning the constant digit by digit, multiplying by 16 
each time and adding the new digit value.  

   You program is clearly in error, since hex constants can be at most 8 hex
digits long.  

p554mve@mpirbn.mpifr-bonn.mpg.de (Michael van Elst) (09/06/90)

In article <33535@cup.portal.com> Bits_of_Magic@cup.portal.com writes:
>case 0x100000000
>
>whether value is 0 or 100000000, DoSomething() executes.  When I looked at

Joking ? 0x100000000 is out of range for 32bit longs (and with modulo 32bit
arithmetic equal to zero).

-- 
Michael van Elst
UUCP:     universe!local-cluster!milky-way!sol!earth!uunet!unido!mpirbn!p554mve
Internet: p554mve@mpirbn.mpifr-bonn.mpg.de
                                "A potential Snark may lurk in every tree."