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,15 +119,20 @@ 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); }
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user