Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jan 2012 20:04:05 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r230154 - in head: bin/sh tools/regression/bin/sh/builtins
Message-ID:  <201201152004.q0FK45U8097889@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Jan 15 20:04:05 2012
New Revision: 230154
URL: http://svn.freebsd.org/changeset/base/230154

Log:
  sh: Fix two bugs with case and exit status:
  
  * If no pattern is matched, POSIX says the exit status shall be 0 (even if
    there are command substitutions).
  * If a pattern is matched and there are no command substitutions, the first
    command should see the $? from before the case command, not always 0.

Added:
  head/tools/regression/bin/sh/builtins/case14.0   (contents, props changed)
  head/tools/regression/bin/sh/builtins/case15.0   (contents, props changed)
  head/tools/regression/bin/sh/builtins/case16.0   (contents, props changed)
Modified:
  head/bin/sh/eval.c

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c	Sun Jan 15 19:45:23 2012	(r230153)
+++ head/bin/sh/eval.c	Sun Jan 15 20:04:05 2012	(r230154)
@@ -378,7 +378,6 @@ evalcase(union node *n, int flags)
 	setstackmark(&smark);
 	arglist.lastp = &arglist.list;
 	oexitstatus = exitstatus;
-	exitstatus = 0;
 	expandarg(n->ncase.expr, &arglist, EXP_TILDE);
 	for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
 		for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
@@ -392,11 +391,14 @@ evalcase(union node *n, int flags)
 						return (NULL);
 					cp = cp->nclist.next;
 				}
+				if (cp->nclist.body == NULL)
+					exitstatus = 0;
 				return (cp->nclist.body);
 			}
 		}
 	}
 	popstackmark(&smark);
+	exitstatus = 0;
 	return (NULL);
 }
 

Added: head/tools/regression/bin/sh/builtins/case14.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/case14.0	Sun Jan 15 20:04:05 2012	(r230154)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+case `false` in
+no) exit 3 ;;
+esac

Added: head/tools/regression/bin/sh/builtins/case15.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/case15.0	Sun Jan 15 20:04:05 2012	(r230154)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+case x in
+`false`) exit 3 ;;
+esac

Added: head/tools/regression/bin/sh/builtins/case16.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/case16.0	Sun Jan 15 20:04:05 2012	(r230154)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+f() { return 42; }
+f
+case x in
+x) [ $? = 42 ] ;;
+esac



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201152004.q0FK45U8097889>