From 30051c8e80c9c5fe1f40b6c5ce79e21f3ace7f4e Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 25 Aug 2014 17:48:42 +0200 Subject: [PATCH] issue: #79: Crash when enter on empty list. * This fixes the reproducable part of the bug. (enter on empty list) * check selected < filtered_lines. so we do not try to dereference a null pointer. --- source/rofi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/rofi.c b/source/rofi.c index b223a158..1a74571d 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1390,12 +1390,17 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom if ( shift != NULL ) { ( *shift ) = ( ( ev.xkey.state & ShiftMask ) == ShiftMask ); } - if ( filtered[selected] != NULL ) { + + // If a valid item is selected, return that.. + if ( selected < filtered_lines && filtered[selected] != NULL ) { retv = MENU_OK; *selected_line = line_map[selected]; } - else{ + // No item selected, but user entered something + else if ( strlen (text->text) > 0 ){ retv = MENU_CUSTOM_INPUT; + }else{ + retv = MENU_CANCEL; } quit = TRUE;