[Libreoffice-commits] .: sc/source
Eike Rathke
erack at kemper.freedesktop.org
Sun Sep 4 14:57:48 PDT 2011
sc/source/core/tool/rangenam.cxx | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
New commits:
commit 0bf8fd627afc8567ae8ec6fad8edf20a11f143ad
Author: Eike Rathke <erack at erack.de>
Date: Sun Sep 4 23:48:23 2011 +0200
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.
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 98188fa..6ba9c26 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -782,7 +782,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<ScRangeData*>(&(*itr));
+ }
+}
const ScRangeData* ScRangeName::findByRange(const ScRange& rRange) const
{
@@ -939,8 +955,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()
More information about the Libreoffice-commits
mailing list