Validate vector indeces

This commit is contained in:
Ryan Geary 2019-09-10 23:51:01 -04:00
parent 4b6d44e121
commit e7197092b5

View file

@ -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!(