From 718c6e94fcc111e5607d6ca0bf3d15271adc0d97 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Thu, 9 Apr 2015 04:37:19 -0400 Subject: [PATCH] ui: fix crash due to out-of-bounds array access If the search string typed at the "Find file:" prompt in the file finder does not match any files, then the resulting file list is empty. When ENTER is pressed, open_file_finder() attempts to retrieve the non-existent entry at index 0 in the empty list, often resulting in a crash. Fix this boundary condition error. Signed-off-by: Eric Sunshine Signed-off-by: Jonas Fonseca --- src/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui.c b/src/ui.c index 7f01a96ea..e484d6a53 100644 --- a/src/ui.c +++ b/src/ui.c @@ -293,7 +293,7 @@ open_file_finder(const char *commit) finder.keymap = get_keymap("search", STRING_SIZE("search")), file_finder_update(&finder); file_finder_draw(&finder); - if (read_prompt_incremental("Find file: ", FALSE, file_finder_input_handler, &finder)) + if (read_prompt_incremental("Find file: ", FALSE, file_finder_input_handler, &finder) && finder.pos.lineno < finder.lines) file = get_path(finder.line[finder.pos.lineno]->text); file_finder_done(&finder);