🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.usg
Article #279

"regexp.h" does an incorrect comparison of a "char" against 255

#279
From: Guy Harris
Date: Wed, 26 Mar 1986 05:04
83 lines
2167 bytes
"regexp.h" compares a "char" expression against 255.  On a machine with
8-bit signed "char"s and a correct C compiler, this comparison will always
indicate that the value of the expression is not equal to 255.  What it
intended to do was mask the character with 0377 and then do the comparison.
Here's a context diff of the fix, with two free "lint" fixes courtesy of Doug
Gwyn:

*** /archbeluga/s5r2/usr/include/regexp.h	Sat Nov  5 09:42:54 1983
--- /tmp/regexp.h	Tue Mar 25 20:59:36 1986
***************
*** 220,225
  			*ep++ = c;
  		}
  	}
  }
  
  step(p1, p2)

--- 220,226 -----
  			*ep++ = c;
  		}
  	}
+ 	/*NOTREACHED*/
  }
  
  step(p1, p2)
***************
*** 400,405
  
  		}
  	}
  }
  
  static

--- 401,407 -----
  
  		}
  	}
+ 	/*NOTREACHED*/
  }
  
  static
***************
*** 406,411
  getrnge(str)
  register char *str;
  {
  	low = *str++ & 0377;
  	size = (*str == 255)? 20000: (*str &0377) - low;
  }

--- 408,415 -----
  getrnge(str)
  register char *str;
  {
+ 	register int sizecode;
+ 
  	low = *str++ & 0377;
  	sizecode = *str & 0377;
  	if (sizecode == 255)
***************
*** 407,411
  register char *str;
  {
  	low = *str++ & 0377;
! 	size = (*str == 255)? 20000: (*str &0377) - low;
  }

--- 411,419 -----
  	register int sizecode;
  
  	low = *str++ & 0377;
! 	sizecode = *str & 0377;
! 	if (sizecode == 255)
! 		size = 20000;
! 	else
! 		size = sizecode - low;
  }
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.arpa	(yes, really)
Technical Details
Message-ID: <3404@sun.uucp>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!decwrl!sun!guy

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!decwrl!sun!guy
From: guy@sun.uucp (Guy Harris)
Newsgroups: net.bugs.usg
Subject: "regexp.h" does an incorrect comparison of a "char" against 255
Message-ID: <3404@sun.uucp>
Date: Wed, 26-Mar-86 00:04:49 EST
Article-I.D.: sun.3404
Posted: Wed Mar 26 00:04:49 1986
Date-Received: Thu, 27-Mar-86 07:24:15 EST
Distribution: net
Organization: Sun Microsystems, Inc.
Lines: 83