From 6e0f89a4b4415e927097ab2c0e3caf4ccb26152b Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Fri, 12 Apr 2013 15:19:35 +0000 Subject: [PATCH] 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 --- bin/sh/eval.c | 2 ++ tools/regression/bin/sh/execution/not1.0 | 4 ++++ tools/regression/bin/sh/execution/not2.0 | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 tools/regression/bin/sh/execution/not1.0 create mode 100644 tools/regression/bin/sh/execution/not2.0 diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 0972b105a2ed..d3708b3bd140 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 000000000000..12c6265a9282 --- /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 000000000000..1b128d096716 --- /dev/null +++ b/tools/regression/bin/sh/execution/not2.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +while :; do + ! break + exit 3 +done