From owner-svn-src-all@FreeBSD.ORG Sun Jan 15 20:04:06 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 21875106566C; Sun, 15 Jan 2012 20:04:06 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E515F8FC0A; Sun, 15 Jan 2012 20:04:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0FK45BJ097894; Sun, 15 Jan 2012 20:04:05 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0FK45U8097889; Sun, 15 Jan 2012 20:04:05 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201201152004.q0FK45U8097889@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 15 Jan 2012 20:04:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r230154 - in head: bin/sh tools/regression/bin/sh/builtins X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Jan 2012 20:04:07 -0000 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