aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-21 03:37:56 +0800
committerobscuren <geffobscura@gmail.com>2015-03-21 03:37:56 +0800
commitabce6804a085087770be587e039fd4669d5eac26 (patch)
treee2ca07be1981c7ac38227e7d5aeb94870affa37c
parentf4e9638867f5dab01eeb6db5fdbd85737a11fbd6 (diff)
downloaddexon-abce6804a085087770be587e039fd4669d5eac26.tar
dexon-abce6804a085087770be587e039fd4669d5eac26.tar.gz
dexon-abce6804a085087770be587e039fd4669d5eac26.tar.bz2
dexon-abce6804a085087770be587e039fd4669d5eac26.tar.lz
dexon-abce6804a085087770be587e039fd4669d5eac26.tar.xz
dexon-abce6804a085087770be587e039fd4669d5eac26.tar.zst
dexon-abce6804a085087770be587e039fd4669d5eac26.zip
Right pad bytes to prevent future programmers making bugs
-rw-r--r--vm/memory.go32
1 files changed, 18 insertions, 14 deletions
diff --git a/vm/memory.go b/vm/memory.go
index 2a1e6e1b9..dd47fa1b5 100644
--- a/vm/memory.go
+++ b/vm/memory.go
@@ -1,6 +1,10 @@
package vm
-import "fmt"
+import (
+ "fmt"
+
+ "github.com/ethereum/go-ethereum/common"
+)
type Memory struct {
store []byte
@@ -11,21 +15,21 @@ func NewMemory() *Memory {
}
func (m *Memory) Set(offset, size uint64, value []byte) {
- if len(value) > 0 {
- totSize := offset + size
- lenSize := uint64(len(m.store) - 1)
- if totSize > lenSize {
- // Calculate the diff between the sizes
- diff := totSize - lenSize
- if diff > 0 {
- // Create a new empty slice and append it
- newSlice := make([]byte, diff-1)
- // Resize slice
- m.store = append(m.store, newSlice...)
- }
+ value = common.RightPadBytes(value, int(size))
+
+ totSize := offset + size
+ lenSize := uint64(len(m.store) - 1)
+ if totSize > lenSize {
+ // Calculate the diff between the sizes
+ diff := totSize - lenSize
+ if diff > 0 {
+ // Create a new empty slice and append it
+ newSlice := make([]byte, diff-1)
+ // Resize slice
+ m.store = append(m.store, newSlice...)
}
- copy(m.store[offset:offset+size], value)
}
+ copy(m.store[offset:offset+size], value)
}
func (m *Memory) Resize(size uint64) {