From: Grazvydas Ignotas Date: Sat, 22 Jun 2013 23:28:08 +0000 (+0300) Subject: fix corruption on empty sel_fname X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20b143089cc395dbcd51cac516a9e36f4ab6f5ac;p=libpicofe.git fix corruption on empty sel_fname --- diff --git a/menu.c b/menu.c index eb27ce6..503107f 100644 --- a/menu.c +++ b/menu.c @@ -983,12 +983,12 @@ static const char *menu_loop_romsel(char *curr_path, int len, // is this a dir or a full path? if (!plat_is_dir(curr_path)) { - char *p = curr_path + strlen(curr_path) - 1; - for (; p > curr_path && *p != '/'; p--) - ; - *p = 0; - curr_path_restore = p; - snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1); + char *p = strrchr(curr_path, '/'); + if (p != NULL) { + *p = 0; + curr_path_restore = p; + snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1); + } if (rom_fname_reload[0] == 0) show_help = 2;