Skip to content

Commit

Permalink
If buffer is too small, just use the first part of it.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Jun 12, 2024
1 parent 6241775 commit 874cd08
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/device/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::transport::Transport;
use crate::volatile::{volread, volwrite, ReadOnly, VolatileReadable, WriteOnly};
use crate::Result;
use alloc::boxed::Box;
use core::cmp::min;
use core::ptr::{addr_of, NonNull};
use zerocopy::{AsBytes, FromBytes, FromZeroes};

Expand Down Expand Up @@ -112,8 +113,8 @@ impl<H: Hal, T: Transport> VirtIOInput<H, T> {
volwrite!(self.config, select, select as u8);
volwrite!(self.config, subsel, subsel);
size = volread!(self.config, size);
for i in 0..size {
let i = usize::from(i);
let size_to_copy = min(usize::from(size), out.len());
for i in 0..size_to_copy {
out[i] = addr_of!((*self.config.as_ptr()).data[i]).vread();
}
}
Expand Down

0 comments on commit 874cd08

Please sign in to comment.