diff options
author | jilles <jilles@FreeBSD.org> | 2013-04-12 15:19:35 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2013-04-12 15:19:35 +0000 |
commit | 8b2029265883067bf67b0fa209dd4f6e47c48e3f (patch) | |
tree | 0aac568cbf8c2959f1e1a7008c5231687838385b | |
parent | fd27383897a40fb960ee449c2c656b991babd97d (diff) | |
download | FreeBSD-src-8b2029265883067bf67b0fa209dd4f6e47c48e3f.zip FreeBSD-src-8b2029265883067bf67b0fa209dd4f6e47c48e3f.tar.gz |
sh: Don't modify exit status when break/continue/return passes !.
This matches what would happen if ! P were to be replaced with
if P; then false; else true; fi.
Example:
f() { ! return 0; }; f
-rw-r--r-- | bin/sh/eval.c | 2 | ||||
-rw-r--r-- | tools/regression/bin/sh/execution/not1.0 | 4 | ||||
-rw-r--r-- | tools/regression/bin/sh/execution/not2.0 | 6 |
3 files changed, 12 insertions, 0 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 0972b10..d3708b3 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -279,6 +279,8 @@ evaltree(union node *n, int flags) break; case NNOT: evaltree(n->nnot.com, EV_TESTED); + if (evalskip) + goto out; exitstatus = !exitstatus; break; diff --git a/tools/regression/bin/sh/execution/not1.0 b/tools/regression/bin/sh/execution/not1.0 new file mode 100644 index 0000000..12c6265 --- /dev/null +++ b/tools/regression/bin/sh/execution/not1.0 @@ -0,0 +1,4 @@ +# $FreeBSD$ + +f() { ! return $1; } +f 0 && ! f 1 diff --git a/tools/regression/bin/sh/execution/not2.0 b/tools/regression/bin/sh/execution/not2.0 new file mode 100644 index 0000000..1b128d0 --- /dev/null +++ b/tools/regression/bin/sh/execution/not2.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +while :; do + ! break + exit 3 +done |