Permalink
Browse files

Fix crash on empty for expression ((;;)) (#123)

  • Loading branch information...
Yorwba authored and andychu committed May 28, 2018
1 parent fee4c2e commit 57187b485b485036b8666861118fa78d4e8f451d
Showing with 25 additions and 6 deletions.
  1. +10 −6 core/cmd_exec.py
  2. +15 −0 spec/for-expr.test.sh
View
@@ -997,17 +997,20 @@ def _Dispatch(self, node, fork_external):
elif node.tag == command_e.ForExpr:
status = 0
self.arith_ev.Eval(node.init)
init, cond, body, update = node.init, node.cond, node.body, node.update
if init:
self.arith_ev.Eval(init)
self.loop_level += 1
try:
while True:
b = self.arith_ev.Eval(node.cond)
if not b:
break
if cond:
b = self.arith_ev.Eval(cond)
if not b:
break
try:
status = self._Execute(node.body)
status = self._Execute(body)
except _ControlFlow as e:
if e.IsBreak():
status = 0
@@ -1017,7 +1020,8 @@ def _Dispatch(self, node, fork_external):
else: # return needs to pop up more
raise
self.arith_ev.Eval(node.update)
if update:
self.arith_ev.Eval(update)
finally:
self.loop_level -= 1
View
@@ -42,3 +42,18 @@ done # A construct borrowed from ksh93.
## N-I mksh status: 1
## N-I mksh stdout-json: ""
### For loop with empty head
a=1
for ((;;)); do
if test $a = 4; then
break
fi
echo $((a++))
done # A construct borrowed from ksh93.
## status: 0
## STDOUT:
1
2
3
## N-I mksh status: 1
## N-I mksh stdout-json: ""

0 comments on commit 57187b4

Please sign in to comment.