Improve return data truncate logic (#9254)

* Improve return data truncate logic

* fix: size -> offset + size
This commit is contained in:
Wei Tang 2018-08-07 17:48:25 +08:00 committed by Marek Kotewicz
parent 1e44a62494
commit 0d8001adea

View File

@ -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)
}