From e7197092b56e45394f8d9f9cb42a3207e9da2976 Mon Sep 17 00:00:00 2001 From: Ryan Geary Date: Tue, 10 Sep 2019 23:51:01 -0400 Subject: [PATCH] Validate vector indeces --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ce548c4..68ff3cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,11 @@ impl Choice { let words: Vec<&str> = line.split_whitespace().collect(); match self { - Choice::Field(i) => print!("{} ", words[*i as usize]), + Choice::Field(i) => { + if *i < words.len().try_into().unwrap() { + print!("{} ", words[*i as usize]); + } + }, Choice::FieldRange(r) => match r { (None, None) => print!("{}", words.into_iter().collect::()), (Some(start), None) => print!(