Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy diagnostics #840

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -420,7 +420,7 @@
pub struct Group {
pub gid: GroupId,
pub name: String,
pub passwd: String,

Check warning on line 423 in src/system/mod.rs

View workflow job for this annotation

GitHub Actions / build-and-test-minimal

fields `passwd` and `members` are never read

Check warning on line 423 in src/system/mod.rs

View workflow job for this annotation

GitHub Actions / build-and-test-minimal

fields `passwd` and `members` are never read

Check warning on line 423 in src/system/mod.rs

View workflow job for this annotation

GitHub Actions / miri

fields `passwd` and `members` are never read
pub members: Vec<String>,
}

Expand Down Expand Up @@ -514,7 +514,7 @@
pub struct Process {
pub pid: ProcessId,
pub parent_pid: Option<ProcessId>,
pub group_id: ProcessId,

Check warning on line 517 in src/system/mod.rs

View workflow job for this annotation

GitHub Actions / build-and-test-minimal

fields `group_id` and `name` are never read

Check warning on line 517 in src/system/mod.rs

View workflow job for this annotation

GitHub Actions / miri

fields `group_id` and `name` are never read
pub session_id: ProcessId,
pub name: PathBuf,
}
Expand Down Expand Up @@ -672,6 +672,13 @@
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 @@
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
Loading