From c1a6e47f38f2847b1cac108fd88252670b42e94c Mon Sep 17 00:00:00 2001 From: "Owain G. Ainsworth" Date: Fri, 14 Mar 2014 14:52:22 +0000 Subject: [PATCH] Conditionals must not straddle two scripts. Found by tests dhill is working on. We checked that ifs were closed at the end of execution but not at script switching time, we now move this to just after finishing a single script. --- script.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/script.go b/script.go index 3fe74c3a..23e1fdf5 100644 --- a/script.go +++ b/script.go @@ -583,10 +583,6 @@ func (s *Script) CheckErrorCondition() (err error) { })) err = StackErrScriptFailed } - if err == nil && len(s.condStack) != 1 { - // conditional execution stack context left active - err = StackErrMissingEndif - } return err } @@ -625,6 +621,11 @@ func (m *Script) Step() (done bool, err error) { // prepare for next instruction m.scriptoff++ if m.scriptoff >= len(m.scripts[m.scriptidx]) { + // Illegal to have an `if' that straddles two scripts. + if err == nil && len(m.condStack) != 1 { + return false, StackErrMissingEndif + } + m.numOps = 0 // number of ops is per script. m.scriptoff = 0 if m.scriptidx == 0 && m.bip16 {