negative numbers in expr

amos at instable.UUCP amos at instable.UUCP
Wed Feb 25 00:59:24 AEST 1987


Index:	<source directory>/<source file> 4.2BSD

Description:
	Expr doesn't recognize negative numbers as numeric arguments,
	except as the 1st argument to a relational operation (this is
	even more bogous, since non-numeric arguments are compared
	lexically, without warning).
Repeat-By:
	Try: expr -1 + 2; or expr -1 \> -01
	This is most annoying when expr-ing the output of another expr.
Fix:
	Apply the following patch. (This is from the vanilla 4.3 sources,
	but other versions - maybe even sysV? - are similar).

*** /usr/src/bin/expr.y	Mon Mar  3 16:42:15 1986
--- /tmp/expr.y	Tue Feb 24 16:30:24 1987
***************
*** 94,100
  char *rel(op, r1, r2) register char *r1, *r2; {
  	register long i;
  
! 	if(ematch(r1, "-*[0-9]*$") && ematch(r2, "-*[0-9]*$"))
  		i = atol(r1) - atol(r2);
  	else
  		i = strcmp(r1, r2);

--- 94,100 -----
  char *rel(op, r1, r2) register char *r1, *r2; {
  	register long i;
  
! 	if(ematch(r1, "-*[0-9]*$") && ematch(r2, "[0-9]*$"))
  		i = atol(r1) - atol(r2);
  	else
  		i = strcmp(r1, r2);
***************
*** 113,119
  	long i1, i2;
  	register char *rv;
  
! 	if(!(ematch(r1, "-*[0-9]*$") && ematch(r2, "-*[0-9]*$")))
  		yyerror("non-numeric argument");
  	i1 = atol(r1);
  	i2 = atol(r2);

--- 113,119 -----
  	long i1, i2;
  	register char *rv;
  
! 	if(!(ematch(r1, "[0-9]*$") && ematch(r2, "[0-9]*$")))
  		yyerror("non-numeric argument");
  	i1 = atol(r1);
  	i2 = atol(r2);
-- 
	Amos Shapir
National Semiconductor (Israel)
6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel
(011-972) 52-522261  amos%nsta at nsc.com 34.48'E 32.10'N



More information about the Comp.bugs.4bsd.ucb-fixes mailing list