Skip to content

Commit dee84e9

Browse files
authored
Merge pull request #169 from bryanhitc/bryanhitc/fix-completion-buffer-overflow
Fix buffer overflow in completion example
2 parents 29da763 + e4ffea8 commit dee84e9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

examples/completion.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ impl Default for MyCompletion {
2929
impl Completion for MyCompletion {
3030
/// Simple completion implementation based on substring
3131
fn get(&self, input: &str) -> Option<String> {
32-
let s = input.to_string();
33-
let ss: Vec<&String> = self.options.iter().filter(|x| s == x[..s.len()]).collect();
34-
if ss.len() == 1 {
35-
Some(ss[0].to_string())
32+
let matches = self
33+
.options
34+
.iter()
35+
.filter(|option| option.starts_with(input))
36+
.collect::<Vec<_>>();
37+
38+
if matches.len() == 1 {
39+
Some(matches[0].to_string())
3640
} else {
3741
None
3842
}

0 commit comments

Comments
 (0)