From e7d5bad5ae083da12c3ec4a4a8bdc8b42447a242 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Fri, 5 Oct 2018 22:02:45 +0000 Subject: lru_map: fix std::move insert After the move the std::pair is invalid. That caused invalid iterators on lookups - hard to debug... Also adds an assertion to warn if size of map and list differ. Change-Id: Ib987d47963d5e1009d64a96dcdd588a0bc27cd77 Reviewed-on: https://gerrit.libreoffice.org/61451 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski --- include/o3tl/lru_map.hxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx index f2369e45030a..015120e31cb3 100644 --- a/include/o3tl/lru_map.hxx +++ b/include/o3tl/lru_map.hxx @@ -11,6 +11,7 @@ #ifndef INCLUDED_O3TL_LRU_MAP_HXX #define INCLUDED_O3TL_LRU_MAP_HXX +#include #include #include @@ -74,7 +75,8 @@ public: // add to front of the list mLruList.push_front(rPair); // add the list position (iterator) to the map - mLruMap[rPair.first] = mLruList.begin(); + auto it = mLruList.begin(); + mLruMap[it->first] = it; checkLRU(); } else // already exists -> replace value @@ -95,7 +97,8 @@ public: // add to front of the list mLruList.push_front(std::move(rPair)); // add the list position (iterator) to the map - mLruMap[rPair.first] = mLruList.begin(); + auto it = mLruList.begin(); + mLruMap[it->first] = it; checkLRU(); } else // already exists -> replace value @@ -130,7 +133,8 @@ public: size_t size() const { - return mLruList.size(); + assert(mLruMap.size() == mLruList.size()); + return mLruMap.size(); } void clear() -- cgit