Permalink
Browse files

Music search bugfix

CDirectoryHistory::ClearSearchHistory misused vector::iterator::operator++
in conjunction with vector::erase such that it iterated beyond the end of
the vector if there was a previous music search, resulting in a segfault.
End effect: you could only do one search. Replaced with std::remove_if.
  • Loading branch information...
1 parent e3e17ef commit 5d374284cb54222a544ff02de89de97966d43529 @bavison bavison committed Sep 12, 2013
Showing with 7 additions and 5 deletions.
  1. +6 −5 xbmc/filesystem/DirectoryHistory.cpp
  2. +1 −0 xbmc/filesystem/DirectoryHistory.h
@@ -118,13 +118,14 @@ void CDirectoryHistory::ClearPathHistory()
m_vecPathHistory.clear();
}
+bool CDirectoryHistory::IsMusicSearchUrl(CPathHistoryItem &i)
+{
+ return i.GetPath().Left(14) == "musicsearch://";
+}
+
void CDirectoryHistory::ClearSearchHistory()
{
- for (vector<CPathHistoryItem>::iterator it = m_vecPathHistory.begin(); it != m_vecPathHistory.end(); ++it)
- {
- if (it->GetPath().Left(14) == "musicsearch://")
- it = m_vecPathHistory.erase(it);
- }
+ m_vecPathHistory.erase(remove_if(m_vecPathHistory.begin(), m_vecPathHistory.end(), IsMusicSearchUrl), m_vecPathHistory.end());
}
void CDirectoryHistory::DumpPathHistory()
@@ -68,4 +68,5 @@ class CDirectoryHistory
typedef std::map<CStdString, CHistoryItem> HistoryMap;
HistoryMap m_vecHistory;
std::vector<CPathHistoryItem> m_vecPathHistory; ///< History of traversed directories
+ static bool IsMusicSearchUrl(CPathHistoryItem &i);
};

0 comments on commit 5d37428

Please sign in to comment.