From 3718aad41447d86bdc69051c1c74724f8638cb5a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 24 Mar 2024 23:15:23 -0700 Subject: [PATCH] Import upstream openal commit, fixing an assert in debug iterators: Original commit: 94a6230a7295ff93815e2293189d5177fd6fca92 Don't try to sort an empty list --- libs/openal-soft/core/helpers.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/openal-soft/core/helpers.cpp b/libs/openal-soft/core/helpers.cpp index 1898f5e0..d9fa8e9f 100644 --- a/libs/openal-soft/core/helpers.cpp +++ b/libs/openal-soft/core/helpers.cpp @@ -60,10 +60,18 @@ void DirectorySearch(const std::filesystem::path &path, const std::string_view e ERR("Exception enumerating files: %s\n", e.what()); } - const al::span newlist{results->begin()+base, results->end()}; - std::sort(newlist.begin(), newlist.end()); - for(const auto &name : newlist) - TRACE(" got %s\n", name.c_str()); + /* HACK: Without the size check this trips up range-checked iterators, as + * al::span uses al::to_address to get the first iterator's data pointer, + * which relies on operator->(), which can assert on end iterators. The + * check shouldn't be needed with C++20's std::span. + */ + if(static_cast(base) < results->size()) + { + const al::span newlist{results->begin()+base, results->end()}; + std::sort(newlist.begin(), newlist.end()); + for(const auto &name : newlist) + TRACE(" got %s\n", name.c_str()); + } } } // namespace