comphelper/source/misc/sequenceashashmap.cxx | 1 include/comphelper/sequenceashashmap.hxx | 85 ++++++++++++++++++++---- sw/source/core/doc/DocumentRedlineManager.cxx | 69 ++++++++----------- sw/source/core/inc/DocumentRedlineManager.hxx | 1 writerfilter/source/rtftok/rtfdispatchvalue.cxx | 4 - 5 files changed, 106 insertions(+), 54 deletions(-)
New commits: commit f7445e1014815a9eb02e2c22257bbce32dc43589 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Sep 26 21:02:24 2017 +0200 tdf#75757 comphelper: avoid STL inheritance in SequenceAsHashMap Change-Id: I5c7d107a05deb06749b4d04246ba183adfafb14d Reviewed-on: https://gerrit.libreoffice.org/42829 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/comphelper/source/misc/sequenceashashmap.cxx b/comphelper/source/misc/sequenceashashmap.cxx index 9c51ad19bf69..707512f42d21 100644 --- a/comphelper/source/misc/sequenceashashmap.cxx +++ b/comphelper/source/misc/sequenceashashmap.cxx @@ -26,7 +26,6 @@ namespace comphelper{ SequenceAsHashMap::SequenceAsHashMap() - : SequenceAsHashMapBase() { } diff --git a/include/comphelper/sequenceashashmap.hxx b/include/comphelper/sequenceashashmap.hxx index 270601af7c67..b4b2991948ae 100644 --- a/include/comphelper/sequenceashashmap.hxx +++ b/include/comphelper/sequenceashashmap.hxx @@ -40,14 +40,9 @@ namespace comphelper{ such name sequences very easy ... */ -struct SequenceAsHashMapBase : public std::unordered_map< - OUString , - css::uno::Any , - OUStringHash > -{ -}; +using SequenceAsHashMapBase = std::unordered_map<OUString, css::uno::Any, OUStringHash>; -class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAsHashMapBase +class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap { public: @@ -221,8 +216,8 @@ class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAs TValueType getUnpackedValueOrDefault(const OUString& sKey , const TValueType& aDefault) const { - const_iterator pIt = find(sKey); - if (pIt == end()) + auto pIt = m_aMap.find(sKey); + if (pIt == m_aMap.end()) return aDefault; TValueType aValue = TValueType(); @@ -249,8 +244,8 @@ class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAs */ css::uno::Any getValue(const OUString& sKey) const { - const_iterator pIt = find(sKey); - if (pIt == end()) + auto pIt = m_aMap.find(sKey); + if (pIt == m_aMap.end()) return css::uno::Any(); return pIt->second; @@ -281,7 +276,7 @@ class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAs bool createItemIfMissing(const OUString& sKey , const TValueType& aValue) { - if (find(sKey) == end()) + if (m_aMap.find(sKey) == m_aMap.end()) { (*this)[sKey] = css::uno::toAny(aValue); return true; @@ -320,6 +315,72 @@ class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAs the map containing all items for the update. */ void update(const SequenceAsHashMap& rSource); + + css::uno::Any& operator[](const OUString& rKey) + { + return m_aMap[rKey]; + } + + using iterator = SequenceAsHashMapBase::iterator; + using const_iterator = SequenceAsHashMapBase::const_iterator; + + void clear() + { + m_aMap.clear(); + } + + size_t size() const + { + return m_aMap.size(); + } + + bool empty() const + { + return m_aMap.empty(); + } + + iterator begin() + { + return m_aMap.begin(); + } + + const_iterator begin() const + { + return m_aMap.begin(); + } + + iterator end() + { + return m_aMap.end(); + } + + const_iterator end() const + { + return m_aMap.end(); + } + + iterator find(const OUString& rKey) + { + return m_aMap.find(rKey); + } + + const_iterator find(const OUString& rKey) const + { + return m_aMap.find(rKey); + } + + iterator erase(iterator it) + { + return m_aMap.erase(it); + } + + size_t erase(const OUString& rKey) + { + return m_aMap.erase(rKey); + } + +private: + SequenceAsHashMapBase m_aMap; }; } // namespace comphelper diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx index 70d6cbf46f2f..bb803365a2f5 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -388,8 +388,8 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) return RTFError::OK; m_nCurrentEncoding = aRTFEncodings[i].codepage == 0 // Default (CP_ACP) - ? osl_getThreadTextEncoding() - : rtl_getTextEncodingFromWindowsCodePage(aRTFEncodings[i].codepage); + ? osl_getThreadTextEncoding() + : rtl_getTextEncodingFromWindowsCodePage(aRTFEncodings[i].codepage); m_aStates.top().nCurrentEncoding = m_nCurrentEncoding; } break; commit 34905a6e9e0c262b61e5969274b661692af44a46 Author: Michael Stahl <mst...@redhat.com> Date: Fri Sep 15 13:51:04 2017 +0200 ofz#3301 sw: DeleteAndJoin found yet another way to delete new redline Not only can that happen in CompressRedlines(), it can also happen in the SwComparePosition::Outside case when the DeleteRedline() decides in particular circumstances to split up the inserted new redline. Arguably it's wrong to split up the new redline in this case; not sure if that ever happens in a legitimate use case though. Avoid this by removing the hack to temporarily insert the new redline and instead create a temporary SwUnoCursor that will be corrected on behalf of the new redline, while the new redline is parked on a safe node. This not only avoids the crash on this file but also makes the "corrupted redline table" assertions go away. Change-Id: I478f4cfc53a19d2cf2f0937f631962f80b1815ff Reviewed-on: https://gerrit.libreoffice.org/42322 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index 1d9a24be3153..92557481bd8d 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -25,6 +25,7 @@ #include <UndoRedline.hxx> #include <docary.hxx> #include <ndtxt.hxx> +#include <unocrsr.hxx> #include <strings.hrc> #include <swmodule.hxx> #include <editsh.hxx> @@ -574,6 +575,32 @@ namespace } } } + + /// in case some text is deleted, ensure that the not-yet-inserted + /// SwRangeRedline has its positions corrected not to point to deleted node + class TemporaryRedlineUpdater + { + private: + SwRangeRedline & m_rRedline; + std::shared_ptr<SwUnoCursor> m_pCursor; + public: + TemporaryRedlineUpdater(SwDoc & rDoc, SwRangeRedline & rRedline) + : m_rRedline(rRedline) + , m_pCursor(rDoc.CreateUnoCursor(*rRedline.GetPoint(), false)) + { + if (m_rRedline.HasMark()) + { + m_pCursor->SetMark(); + *m_pCursor->GetMark() = *m_rRedline.GetMark(); + *m_rRedline.GetMark() = SwPosition(rDoc.GetNodes().GetEndOfContent()); + } + *m_rRedline.GetPoint() = SwPosition(rDoc.GetNodes().GetEndOfContent()); + } + ~TemporaryRedlineUpdater() + { + static_cast<SwPaM&>(m_rRedline) = *m_pCursor; + } + }; } namespace sw @@ -1228,20 +1255,11 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall { mpRedlineTable->Remove( n ); bDec = true; - // We insert temporarily so that pNew is - // also dealt with when moving the indices. if( bCallDelete ) { - ::comphelper::FlagGuard g(m_isForbidCompressRedlines); - //Insert may delete pNewRedl, in which case it sets pNewRedl to nullptr - mpRedlineTable->Insert( pNewRedl ); + TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl); m_rDoc.getIDocumentContentOperations().DeleteAndJoin( *pRedl ); - if (pNewRedl && !mpRedlineTable->Remove(pNewRedl)) - { - assert(false); // can't happen - pNewRedl = nullptr; - } - bCompress = true; // delayed compress + n = 0; // re-initialize } delete pRedl; } @@ -1263,18 +1281,8 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall if( bCallDelete ) { - // We insert temporarily so that pNew is - // also dealt with when moving the indices. - ::comphelper::FlagGuard g(m_isForbidCompressRedlines); - //Insert may delete pNewRedl, in which case it sets pNewRedl to nullptr - mpRedlineTable->Insert( pNewRedl ); + TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl); m_rDoc.getIDocumentContentOperations().DeleteAndJoin( aPam ); - if (pNewRedl && !mpRedlineTable->Remove(pNewRedl)) - { - assert(false); // can't happen - pNewRedl = nullptr; - } - bCompress = true; // delayed compress n = 0; // re-initialize } bDec = true; @@ -1295,18 +1303,8 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall if( bCallDelete ) { - // We insert temporarily so that pNew is - // also dealt with when moving the indices. - ::comphelper::FlagGuard g(m_isForbidCompressRedlines); - //Insert may delete pNewRedl, in which case it sets pNewRedl to nullptr - mpRedlineTable->Insert( pNewRedl ); + TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl); m_rDoc.getIDocumentContentOperations().DeleteAndJoin( aPam ); - if (pNewRedl && !mpRedlineTable->Remove(pNewRedl)) - { - assert(false); // can't happen - pNewRedl = nullptr; - } - bCompress = true; // delayed compress n = 0; // re-initialize bDec = true; } @@ -1797,11 +1795,6 @@ bool DocumentRedlineManager::AppendTableCellRedline( SwTableCellRedline* pNewRed void DocumentRedlineManager::CompressRedlines() { - if (m_isForbidCompressRedlines) - { - return; - } - CHECK_REDLINE( *this ) void (SwRangeRedline::*pFnc)(sal_uInt16, size_t) = nullptr; diff --git a/sw/source/core/inc/DocumentRedlineManager.hxx b/sw/source/core/inc/DocumentRedlineManager.hxx index 9ba7e5bd7f1d..afe8d4090271 100644 --- a/sw/source/core/inc/DocumentRedlineManager.hxx +++ b/sw/source/core/inc/DocumentRedlineManager.hxx @@ -138,7 +138,6 @@ private: sal_uInt16 mnAutoFormatRedlnCommentNo; /**< SeqNo for conjoining of AutoFormat-Redlines. by the UI. Managed by SwAutoFormat! */ css::uno::Sequence <sal_Int8 > maRedlinePasswd; - bool m_isForbidCompressRedlines = false; }; }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits