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

Commit

Permalink
Improve return data truncate logic (#9254)
Browse files Browse the repository at this point in the history
* Improve return data truncate logic

* fix: size -> offset + size
  • Loading branch information
sorpaas authored and debris committed Aug 7, 2018
1 parent 1e44a62 commit 0d8001a
Showing 1 changed file with 10 additions and 5 deletions.
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();
}

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

0 comments on commit 0d8001a

Please sign in to comment.