modes/run: don't segfault on invalid cache lines

Cache lines without a forward-slash resulted in a segfault attempting strlen(NULL + 1), the NULL coming from strrchr().

This patch handles the NULL and displays that cache line varbatim, and without modifying its search_text.
This commit is contained in:
Paul Annesley 2019-11-08 23:51:05 +11:00
parent eeb8a8a324
commit 18be45f69e

View File

@ -23,8 +23,17 @@ void wofi_run_init() {
struct cache_line* node, *tmp; struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) { wl_list_for_each_safe(node, tmp, cache, link) {
char* text = strrchr(node->line, '/') + 1; char* text;
char* search_text = utils_concat(2, text, node->line); char* search_prefix;
char* final_slash = strrchr(node->line, '/');
if(final_slash == NULL) {
text = node->line;
search_prefix = "";
} else {
text = final_slash + 1;
search_prefix = text;
}
char* search_text = utils_concat(2, search_prefix, node->line);
wofi_insert_widget("run", text, search_text, node->line); wofi_insert_widget("run", text, search_text, node->line);
map_put(cached, node->line, "true"); map_put(cached, node->line, "true");
free(search_text); free(search_text);