[comp.sys.atari.st] Sozobon C bug report

S.Usher@ucl-cs.UUCP (07/07/89)

From:     Stephen Usher <S.Usher@uk.ac.ucl.cs>


I have just found an unfortunate bug with Sozobon C. If you divide using
long integers you sometimes get a negative result, even when both the
integers have positive values.

The piece of code which highlighed the bug is part of a program which
emulates the UN*X MORE program. It's actual function is to work and display
the percentage of the file so far seen. Here is a code segment.

static long endoffile, bytes = 0, topbytes;

   endoffile = endof(fp);

      topbytes = bytes;

      if (fp != stdin)
         printf("(%ld%%)", ((bytes * 100) / endoffile));

long endof(fp)
FILE *fp;
{
   return (lseek(fileno(fp), 0L, 2));
}

The variable "bytes" is always incremented and, therefore, can never become
negative, so topbytes can never become negative (topbytes holds the file
position of the top of the screen).

		Stephen Usher

Addresses:-
(JANET)

S.Usher@uk.ac.ucl.cs		or	UCACMSU@uk.ac.ucl.euclid

--8<-------------- Cut --------------------- Here ------------------------