fix corruption on empty sel_fname
authorGrazvydas Ignotas <notasas@gmail.com>
Sat, 22 Jun 2013 23:28:08 +0000 (02:28 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 22 Jun 2013 23:28:08 +0000 (02:28 +0300)
menu.c

diff --git a/menu.c b/menu.c
index eb27ce6..503107f 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -983,12 +983,12 @@ static const char *menu_loop_romsel(char *curr_path, int len,
 \r
        // is this a dir or a full path?\r
        if (!plat_is_dir(curr_path)) {\r
-               char *p = curr_path + strlen(curr_path) - 1;\r
-               for (; p > curr_path && *p != '/'; p--)\r
-                       ;\r
-               *p = 0;\r
-               curr_path_restore = p;\r
-               snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1);\r
+               char *p = strrchr(curr_path, '/');\r
+               if (p != NULL) {\r
+                       *p = 0;\r
+                       curr_path_restore = p;\r
+                       snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1);\r
+               }\r
 \r
                if (rom_fname_reload[0] == 0)\r
                        show_help = 2;\r