MCPcopy Create free account
hub / github.com/chain/Core / opSubstr

Function opSubstr

protocol/vm/splice.go:31–68  ·  view source on GitHub ↗
(vm *virtualMachine)

Source from the content-addressed store, hash-verified

29}
30
31func opSubstr(vm *virtualMachine) error {
32 err := vm.applyCost(4)
33 if err != nil {
34 return err
35 }
36 size, err := vm.popInt64(true)
37 if err != nil {
38 return err
39 }
40 if size < 0 {
41 return ErrBadValue
42 }
43 err = vm.applyCost(size)
44 if err != nil {
45 return err
46 }
47 vm.deferCost(-size)
48 offset, err := vm.popInt64(true)
49 if err != nil {
50 return err
51 }
52 if offset < 0 {
53 return ErrBadValue
54 }
55 str, err := vm.pop(true)
56 if err != nil {
57 return err
58 }
59 end, ok := checked.AddInt64(offset, size)
60 if !ok || end > int64(len(str)) {
61 return ErrBadValue
62 }
63 err = vm.push(str[offset:end], true)
64 if err != nil {
65 return err
66 }
67 return nil
68}
69
70func opLeft(vm *virtualMachine) error {
71 err := vm.applyCost(4)

Callers

nothing calls this directly

Calls 6

applyCostMethod · 0.80
popInt64Method · 0.80
deferCostMethod · 0.80
popMethod · 0.80
AddInt64Method · 0.80
pushMethod · 0.80

Tested by

no test coverage detected