aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-10-24 21:58:35 -0700
committerChris Robinson <[email protected]>2019-10-24 21:58:35 -0700
commit5ac1f192419a5d1d435a0f8703560823075799af (patch)
tree6dc5309e97168ebfed96136137e1cb9a06b61ca8
parent48347f62b52e4f88fddbe8ca25e662abddb9804e (diff)
Don't dereference the end iterator
-rw-r--r--alc/helpers.cpp88
1 files changed, 42 insertions, 46 deletions
diff --git a/alc/helpers.cpp b/alc/helpers.cpp
index bd0754b8..25b2e4a2 100644
--- a/alc/helpers.cpp
+++ b/alc/helpers.cpp
@@ -324,25 +324,23 @@ static void DirectorySearch(const char *path, const char *ext, al::vector<std::s
std::wstring wpath{utf8_to_wstr(pathstr.c_str())};
WIN32_FIND_DATAW fdata;
HANDLE hdl{FindFirstFileW(wpath.c_str(), &fdata)};
- if(hdl != INVALID_HANDLE_VALUE)
- {
- const auto base = results->cend() - results->cbegin();
-
- do {
- results->emplace_back();
- std::string &str = results->back();
- str = path;
- str += '\\';
- str += wstr_to_utf8(fdata.cFileName);
- } while(FindNextFileW(hdl, &fdata));
- FindClose(hdl);
-
- const al::span<std::string> newlist{std::addressof(*(results->begin()+base)),
- std::addressof(*results->end())};
- std::sort(newlist.begin(), newlist.end());
- for(const auto &name : newlist)
- TRACE(" got %s\n", name.c_str());
- }
+ if(hdl == INVALID_HANDLE_VALUE) return;
+
+ const auto base = results->size();
+
+ do {
+ results->emplace_back();
+ std::string &str = results->back();
+ str = path;
+ str += '\\';
+ str += wstr_to_utf8(fdata.cFileName);
+ } while(FindNextFileW(hdl, &fdata));
+ FindClose(hdl);
+
+ const al::span<std::string> newlist{results->data()+base, results->size()-base};
+ std::sort(newlist.begin(), newlist.end());
+ for(const auto &name : newlist)
+ TRACE(" got %s\n", name.c_str());
}
al::vector<std::string> SearchDataFiles(const char *ext, const char *subdir)
@@ -519,37 +517,35 @@ static void DirectorySearch(const char *path, const char *ext, al::vector<std::s
{
TRACE("Searching %s for *%s\n", path, ext);
DIR *dir{opendir(path)};
- if(dir != nullptr)
+ if(!dir) return;
+
+ const auto base = results->size();
+ const size_t extlen{strlen(ext)};
+
+ struct dirent *dirent;
+ while((dirent=readdir(dir)) != nullptr)
{
- const auto base = results->cend() - results->cbegin();
- const size_t extlen{strlen(ext)};
+ if(strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0)
+ continue;
- struct dirent *dirent;
- while((dirent=readdir(dir)) != nullptr)
- {
- if(strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0)
- continue;
-
- const size_t len{strlen(dirent->d_name)};
- if(len <= extlen) continue;
- if(al::strcasecmp(dirent->d_name+len-extlen, ext) != 0)
- continue;
-
- results->emplace_back();
- std::string &str = results->back();
- str = path;
- if(str.back() != '/')
- str.push_back('/');
- str += dirent->d_name;
- }
- closedir(dir);
+ const size_t len{strlen(dirent->d_name)};
+ if(len <= extlen) continue;
+ if(al::strcasecmp(dirent->d_name+len-extlen, ext) != 0)
+ continue;
- const al::span<std::string> newlist{std::addressof(*(results->begin()+base)),
- std::addressof(*results->end())};
- std::sort(newlist.begin(), newlist.end());
- for(const auto &name : newlist)
- TRACE(" got %s\n", name.c_str());
+ results->emplace_back();
+ std::string &str = results->back();
+ str = path;
+ if(str.back() != '/')
+ str.push_back('/');
+ str += dirent->d_name;
}
+ closedir(dir);
+
+ const al::span<std::string> newlist{results->data()+base, results->size()-base};
+ std::sort(newlist.begin(), newlist.end());
+ for(const auto &name : newlist)
+ TRACE(" got %s\n", name.c_str());
}
al::vector<std::string> SearchDataFiles(const char *ext, const char *subdir)