Skip to content

Commit

Permalink
Merge pull request #85 from BitcoinSchema/fix-out-of-range
Browse files Browse the repository at this point in the history
fix: index out of range
  • Loading branch information
mrz1836 authored Apr 7, 2024
2 parents 8e4b95c + 15600f0 commit aadcf17
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ord/ord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

0 comments on commit aadcf17

Please sign in to comment.