diff options
Diffstat (limited to 'core/vm/memory.go')
-rw-r--r-- | core/vm/memory.go | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/core/vm/memory.go b/core/vm/memory.go index f5984d82f..a80a6aae0 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -15,28 +15,32 @@ func NewMemory() *Memory { } func (m *Memory) Set(offset, size uint64, value []byte) { - // If the length of the store is 0 this is a complete failure - // memory size is set prior to calling this method so enough size - // should always be available. - if len(m.store) == 0 { + // length of store may never be less than offset + size. + // The store should be resized PRIOR to setting the memory + if size > uint64(len(m.store)) { panic("INVALID memory: store empty") } - value = common.RightPadBytes(value, int(size)) + // It's possible the offset is greater than 0 and size equals 0. This is because + // the calcMemSize (common.go) could potentially return 0 when size is zero (NO-OP) + if size > 0 { + copy(m.store[offset:offset+size], common.RightPadBytes(value, int(size))) + } - totSize := offset + size - lenSize := int64(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...) + /* + 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) + */ } func (m *Memory) Resize(size uint64) { |