Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Improve return data truncate logic #9254

Merged
merged 2 commits into from
Aug 7, 2018
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
15 changes: 10 additions & 5 deletions ethcore/evm/src/interpreter/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,19 @@ impl Memory for Vec<u8> {
fn into_return_data(mut self, offset: U256, size: U256) -> ReturnData {
let mut offset = offset.low_u64() as usize;
let size = size.low_u64() as usize;

if !is_valid_range(offset, size) {
return ReturnData::empty()
return ReturnData::empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid redundant ;

}

if self.len() - size > MAX_RETURN_WASTE_BYTES {
{ let _ = self.drain(..offset); }
self.truncate(size);
self.shrink_to_fit();
offset = 0;
if offset == 0 {
self.truncate(size);
self.shrink_to_fit();
} else {
self = self[offset..(offset + size)].to_vec();
offset = 0;
}
}
ReturnData::new(self, offset, size)
}
Expand Down