filter = scandir_filter;\r
\r
n = scandir(curr_path, &namelist, filter, (void *)scandir_cmp);\r
- if (n < 0) {\r
+ if (n < 0 || !namelist) {\r
lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
\r
// try data root\r
plat_get_data_dir(curr_path, len);\r
n = scandir(curr_path, &namelist, filter, (void *)scandir_cmp);\r
- if (n < 0) {\r
+ if (n < 0 || !namelist) {\r
// oops, we failed\r
lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
- return NULL;\r
+ namelist = malloc(sizeof(*namelist));\r
+ namelist[0] = calloc(1, sizeof(**namelist));\r
}\r
}\r
\r
namelist[sel]->d_name);\r
goto rescan;\r
}\r
- if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-1; }\r
+ int last = n ? n-1 : 0;\r
+ if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = last; }\r
else if (inp & PBTN_DOWN) { sel++; if (sel > n-1) sel = 0; }\r
else if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r
- else if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-1) sel = n-1; }\r
+ else if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-1) sel = last; }\r
else if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }\r
- else if (inp & PBTN_R) { sel+=24; if (sel > n-1) sel = n-1; }\r
+ else if (inp & PBTN_R) { sel+=24; if (sel > n-1) sel = last; }\r
\r
else if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2))\r
{\r