Bug in compress

Kenneth Almquist ka at hou3c.UUCP
Wed Jan 16 08:20:03 AEST 1985


> The following code appears in two places in compress.c:
> 
>     while ( (c = getchar()) != (unsigned) EOF ) {
> 
> The problem is that ((unsigned) -1) is not the same thing as ((int) -1).
> The vax (and many other machines) do 32-bit compares, and say they are
> equal, but other machines (correctly) do not.  The program drops into
> an infinite loop looking for EOF.

The bug is in your C compiler, not in compress.  When one operand of
a binary operator is of type int and the other is of type unsigned,
both operands should be converted to unsigned.
					Kenneth Almquist


"Of course I don't read the C reference manual; it didn't come over the USENET!"



More information about the Comp.sources.bugs mailing list