Fix dereferencing invalid iterator in wxMemoryFSHandlerBase

Don't assume that m_findIter is always valid initially, i.e. after
FindFirst() is called, as this is not the case if the memory FS is
empty, i.e. which no files had been added to it yet.

This also allows to simplify the iteration logic, as we don't need to
check m_findArgument (which, in turn, obviates the need to clear it when
we reach the end of the iteration) and can just use m_findIter directly.

Closes #18416.
This commit is contained in:
Vadim Zeitlin
2019-06-10 18:07:57 +02:00
parent 3ff6647886
commit 39bab48dee
2 changed files with 7 additions and 14 deletions

View File

@@ -147,22 +147,16 @@ wxString wxMemoryFSHandlerBase::FindFirst(const wxString& url, int flags)
wxString wxMemoryFSHandlerBase::FindNext()
{
// m_findArgument is used to indicate that search is in progress, we reset
// it to empty string after iterating over all elements
while ( !m_findArgument.empty() )
while ( m_findIter != m_Hash.end() )
{
// test for the match before (possibly) clearing m_findArgument below
const bool found = m_findIter->first.Matches(m_findArgument);
const wxString& path = m_findIter->first;
// advance m_findIter first as we need to do it anyhow, whether it
// matches or not
const wxMemoryFSHash::const_iterator current = m_findIter;
++m_findIter;
if ( ++m_findIter == m_Hash.end() )
m_findArgument.clear();
if ( found )
return "memory:" + current->first;
if ( path.Matches(m_findArgument) )
return "memory:" + path;
}
return wxString();