svn commit: r201259 - in head: bin/sh tools/regression/bin/sh/expansion

Jilles Tjoelker jilles at FreeBSD.org
Wed Dec 30 15:59:41 UTC 2009


Author: jilles
Date: Wed Dec 30 15:59:40 2009
New Revision: 201259
URL: http://svn.freebsd.org/changeset/base/201259

Log:
  sh: arith: Return only 0 and 1 from && and ||.
  
  This agrees with C, POSIX and other shells.

Added:
  head/tools/regression/bin/sh/expansion/arith1.0   (contents, props changed)
Modified:
  head/bin/sh/arith.y

Modified: head/bin/sh/arith.y
==============================================================================
--- head/bin/sh/arith.y	Wed Dec 30 15:44:36 2009	(r201258)
+++ head/bin/sh/arith.y	Wed Dec 30 15:59:40 2009	(r201259)
@@ -85,9 +85,9 @@ expr:
 	ARITH_LPAREN expr ARITH_RPAREN
 		{ $$ = $2; } |
 	expr ARITH_OR expr
-		{ $$ = $1 ? $1 : $3 ? $3 : 0; } |
+		{ $$ = $1 || $3; } |
 	expr ARITH_AND expr
-		{ $$ = $1 ? ( $3 ? $3 : 0 ) : 0; } |
+		{ $$ = $1 && $3; } |
 	expr ARITH_BOR expr
 		{ $$ = $1 | $3; } |
 	expr ARITH_BXOR expr

Added: head/tools/regression/bin/sh/expansion/arith1.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/expansion/arith1.0	Wed Dec 30 15:59:40 2009	(r201259)
@@ -0,0 +1,30 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+	if [ $(($1)) != $2 ]; then
+		failures=$((failures+1))
+		echo "For $1, expected $2 actual $(($1))"
+	fi
+}
+
+check "0&&0" 0
+check "1&&0" 0
+check "0&&1" 0
+check "1&&1" 1
+check "2&&2" 1
+check "1&&2" 1
+check "1<<40&&1<<40" 1
+check "1<<40&&4" 1
+
+check "0||0" 0
+check "1||0" 1
+check "0||1" 1
+check "1||1" 1
+check "2||2" 1
+check "1||2" 1
+check "1<<40||1<<40" 1
+check "1<<40||4" 1
+
+exit $((failures != 0))


More information about the svn-src-head mailing list