🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.ghostscript.bug
Article #211

string comparisons

#211
From: Hal Peterson
Date: Tue, 25 Jul 1989 21:32
58 lines
2117 bytes
I am using GhostScript 1.3 with the patches supplied by Tony Li and
snoopy's fix to interp.c.  My platform is an 8MB Sun 3/50 running
SunOS 3.5.  I am compiling with GCC 1.35.

String comparison was not producing lexical ordering.  The function
bytes_compare() was comparing string lengths first rather than last,
which resulted in the program

    %!
    (aardvark) (zebra) gt ==

returning true, which is wrong; aardvark does not come after zebra in
the dictionary.
--
Hal Peterson			Domain:  hrp@cray.com
Cray Research			Old style:  hrp%cray.com@uc.msc.umn.edu
1440 Northland Dr.		UUCP:  uunet!cray!hrp
Mendota Hts, MN  55120  USA	Telephone:  +1 612 681 3145

========================================================================
*** iutil-DIST.c	Tue Jun 20 07:07:59 1989
--- iutil.c	Tue Jul 25 16:20:33 1989
***************
*** 107,120 ****
  int
  bytes_compare(byte *s1, uint len1, byte *s2, uint len2)
  {	register uint len = len1;
! 	if ( len != len2 ) return (len < len2 ? -1 : 1);
! 	   {	register byte *p1 = s1;
! 		register byte *p2 = s2;
! 		while ( len-- )
! 			if ( *p1++ != *p2++ )
! 				return (p1[-1] < p2[-1] ? -1 : 1);
  	   }
! 	return 0;
  }
  
  /* Compute a hash for a string */
--- 107,125 ----
  int
  bytes_compare(byte *s1, uint len1, byte *s2, uint len2)
  {	register uint len = len1;
! 	if (len > len2) len = len2;
! 	/* Compare the contents */
! 	while (len--)
! 	   {	if (*s1 < *s2) return -1;
! 		else if (*(s1++) > *(s2++)) return 1;
  	   }
! 	/* Contents are identical; try the lengths. */
! 	if (len1 > len2)
! 		return 1;
! 	else if (len1 < len2)
! 		return -1;
! 	else
! 		return 0;
  }
  
  /* Compute a hash for a string */
Technical Details
Message-ID: <8907252132.AA14540@rothko.cray.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!boring.cray.com!hrp

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!boring.cray.com!hrp
From: hrp@boring.cray.com (Hal Peterson)
Newsgroups: gnu.ghostscript.bug
Subject: string comparisons
Message-ID: <8907252132.AA14540@rothko.cray.com>
Date: 25 Jul 89 21:32:39 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 58