Xref: utzoo comp.bugs.4bsd:1305 comp.bugs.sys5:1014 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.bugs.4bsd,comp.bugs.sys5 Subject: Re: Bug in "comm" utility Keywords: UNIX "comm" bug fix Message-ID: <2758@piraat.cs.vu.nl> Date: 14 Jun 89 19:00:35 GMT References: <10396@smoke.BRL.MIL> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 50 gwyn@smoke.BRL.MIL (Doug Gwyn) writes: [quick kludge deleted, sorry Doug] Why didn't you change compare()? The new version should be faster too! /* * old version */ compare(a,b) char *a,*b; { register char *ra,*rb; /* * it's non-portable to move a pointer one position before the begin * of the array: on segmented architectures &array[0] could be the * start of a segment */ ra = --a; rb = --b; while(*++ra == *++rb) /* pre-increment instructions?! */ if(*ra == '\0') return(0); if(*ra < *rb) return(1); return(2); } /* * new version - according to the ANSI standard a pointer may be moved one * position PAST the end of the array */ int compare(a, b) char *a, *b; { register char *ra, *rb; ra = a; rb = b; while (*ra == *rb++) /* post-increment instructions!! */ if (!*ra++) return 0; return *ra < *--rb ? 1 : 2; } -- "I HATE arbitrary limits, especially when |Maarten Litmaath @ VU Amsterdam: they're small." (Stephen Savitzky) |maart@cs.vu.nl, mcvax!botter!maart