Skip to content

Commit

Permalink
Fix buffer overflow for completion example
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanhitc committed Jan 26, 2022
1 parent 29da763 commit cb1e9a5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions examples/completion.rs
Expand Up @@ -29,10 +29,9 @@ impl Default for MyCompletion {
impl Completion for MyCompletion {
/// Simple completion implementation based on substring
fn get(&self, input: &str) -> Option<String> {
let s = input.to_string();
let ss: Vec<&String> = self.options.iter().filter(|x| s == x[..s.len()]).collect();
if ss.len() == 1 {
Some(ss[0].to_string())
let matches = self.options.iter().filter(|x| x.starts_with(input)).collect::<Vec<_>>();
if matches.len() == 1 {
Some(matches[0].to_string())
} else {
None
}
Expand Down

0 comments on commit cb1e9a5

Please sign in to comment.