From 093b9c1c5b73efb8f7a8f596f458501fc1f413e1 Mon Sep 17 00:00:00 2001 From: Jonathan Rothberg Date: Sun, 29 Sep 2019 20:20:18 -0700 Subject: [PATCH] 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. --- src/commands/last.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/commands/last.rs b/src/commands/last.rs index 4813c555a..321506846 100644 --- a/src/commands/last.rs +++ b/src/commands/last.rs @@ -38,10 +38,13 @@ fn last( ) -> Result { let stream = async_stream! { let v: Vec<_> = context.input.into_vec().await; - let k = v.len() - (*amount as usize); - for x in v[k..].iter() { - let y: Tagged = x.clone(); - yield ReturnSuccess::value(y) + let count = (*amount as usize); + if count < v.len() { + let k = v.len() - count; + for x in v[k..].iter() { + let y: Tagged = x.clone(); + yield ReturnSuccess::value(y) + } } }; Ok(stream.to_output_stream())