aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-07-11 11:28:10 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-07-11 11:28:10 -0700
commit98297e5234360c3e5e6a70f26b66904a6d94a39f (patch)
tree01e627cc9be08653e71c73926deb3b34ead10c2b
parent3915faf3820ad25f326c98c1f7042f9e2670202c (diff)
Teach while loops to not hang forever with no-execute
Fixes #1543
-rw-r--r--exec.cpp1
-rw-r--r--parse_execution.cpp6
-rw-r--r--tests/test1.in4
-rw-r--r--tests/test1.out1
4 files changed, 12 insertions, 0 deletions
diff --git a/exec.cpp b/exec.cpp
index ae4c496d..f2d168a9 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -592,6 +592,7 @@ void exec_job(parser_t &parser, job_t *j)
CHECK(j,);
CHECK_BLOCK();
+ /* If fish was invoked with -n or --no-execute, then no_exec will be set and we do nothing. */
if (no_exec)
{
return;
diff --git a/parse_execution.cpp b/parse_execution.cpp
index 03066ba7..22c13285 100644
--- a/parse_execution.cpp
+++ b/parse_execution.cpp
@@ -673,6 +673,12 @@ parse_execution_result_t parse_execution_context_t::run_while_statement(const pa
break;
}
}
+
+ /* no_exec means that fish was invoked with -n or --no-execute. If set, we allow the loop to not-execute once so its contents can be checked, and then break */
+ if (no_exec)
+ {
+ break;
+ }
}
/* Done */
diff --git a/tests/test1.in b/tests/test1.in
index 4de8d6b1..424b931a 100644
--- a/tests/test1.in
+++ b/tests/test1.in
@@ -123,6 +123,10 @@ echo -e Catch your breath
echo -e 'abc\x21def'
echo -e 'abc\x211def'
+# Make sure while loops don't run forever with no-exec (#1543)
+echo "Checking for infinite loops in no-execute"
+echo "while true; end" | ../fish --no-execute
+
function always_fails
if true
return 1
diff --git a/tests/test1.out b/tests/test1.out
index 85a6d225..e79d75bc 100644
--- a/tests/test1.out
+++ b/tests/test1.out
@@ -37,4 +37,5 @@ abc
Catch your breath
abc!def
abc!1def
+Checking for infinite loops in no-execute
1