From a961f15ce8dbf5bfbeb2b853cd82624f3a4c0692 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Sun, 4 Sep 2011 23:48:23 +0200 Subject: fixed various crashes due to newly introduced ScRangeName::maIndexToData * The newly introduced ScRangeName::maIndexToData needs to take into account that boost::ptr_set clones and deletes elements, hence each collection needs its own maIndexToData setup in copy-ctor. * Also fixed ScRangeName::erase() where a wrong index element was set to NULL. Signed-off-by: Eike Rathke --- sc/source/core/tool/rangenam.cxx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 599590a93..35c00dc44 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -735,7 +735,23 @@ void ScRangeName::copyLocalNames(const TabNameMap& rNames, TabNameCopyMap& rCopy ScRangeName::ScRangeName() {} ScRangeName::ScRangeName(const ScRangeName& r) : - maData(r.maData), maIndexToData(r.maIndexToData) {} + maData(r.maData) +{ + // boost::ptr_set clones and deletes, so each collection needs its own + // index to data. + maIndexToData.resize( r.maIndexToData.size(), NULL); + DataType::const_iterator itr = maData.begin(), itrEnd = maData.end(); + for (; itr != itrEnd; ++itr) + { + size_t nPos = itr->GetIndex() - 1; + if (nPos >= maIndexToData.size()) + { + OSL_FAIL( "ScRangeName copy-ctor: maIndexToData size doesn't fit"); + maIndexToData.resize(nPos+1, NULL); + } + maIndexToData[nPos] = const_cast(&(*itr)); + } +} const ScRangeData* ScRangeName::findByRange(const ScRange& rRange) const { @@ -885,8 +901,9 @@ void ScRangeName::erase(const iterator& itr) { sal_uInt16 nIndex = itr->GetIndex(); maData.erase(itr); - if (nIndex < maIndexToData.size()) - maIndexToData[nIndex] = NULL; + OSL_ENSURE( 0 < nIndex && nIndex <= maIndexToData.size(), "ScRangeName::erase: bad index"); + if (0 < nIndex && nIndex <= maIndexToData.size()) + maIndexToData[nIndex-1] = NULL; } void ScRangeName::clear() -- cgit v1.2.3