Browse code

Fix segfault when autocompleting on no matches

John Hawthorn authored on 04/07/2016 05:51:35
Showing 2 changed files

... ...
@@ -8,6 +8,7 @@ Performance:
8 8
 Bugfixes:
9 9
 
10 10
   - Fixed command line parsing on ARM
11
+  - Fix error when autocompleting and there are no matches
11 12
 
12 13
 ## 0.5 (2016-06-11)
13 14
 
... ...
@@ -166,7 +166,10 @@ static void action_pagedown(tty_interface_t *state) {
166 166
 
167 167
 static void action_autocomplete(tty_interface_t *state) {
168 168
 	update_state(state);
169
-	strncpy(state->search, choices_get(state->choices, state->choices->selection), SEARCH_SIZE_MAX);
169
+	const char *current_selection = choices_get(state->choices, state->choices->selection);
170
+	if (current_selection) {
171
+		strncpy(state->search, choices_get(state->choices, state->choices->selection), SEARCH_SIZE_MAX);
172
+	}
170 173
 }
171 174
 
172 175
 static void action_exit(tty_interface_t *state) {