Skip to content

Commit

Permalink
fixed off-by-one error in the assembler's typeDig() and improved unit…
Browse files Browse the repository at this point in the history
… test (algorand#3056)
  • Loading branch information
algoidurovic authored and cce committed Oct 28, 2021
1 parent b00d95e commit 0584129
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,8 @@ func typeDig(ops *OpStream, args []string) (StackTypes, StackTypes) {
idx := len(ops.typeStack) - depth
if idx >= 0 {
returns[len(returns)-1] = ops.typeStack[idx]
for i := idx + 1; i < len(ops.typeStack); i++ {
returns[i-idx-1] = ops.typeStack[i]
for i := idx; i < len(ops.typeStack); i++ {
returns[i-idx] = ops.typeStack[i]
}
}
return anys, returns
Expand Down
3 changes: 2 additions & 1 deletion data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,8 @@ func TestDigAsm(t *testing.T) {

// Confirm that digging something out does not ruin our knowledge about the types in the middle
testProg(t, "int 1; byte 0x1234; byte 0x1234; dig 2; dig 3; +; pop; +", AssemblerMaxVersion,
expect{6, "+ arg 1..."})
expect{8, "+ arg 1..."})
testProg(t, "int 3; pushbytes \"123456\"; int 1; dig 2; substring3", AssemblerMaxVersion)

}

Expand Down

0 comments on commit 0584129

Please sign in to comment.