summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-06-03 14:35:27 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-06-04 18:49:40 +0200
commitc344de1b9985b6ca10b354e24151d0bdf92dc20e (patch)
treef49f903855eb74de3dff83c3c7cc38f33e09dbc5 /svl
parentf31f903628d5e578b003524d62b905289f64e58f (diff)
fix ubsan in SharedStringPool
with a slightly dodgy fix. regression from commit 3581f1d71ae0d431ba28c0f3b7b263ff6212ce7b optimize SharedStringPool::purge() and fix tests It's not ideal - we no longer have a way of purging uppercase keys that are longer in use. But that doesn't cost much memory, because we are sharing those strings. We could potentially identify them with extra book-keeping in either intern() or purge(), but since this class is performance-sensitive, best just to sacrifice some space in the map. Change-Id: I85a469448f5b36b1b6889da60280edd56bbcb083 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95432 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> (cherry picked from commit 4aa6ae8ba911bd3420d3b74c085aa69d87339f4d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95426
Diffstat (limited to 'svl')
-rw-r--r--svl/qa/unit/svl.cxx4
-rw-r--r--svl/source/misc/sharedstringpool.cxx7
2 files changed, 8 insertions, 3 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 6b44a96729d1..2c266e4d9d31 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -392,10 +392,10 @@ void Test::testSharedStringPoolPurge()
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aPool.getCount());
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPool.getCountIgnoreCase());
- // Ditto...
+ // Nothing changes, because the upper-string is still in the map
pStr3.reset();
aPool.purge();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPool.getCount());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aPool.getCount());
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPool.getCountIgnoreCase());
// Again.
diff --git a/svl/source/misc/sharedstringpool.cxx b/svl/source/misc/sharedstringpool.cxx
index 25898084f327..d2d890004fbd 100644
--- a/svl/source/misc/sharedstringpool.cxx
+++ b/svl/source/misc/sharedstringpool.cxx
@@ -60,7 +60,12 @@ SharedString SharedStringPool::intern( const OUString& rStr )
// need to use the same underlying rtl_uString object so the
// upper->upper detection in purge() works
auto pData = insertResult.first->pData;
- mpImpl->maStrMap.insert_or_assign(mapIt, pData, pData);
+ // This is dodgy, but necessary. I don't want to do a delete/insert because
+ // this class is very performance sensitive. This does not violate the internals
+ // the map because the new key points to something with the same hash and equality
+ // as the old key.
+ const_cast<OUString&>(mapIt->first) = *insertResult.first;
+ mapIt->second = pData;
}
else
{