forked from TrueCloudLab/neoneo-go
Merge pull request #379 from nspcc-dev/fix/left-with-big-index
vm: do not fault on LEFT with big index
This commit is contained in:
commit
0055701ec0
2 changed files with 7 additions and 2 deletions
|
@ -315,6 +315,9 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
|||
case LEFT:
|
||||
l := int(v.estack.Pop().BigInt().Int64())
|
||||
s := v.estack.Pop().Bytes()
|
||||
if t := len(s); l > t {
|
||||
l = t
|
||||
}
|
||||
v.estack.PushVal(s[:l])
|
||||
case RIGHT:
|
||||
l := int(v.estack.Pop().BigInt().Int64())
|
||||
|
|
|
@ -685,13 +685,15 @@ func TestLEFTGood(t *testing.T) {
|
|||
assert.Equal(t, []byte("ab"), vm.estack.Peek(0).Bytes())
|
||||
}
|
||||
|
||||
func TestLEFTBadLen(t *testing.T) {
|
||||
func TestLEFTGoodLen(t *testing.T) {
|
||||
prog := makeProgram(LEFT)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal([]byte("abcdef"))
|
||||
vm.estack.PushVal(8)
|
||||
vm.Run()
|
||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||
assert.Equal(t, 1, vm.estack.Len())
|
||||
assert.Equal(t, []byte("abcdef"), vm.estack.Peek(0).Bytes())
|
||||
}
|
||||
|
||||
func TestRIGHTBadNoArgs(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue