Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shortcut for empty memload/memstore #221

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ function trap (err) {
* @return {String}
*/
function subMemUsage (runState, offset, length) {
// abort if no usage
// YP (225): access with zero length will not extend the memory
if (!length) return

// hacky: if the dataOffset is larger than the largest safeInt then just
Expand Down Expand Up @@ -907,6 +907,12 @@ function subMemUsage (runState, offset, length) {
function memLoad (runState, offset, length) {
// check to see if we have enougth gas for the mem read
subMemUsage(runState, offset, length)

// shortcut
if (length === 0) {
return new Buffer('')
}

var loaded = runState.memory.slice(offset, offset + length)
// fill the remaining lenth with zeros
for (var i = loaded.length; i < length; i++) {
Expand All @@ -928,6 +934,11 @@ function memStore (runState, offset, val, valOffset, length, skipSubMem) {
subMemUsage(runState, offset, length)
}

// shortcut
if (length === 0) {
return
}

var valLength = Math.min(val.length, length)

// read max possible from the value
Expand Down