Skip to content

Commit 093b9c1

Browse files
committed
Fixed last command crash
When the last command has an input value larger than the data its operating on it would crash. Added a check to ensure there are enough elements to take.
1 parent 348d751 commit 093b9c1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/commands/last.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ fn last(
3838
) -> Result<OutputStream, ShellError> {
3939
let stream = async_stream! {
4040
let v: Vec<_> = context.input.into_vec().await;
41-
let k = v.len() - (*amount as usize);
42-
for x in v[k..].iter() {
43-
let y: Tagged<Value> = x.clone();
44-
yield ReturnSuccess::value(y)
41+
let count = (*amount as usize);
42+
if count < v.len() {
43+
let k = v.len() - count;
44+
for x in v[k..].iter() {
45+
let y: Tagged<Value> = x.clone();
46+
yield ReturnSuccess::value(y)
47+
}
4548
}
4649
};
4750
Ok(stream.to_output_stream())

0 commit comments

Comments
 (0)