vm: fix typo in MEMCPY handling
This commit is contained in:
parent
931dc6c64f
commit
ab4cd8a990
2 changed files with 5 additions and 1 deletions
|
@ -659,7 +659,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
panic("invalid destination index")
|
||||
}
|
||||
dst := v.estack.Pop().value.(*stackitem.Buffer).Value().([]byte)
|
||||
if sum := si + n; sum < 0 || sum > len(dst) {
|
||||
if sum := di + n; sum < 0 || sum > len(dst) {
|
||||
panic("size is too big")
|
||||
}
|
||||
copy(dst[di:], src[si:si+n])
|
||||
|
|
|
@ -1344,6 +1344,10 @@ func TestMEMCPY(t *testing.T) {
|
|||
buf := stackitem.NewBuffer([]byte{0, 1, 2, 3})
|
||||
runWithArgs(t, prog, stackitem.NewBuffer([]byte{0, 6, 7, 3}), buf, buf, 1, []byte{4, 5, 6, 7}, 2, 2)
|
||||
})
|
||||
t.Run("NonZeroDstIndex", func(t *testing.T) {
|
||||
buf := stackitem.NewBuffer([]byte{0, 1, 2})
|
||||
runWithArgs(t, prog, stackitem.NewBuffer([]byte{0, 6, 7}), buf, buf, 1, []byte{4, 5, 6, 7}, 2, 2)
|
||||
})
|
||||
t.Run("NegativeSize", getTestFuncForVM(prog, nil, stackitem.NewBuffer([]byte{0, 1}), 0, []byte{2}, 0, -1))
|
||||
t.Run("NegativeSrcIndex", getTestFuncForVM(prog, nil, stackitem.NewBuffer([]byte{0, 1}), 0, []byte{2}, -1, 1))
|
||||
t.Run("NegativeDstIndex", getTestFuncForVM(prog, nil, stackitem.NewBuffer([]byte{0, 1}), -1, []byte{2}, 0, 1))
|
||||
|
|
Loading…
Reference in a new issue