mirror of
https://github.com/status-im/op-geth.git
synced 2025-02-06 20:03:58 +00:00
Right pad bytes to prevent future programmers making bugs
This commit is contained in:
parent
f4e9638867
commit
abce6804a0
10
vm/memory.go
10
vm/memory.go
@ -1,6 +1,10 @@
|
|||||||
package vm
|
package vm
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
)
|
||||||
|
|
||||||
type Memory struct {
|
type Memory struct {
|
||||||
store []byte
|
store []byte
|
||||||
@ -11,7 +15,8 @@ func NewMemory() *Memory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Memory) Set(offset, size uint64, value []byte) {
|
func (m *Memory) Set(offset, size uint64, value []byte) {
|
||||||
if len(value) > 0 {
|
value = common.RightPadBytes(value, int(size))
|
||||||
|
|
||||||
totSize := offset + size
|
totSize := offset + size
|
||||||
lenSize := uint64(len(m.store) - 1)
|
lenSize := uint64(len(m.store) - 1)
|
||||||
if totSize > lenSize {
|
if totSize > lenSize {
|
||||||
@ -25,7 +30,6 @@ func (m *Memory) Set(offset, size uint64, value []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
copy(m.store[offset:offset+size], value)
|
copy(m.store[offset:offset+size], value)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Memory) Resize(size uint64) {
|
func (m *Memory) Resize(size uint64) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user