Skip to content

Commit

Permalink
poller: use empty() instead of mem::zeroed() to initialize EPollEvent…
Browse files Browse the repository at this point in the history
… array

While mem::zeroed() is currently a valid initial value for EPollEvent,
but there is no guarantee this will remain this way. Use the empty()
method instead to make sure the value remains valid.
  • Loading branch information
Gnurou committed Apr 19, 2024
1 parent 63cd8a6 commit a0da824
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/src/device/poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{
collections::BTreeMap,
fs::File,
io::{self, Read, Write},
mem,
sync::atomic::{AtomicUsize, Ordering},
sync::Arc,
task::Wake,
Expand Down Expand Up @@ -46,8 +45,12 @@ pub struct PollEvents {
impl PollEvents {
fn new() -> Self {
PollEvents {
// Safe because that's the rightful initial state for epoll_event.
events: unsafe { mem::zeroed() },
events: [
EpollEvent::empty(),
EpollEvent::empty(),
EpollEvent::empty(),
EpollEvent::empty(),
],
nb_events: 0,
cur_event: 0,
}
Expand Down

0 comments on commit a0da824

Please sign in to comment.