Skip to content

Commit

Permalink
ui: fix crash due to out-of-bounds array access
Browse files Browse the repository at this point in the history
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 <sunshine@sunshineco.com>
Signed-off-by: Jonas Fonseca <jonas.fonseca@gmail.com>
  • Loading branch information
sunshineco authored and jonas committed Apr 9, 2015
1 parent 09fb65c commit 718c6e9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui.c
Expand Up @@ -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);
Expand Down

0 comments on commit 718c6e9

Please sign in to comment.