[comp.os.minix] bug in diff.c

rmtodd@uokmax.UUCP (Richard Michael Todd) (07/22/87)

Surprising that nobody's noticed this before--the diff.c that recently
appeared on the net (in the MINIX 1.2 files) won't work when compiled with
MINIX cc--the resulting program gives bogus output.  The problem is in the
line in read_line():
	if (p[1] != '\377' && *p != '\n') {
Can you say "non-portable character comparison"? Sure. I knew you could.
Lint can say it too.  Under the MINIX C compiler, p[1] gets sign-extended
and '\377' doesn't when converted to int, so the comparison fails even when
p[1] has 255 (0377) in it.  The quick fix is to change it to read
	if ((p[1]&255) != '\377' && *p != '\n') {
--------------------------------------------------------------------------
Richard Todd
USSnail:820 Annie Court,Norman OK 73069
UUCP: {allegra!cbosgd|ihnp4}!okstate!uokmax!rmtodd