Improve return data truncate logic (#9254)
* Improve return data truncate logic * fix: size -> offset + size
This commit is contained in:
parent
1e44a62494
commit
0d8001adea
@ -119,14 +119,19 @@ impl Memory for Vec<u8> {
|
|||||||
fn into_return_data(mut self, offset: U256, size: U256) -> ReturnData {
|
fn into_return_data(mut self, offset: U256, size: U256) -> ReturnData {
|
||||||
let mut offset = offset.low_u64() as usize;
|
let mut offset = offset.low_u64() as usize;
|
||||||
let size = size.low_u64() as usize;
|
let size = size.low_u64() as usize;
|
||||||
|
|
||||||
if !is_valid_range(offset, size) {
|
if !is_valid_range(offset, size) {
|
||||||
return ReturnData::empty()
|
return ReturnData::empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.len() - size > MAX_RETURN_WASTE_BYTES {
|
if self.len() - size > MAX_RETURN_WASTE_BYTES {
|
||||||
{ let _ = self.drain(..offset); }
|
if offset == 0 {
|
||||||
self.truncate(size);
|
self.truncate(size);
|
||||||
self.shrink_to_fit();
|
self.shrink_to_fit();
|
||||||
offset = 0;
|
} else {
|
||||||
|
self = self[offset..(offset + size)].to_vec();
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ReturnData::new(self, offset, size)
|
ReturnData::new(self, offset, size)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user