1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-25 17:33:28 +04:00

Don't create len=0 slices in iov

This commit is contained in:
Jiajie Chen 2020-03-24 18:44:25 +08:00
parent 36a1ed98c8
commit c0be01319b

View File

@ -1644,6 +1644,8 @@ impl IoVecs {
readv: bool, readv: bool,
) -> Result<Self, SysError> { ) -> Result<Self, SysError> {
let iovs = vm.check_read_array(iov_ptr, iov_count)?.to_vec(); let iovs = vm.check_read_array(iov_ptr, iov_count)?.to_vec();
let mut slices = vec![];
slices.reserve(iovs.len());
// check all bufs in iov // check all bufs in iov
for iov in iovs.iter() { for iov in iovs.iter() {
// skip empty iov // skip empty iov
@ -1655,11 +1657,8 @@ impl IoVecs {
} else { } else {
vm.check_read_array(iov.base, iov.len)?; vm.check_read_array(iov.base, iov.len)?;
} }
slices.push(slice::from_raw_parts_mut(iov.base, iov.len));
} }
let slices = iovs
.iter()
.map(|iov| slice::from_raw_parts_mut(iov.base, iov.len))
.collect();
Ok(IoVecs(slices)) Ok(IoVecs(slices))
} }