From e8c433b34754490e1415e6b98d2a3c51c7e5dbab Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 11 Dec 2015 14:57:10 +0200 Subject: tdf#96339 fix bug in sort list this bug was caused by commit 2aacf6c2cd82322b953988ff30d3bc997ae76d7b "sc: boost::ptr_vector->std::vector" Since the code in question likes passing around a pointer to the element of the vector, convert to using std::vector Change-Id: I9e9676fe7c2dc32e23ba6708aaea1f16c1bf2ff8 (cherry picked from commit 0bcef149ce3785306271fa06184eb62950b62087) --- sc/source/core/tool/appoptio.cxx | 4 ++-- sc/source/core/tool/userlist.cxx | 45 ++++++++++++++++++++++++++-------------- sc/source/ui/optdlg/tpusrlst.cxx | 2 +- sc/source/ui/unoobj/appluno.cxx | 4 ++-- 4 files changed, 35 insertions(+), 20 deletions(-) (limited to 'sc/source') diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx index 5328f67a353f..3bdf429dfa67 100644 --- a/sc/source/core/tool/appoptio.cxx +++ b/sc/source/core/tool/appoptio.cxx @@ -180,11 +180,11 @@ static void lcl_SetSortList( const Any& rValue ) if (!bDefault) { aList.clear(); - aList.reserve(nCount); for (long i=0; i #include #include +#include #include #include @@ -96,6 +97,10 @@ ScUserListData::ScUserListData(const ScUserListData& rData) : InitTokens(); } +ScUserListData::~ScUserListData() +{ +} + void ScUserListData::SetString( const OUString& rStr ) { aStr = rStr; @@ -233,9 +238,9 @@ ScUserList::ScUserList() OUString aDayLong = aDayLongBuf.makeStringAndClear(); if ( !HasEntry( aDayShort ) ) - maData.push_back( ScUserListData( aDayShort )); + maData.push_back( o3tl::make_unique( aDayShort )); if ( !HasEntry( aDayLong ) ) - maData.push_back( ScUserListData( aDayLong )); + maData.push_back( o3tl::make_unique( aDayLong )); } xCal = xCalendars[j].Months; @@ -258,15 +263,18 @@ ScUserList::ScUserList() OUString aMonthLong = aMonthLongBuf.makeStringAndClear(); if ( !HasEntry( aMonthShort ) ) - maData.push_back( ScUserListData( aMonthShort )); + maData.push_back( o3tl::make_unique( aMonthShort )); if ( !HasEntry( aMonthLong ) ) - maData.push_back( ScUserListData( aMonthLong )); + maData.push_back( o3tl::make_unique( aMonthLong )); } } } -ScUserList::ScUserList(const ScUserList& r) : - maData(r.maData) {} +ScUserList::ScUserList(const ScUserList& rOther) +{ + for (const std::unique_ptr& rData : rOther.maData) + maData.push_back( o3tl::make_unique(*rData.get()) ); +} const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const { @@ -277,12 +285,12 @@ const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const for (; itr != itrEnd; ++itr) { - if (itr->GetSubIndex(rSubStr, nIndex, bMatchCase)) + if ((*itr)->GetSubIndex(rSubStr, nIndex, bMatchCase)) { if (bMatchCase) - return &(*itr); + return itr->get(); if (!pFirstCaseInsensitive) - pFirstCaseInsensitive = &(*itr); + pFirstCaseInsensitive = itr->get(); } } @@ -291,17 +299,19 @@ const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const const ScUserListData& ScUserList::operator[](size_t nIndex) const { - return maData[nIndex]; + return *maData[nIndex].get(); } ScUserListData& ScUserList::operator[](size_t nIndex) { - return maData[nIndex]; + return *maData[nIndex].get(); } -ScUserList& ScUserList::operator=( const ScUserList& r ) +ScUserList& ScUserList::operator=( const ScUserList& rOther ) { - maData = r.maData; + maData.clear(); + for (const std::unique_ptr& rData : rOther.maData) + maData.push_back( o3tl::make_unique(*rData.get()) ); return *this; } @@ -313,8 +323,8 @@ bool ScUserList::operator==( const ScUserList& r ) const DataType::const_iterator itr1 = maData.begin(), itr2 = r.maData.begin(), itrEnd = maData.end(); for (; itr1 != itrEnd; ++itr1, ++itr2) { - const ScUserListData& v1 = *itr1; - const ScUserListData& v2 = *itr2; + const ScUserListData& v1 = *itr1->get(); + const ScUserListData& v2 = *itr2->get(); if (v1.GetString() != v2.GetString() || v1.GetSubCount() != v2.GetSubCount()) return false; } @@ -346,6 +356,11 @@ size_t ScUserList::size() const return maData.size(); } +void ScUserList::push_back(ScUserListData* p) +{ + maData.push_back(std::unique_ptr(p)); +} + void ScUserList::erase(iterator itr) { maData.erase(itr); diff --git a/sc/source/ui/optdlg/tpusrlst.cxx b/sc/source/ui/optdlg/tpusrlst.cxx index 2511027ec78e..9a4ff48aeea8 100644 --- a/sc/source/ui/optdlg/tpusrlst.cxx +++ b/sc/source/ui/optdlg/tpusrlst.cxx @@ -344,7 +344,7 @@ void ScTpUserLists::AddNewList( const OUString& rEntriesStr ) MakeListStr( theEntriesStr ); - pUserLists->push_back(ScUserListData(rEntriesStr)); + pUserLists->push_back(new ScUserListData(theEntriesStr)); } void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos, diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx index c1d847d4008d..b597272f0d06 100644 --- a/sc/source/ui/unoobj/appluno.cxx +++ b/sc/source/ui/unoobj/appluno.cxx @@ -356,12 +356,12 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue( pUserList->clear(); // alle Eintraege raus sal_uInt16 nCount = (sal_uInt16)aSeq.getLength(); - pUserList->reserve(nCount); const OUString* pAry = aSeq.getConstArray(); for (sal_uInt16 i=0; ipush_back( ScUserListData(aEntry) ); + ScUserListData* pData = new ScUserListData(aEntry); + pUserList->push_back(pData); } bSaveApp = true; // Liste wird mit den App-Optionen gespeichert } -- cgit v1.2.3