summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2021-09-08 14:05:51 -0400
committer AJR <ajrhacker@users.noreply.github.com>2021-09-08 14:05:51 -0400
commite7528a445bb0c0d8594f79c5aceabd26077001a5 (patch)
treef8b3279ee1b5e3800726eeb116b384033def45d2
parenta768dd3a26a5f3838d522a2cd9449fa70e68464c (diff)
Filesystem-related bug fixes
- Fix recently-introduced path-trashing bug in zippath_resolve - Prevent UI file select menu from crashing in error cases where no files can be found
-rw-r--r--src/frontend/mame/ui/filesel.cpp28
-rw-r--r--src/lib/util/zippath.cpp2
2 files changed, 16 insertions, 14 deletions
diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp
index bc5c5abbd12..41ecac49c16 100644
--- a/src/frontend/mame/ui/filesel.cpp
+++ b/src/frontend/mame/ui/filesel.cpp
@@ -393,7 +393,6 @@ void menu_file_selector::populate(float &customtop, float &custombottom)
{
const file_selector_entry *selected_entry = nullptr;
-
// clear out the menu entries
m_entrylist.clear();
@@ -406,7 +405,7 @@ void menu_file_selector::populate(float &customtop, float &custombottom)
append_entry(SELECTOR_ENTRY_TYPE_EMPTY, "", "");
// add the "[create]" entry
- if (m_has_create && !directory->is_archive())
+ if (m_has_create && directory && !directory->is_archive())
append_entry(SELECTOR_ENTRY_TYPE_CREATE, "", "");
// add and select the "[software list]" entry if available
@@ -447,17 +446,20 @@ void menu_file_selector::populate(float &customtop, float &custombottom)
}
directory.reset();
- // sort the menu entries
- const std::collate<wchar_t> &coll = std::use_facet<std::collate<wchar_t>>(std::locale());
- std::sort(
- m_entrylist.begin() + first,
- m_entrylist.end(),
- [&coll] (file_selector_entry const &x, file_selector_entry const &y)
- {
- std::wstring const xstr = wstring_from_utf8(x.basename);
- std::wstring const ystr = wstring_from_utf8(y.basename);
- return coll.compare(xstr.data(), xstr.data()+xstr.size(), ystr.data(), ystr.data()+ystr.size()) < 0;
- });
+ if (m_entrylist.size() > first)
+ {
+ // sort the menu entries
+ const std::collate<wchar_t> &coll = std::use_facet<std::collate<wchar_t>>(std::locale());
+ std::sort(
+ m_entrylist.begin() + first,
+ m_entrylist.end(),
+ [&coll] (file_selector_entry const &x, file_selector_entry const &y)
+ {
+ std::wstring const xstr = wstring_from_utf8(x.basename);
+ std::wstring const ystr = wstring_from_utf8(y.basename);
+ return coll.compare(xstr.data(), xstr.data()+xstr.size(), ystr.data(), ystr.data()+ystr.size()) < 0;
+ });
+ }
// append all of the menu entries
for (file_selector_entry const &entry : m_entrylist)
diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp
index 6fad365d6fc..8c37b3d72ad 100644
--- a/src/lib/util/zippath.cpp
+++ b/src/lib/util/zippath.cpp
@@ -211,7 +211,7 @@ std::error_condition zippath_resolve(std::string_view path, osd::directory::entr
auto i = apath.find_last_not_of(PATH_SEPARATOR);
if (i == std::string::npos)
break;
- apath = apath.erase(std::min<decltype(i)>(i + 1, 2));
+ apath = apath.erase(std::max<decltype(i)>(i + 1, 2)); // don't erase drive letter
apath_trimmed = apath;