mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 13:37:48 +00:00
sort: properly check for empty reads
This commit is contained in:
parent
66359a0f56
commit
5a5c7c5a34
2 changed files with 20 additions and 11 deletions
|
@ -102,17 +102,17 @@ pub fn read(
|
||||||
carry_over.clear();
|
carry_over.clear();
|
||||||
carry_over.extend_from_slice(&buffer[read..]);
|
carry_over.extend_from_slice(&buffer[read..]);
|
||||||
|
|
||||||
let payload = Chunk::new(buffer, |buf| {
|
if read != 0 {
|
||||||
let mut lines = unsafe {
|
let payload = Chunk::new(buffer, |buf| {
|
||||||
// SAFETY: It is safe to transmute to a vector of lines with shorter lifetime,
|
let mut lines = unsafe {
|
||||||
// because it was only temporarily transmuted to a Vec<Line<'static>> to make recycling possible.
|
// SAFETY: It is safe to transmute to a vector of lines with shorter lifetime,
|
||||||
std::mem::transmute::<Vec<Line<'static>>, Vec<Line<'_>>>(lines)
|
// because it was only temporarily transmuted to a Vec<Line<'static>> to make recycling possible.
|
||||||
};
|
std::mem::transmute::<Vec<Line<'static>>, Vec<Line<'_>>>(lines)
|
||||||
let read = crash_if_err!(1, std::str::from_utf8(&buf[..read]));
|
};
|
||||||
parse_lines(read, &mut lines, separator, &settings);
|
let read = crash_if_err!(1, std::str::from_utf8(&buf[..read]));
|
||||||
lines
|
parse_lines(read, &mut lines, separator, &settings);
|
||||||
});
|
lines
|
||||||
if !payload.borrow_lines().is_empty() {
|
});
|
||||||
sender.send(payload).unwrap();
|
sender.send(payload).unwrap();
|
||||||
}
|
}
|
||||||
if !should_continue {
|
if !should_continue {
|
||||||
|
|
|
@ -800,3 +800,12 @@ fn sort_multiple() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is("a\nb\nb\n");
|
.stdout_is("a\nb\nb\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sort_empty_chunk() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-S", "40B"])
|
||||||
|
.pipe_in("a\na\n")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("a\na\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue