diff --git a/ord/ord.go b/ord/ord.go index c0767d9..dc2d27b 100644 --- a/ord/ord.go +++ b/ord/ord.go @@ -67,13 +67,17 @@ func ScriptFromTape(tape bpu.Tape) (ordScript []bpu.Cell) { endIdx := 0 // Find OP_IF and OP_ENDIF indexes for idx, c := range tape.Cell { - if idx > 0 && c.Ops != nil && *c.Ops == "OP_IF" && *tape.Cell[idx-1].Op == 0 { + if idx > 0 && c.Ops != nil && *c.Ops == "OP_IF" && tape.Cell[idx-1].Op != nil && *tape.Cell[idx-1].Op == 0 { startIdx = idx - 1 } if startIdx > 0 && c.Ops != nil && *c.Ops == "OP_ENDIF" { endIdx = idx + break } } + if startIdx > endIdx { + return []bpu.Cell{} + } return tape.Cell[startIdx:endIdx] }