Skip to content

Commit

Permalink
Merge pull request #840 from memorysafety/fix-clippy
Browse files Browse the repository at this point in the history
Fix clippy diagnostics
  • Loading branch information
squell authored Apr 8, 2024
2 parents ebd3e60 + 266d07c commit cd8644d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/exec/use_pty/pipe/ring_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ impl RingBuffer {
self.len == self.storage.len()
}

// rustc 1.77.1 clippy gives false diagnostics, https://github.com/rust-lang/rust-clippy/issues/12519
#[allow(clippy::unused_io_amount)]
pub(super) fn insert<R: Read>(&mut self, read: &mut R) -> io::Result<usize> {
let inserted_len = if self.is_empty() {
// Case 1.1. The buffer is empty, meaning that there are two unfilled slices in
Expand Down Expand Up @@ -61,6 +63,8 @@ impl RingBuffer {
self.len == 0
}

// rustc 1.77.1 clippy gives false diagnostics, https://github.com/rust-lang/rust-clippy/issues/12519
#[allow(clippy::unused_io_amount)]
pub(super) fn remove<W: Write>(&mut self, write: &mut W) -> io::Result<usize> {
let removed_len = if self.is_full() {
// Case 2.1. The buffer is full, meaning that there are two filled slices in `storage`:
Expand Down
1 change: 1 addition & 0 deletions src/su/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl SuAction {
}

#[cfg(test)]
#[allow(clippy::result_large_err)]
pub fn try_into_run(self) -> Result<SuRunOptions, Self> {
if let Self::Run(v) = self {
Ok(v)
Expand Down
1 change: 1 addition & 0 deletions src/sudo/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl SudoAction {
}

#[cfg(test)]
#[allow(clippy::result_large_err)]
pub fn try_into_run(self) -> Result<SudoRunOptions, Self> {
if let Self::Run(v) = self {
Ok(v)
Expand Down
14 changes: 7 additions & 7 deletions src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,13 @@ pub fn escape_os_str_lossy(s: &std::ffi::OsStr) -> String {
s.to_string_lossy().escape_default().collect()
}

pub fn make_zeroed_sigaction() -> libc::sigaction {
// SAFETY: since sigaction is a C struct, all-zeroes is a valid representation
// We cannot use a "literal struct" initialization method since the exact representation
// of libc::sigaction is not fixed, see e.g. https://github.com/memorysafety/sudo-rs/issues/829
unsafe { std::mem::zeroed() }
}

#[cfg(test)]
mod tests {
use std::{
Expand Down Expand Up @@ -894,10 +901,3 @@ mod tests {
assert_eq!(status.exit_status(), Some(0));
}
}

pub fn make_zeroed_sigaction() -> libc::sigaction {
// SAFETY: since sigaction is a C struct, all-zeroes is a valid representation
// We cannot use a "literal struct" initialization method since the exact representation
// of libc::sigaction is not fixed, see e.g. https://github.com/memorysafety/sudo-rs/issues/829
unsafe { std::mem::zeroed() }
}
1 change: 1 addition & 0 deletions src/visudo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ fn run(file_arg: Option<&str>, perms: bool, owner: bool) -> io::Result<()> {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&tmp_path)?;

tmp_file.set_permissions(Permissions::from_mode(0o700))?;
Expand Down

0 comments on commit cd8644d

Please sign in to comment.