Skip to content

fix: panics on redirect to /dev/full - #261

Open
toggysmith wants to merge 2 commits into
uutils:mainfrom
toggysmith:handle-redirect-to-dev-full
Open

toggysmith wants to merge 2 commits into
uutils:mainfrom
toggysmith:handle-redirect-to-dev-full

Conversation

@toggysmith

Copy link
Copy Markdown
Contributor

This fixes several panics that would occur when the stdout was redirected to /dev/full. This also introduces a new macro for this purpose, named safe_println!(), that does not panic in this situation, which can presumably be reused elsewhere this issue may reoccur in the future.

This fixes several panics that would occur when the stdout was
redirected to /dev/full. This also introduces a new macro for
this purpose, named `safe_println!()`, that does not panic in
this situation, which can presumably be reused elsewhere this
issue may reoccur in the future.
@toggysmith

Copy link
Copy Markdown
Contributor Author

This resolves #165 .

@codecov

codecov Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (890c3e4) to head (6e4e359).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #261   +/-   ##
===========================
===========================

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/cmp.rs
// For the full copyright and license information, please view the LICENSE-*
// files that was distributed with this source code.

use crate::safe_println;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add tests in tests/integration.rs for diff and cmp writing to /dev/full (exit code + stderr)

Comment thread src/cmp.rs
);
}
println!();
safe_println!();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only works because the print! above is line-buffered
and cmp --help > /dev/full still panics (line 217)

Comment thread src/diff.rs
@@ -91,7 +91,7 @@ pub fn main(opts: Peekable<ArgsOs>) -> ExitCode {
params.to.to_string_lossy()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this one and maybe_report_identical_files? diff -q a b > /dev/full still panics.
same for -y, side_diff still unwraps.

Comment thread src/diff.rs
);
} else {
io::stdout().write_all(&result).unwrap();
let _ = io::stdout().write_all(&result);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoring the error isn't right either
GNU diff prints a write error and exits with 2 here, we would exit 0/1 silently
could you please propagate the error instead?

Comment thread src/macros.rs
}};
}

/// A safe version of println!() that does not panic if stdout is redirected to /dev/full

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a println! that swallows errors will hide real failures, no?
i would rather return the io::Result and handle it in the caller

Comment thread src/main.rs
println!("Usage: {name} [function [arguments...]]\n");
println!("Currently defined functions:\n");
println!(" cmp, diff\n");
safe_println!("{name} {VERSION} (multi-call binary)\n");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this changes the output: println!("...\n") printed two newlines, is safe_println! doing the same?
please add a test either way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants