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
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to