🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.4bsd
Article #11

Re: Bug in "comm" utility

#11
From: Maarten Litmaath
Date: Wed, 14 Jun 1989 19:00
50 lines
1507 bytes
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
Technical Details
Message-ID: <2758@piraat.cs.vu.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart
References: <10396@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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