summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRyan Geary <rtgnj42@gmail.com>2019-09-10 23:51:01 -0400
committerRyan Geary <rtgnj42@gmail.com>2019-09-10 23:51:01 -0400
commite7197092b56e45394f8d9f9cb42a3207e9da2976 (patch)
treef7b3984237b452b927b5413c57859e359a48bec0 /src
parent4b6d44e1214f1059da3c697b3952ec15e11c8dce (diff)
Validate vector indeces
Diffstat (limited to 'src')
-rw-r--r--src/main.rs6
1 files changed, 5 insertions, 1 deletions
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::<String>()),
(Some(start), None) => print!(