sw/source/core/crsr/annotationmark.cxx | 37 +++++++++++---------------------- sw/source/core/doc/docbm.cxx | 12 ++-------- sw/source/core/txtnode/atrfld.cxx | 12 +--------- sw/source/core/unocore/unoportenum.cxx | 15 +++++-------- sw/source/filter/basflt/fltshell.cxx | 27 +++++++++++++++++++++++- 5 files changed, 50 insertions(+), 53 deletions(-)
New commits: commit 31c54fa7bb03768b425ae019096e0a0e26e9c736 Author: Michael Stahl <[email protected]> Date: Fri Jul 7 13:26:50 2017 +0200 sw: convert SwTextAnnotationField OSL_ENSUREs to assert() and simplify Change-Id: Ica69cd4527f36edd7480d897a28ff814ecbe97a9 diff --git a/sw/source/core/crsr/annotationmark.cxx b/sw/source/core/crsr/annotationmark.cxx index bca5e903c72a..a73c1715bb36 100644 --- a/sw/source/core/crsr/annotationmark.cxx +++ b/sw/source/core/crsr/annotationmark.cxx @@ -52,26 +52,19 @@ namespace sw { namespace mark void AnnotationMark::InitDoc(SwDoc* const io_pDoc) { SwTextNode *pTextNode = GetMarkEnd().nNode.GetNode().GetTextNode(); - - SwTextField* pTextField = pTextNode ? - pTextNode->GetFieldTextAttrAt( - GetMarkEnd().nContent.GetIndex()-1, true ) : nullptr; - OSL_ENSURE( pTextField != nullptr, "<AnnotationMark::InitDoc(..)> - missing text attribute for annotation field!" ); - if ( pTextField != nullptr ) + assert(pTextNode); + SwTextField *const pTextField = pTextNode->GetFieldTextAttrAt( + GetMarkEnd().nContent.GetIndex()-1, true); + assert(pTextField != nullptr); + const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextField->GetFormatField().GetField()); + assert(pPostItField != nullptr); + // use the annotation mark's name as the annotation name, if + // - the annotation field has an empty annotation name or + // - the annotation mark's name differs (on mark creation a name clash had been detected) + if ( pPostItField->GetName().isEmpty() + || pPostItField->GetName() != GetName() ) { - const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextField->GetFormatField().GetField()); - OSL_ENSURE( pPostItField != nullptr, "<AnnotationMark::InitDoc(..)> - annotation field missing!" ); - if ( pPostItField != nullptr ) - { - // use the annotation mark's name as the annotation name, if - // - the annotation field has an empty annotation name or - // - the annotation mark's name differs (on mark creation a name clash had been detected) - if ( pPostItField->GetName().isEmpty() - || pPostItField->GetName() != GetName() ) - { - const_cast<SwPostItField*>(pPostItField)->SetName( GetName() ); - } - } + const_cast<SwPostItField*>(pPostItField)->SetName( GetName() ); } if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) @@ -84,11 +77,7 @@ namespace sw { namespace mark const SwFormatField* AnnotationMark::GetAnnotationFormatField() const { SwDoc* pDoc = GetMarkPos().GetDoc(); - if ( pDoc == nullptr ) - { - OSL_ENSURE( false, "<AnnotationMark::GetAnnotationFormatField()> - missing document at annotation mark" ); - return nullptr; - } + assert(pDoc != nullptr); SwFormatField* pAnnotationFormatField = nullptr; diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 7ea1692dd559..68030bbb2955 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -918,15 +918,9 @@ namespace sw { namespace mark case IDocumentMarkAccess::MarkType::ANNOTATIONMARK: { IDocumentMarkAccess::iterator_t ppAnnotationMark = lcl_FindMark(m_vAnnotationMarks, *ppMark); - if ( ppAnnotationMark != m_vAnnotationMarks.end() ) - { - m_vAnnotationMarks.erase(ppAnnotationMark); - } - else - { - assert(false && - "<MarkManager::deleteMark(..)> - Annotation Mark not found in Annotation Mark container."); - } + assert(ppAnnotationMark != m_vAnnotationMarks.end() && + "<MarkManager::deleteMark(..)> - Annotation Mark not found in Annotation Mark container."); + m_vAnnotationMarks.erase(ppAnnotationMark); } break; diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx index de3817eeece9..4beca6d098c6 100644 --- a/sw/source/core/txtnode/atrfld.cxx +++ b/sw/source/core/txtnode/atrfld.cxx @@ -618,18 +618,10 @@ SwTextAnnotationField::~SwTextAnnotationField() ::sw::mark::IMark* SwTextAnnotationField::GetAnnotationMark() const { const SwPostItField* pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField()); - OSL_ENSURE( pPostItField != nullptr, "<SwTextAnnotationField::GetAnnotationMark()> - field missing" ); - if ( pPostItField == nullptr ) - { - return nullptr; - } + assert(pPostItField != nullptr); SwDoc* pDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc(); - OSL_ENSURE( pDoc != nullptr, "<SwTextAnnotationField::GetAnnotationMark()> - missing document" ); - if ( pDoc == nullptr ) - { - return nullptr; - } + assert(pDoc != nullptr); IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess(); IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() ); diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 3e8828c51319..fa2d6d0173a7 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -297,15 +297,12 @@ namespace if ( rStartPos.nNode == nOwnNode ) { const SwFormatField* pAnnotationFormatField = pAnnotationMark->GetAnnotationFormatField(); - OSL_ENSURE( pAnnotationFormatField != nullptr, "<lcl_FillAnnotationStartArray(..)> - annotation fmt fld instance missing!" ); - if ( pAnnotationFormatField != nullptr ) - { - rAnnotationStartArr.insert( - std::make_shared<SwAnnotationStartPortion_Impl>( - SwXTextField::CreateXTextField(&rDoc, - pAnnotationFormatField), - rStartPos)); - } + assert(pAnnotationFormatField != nullptr); + rAnnotationStartArr.insert( + std::make_shared<SwAnnotationStartPortion_Impl>( + SwXTextField::CreateXTextField(&rDoc, + pAnnotationFormatField), + rStartPos)); } } } commit 7b4f14e481846b90b124f2ff2b4ac0a6fc79f77b Author: Michael Stahl <[email protected]> Date: Fri Jul 7 15:42:41 2017 +0200 sw: WW8 import: avoid inserting annotation mark without SwPostItField SwFltControlStack::SetAttrInDoc() will insert a RES_FLTR_ANNOTATIONMARK without checking that there is actually a SwPostItField at that position, which triggers the assertion "<AnnotationMark::InitDoc(..)> - annotation field missing!" in AnnotationMark::InitDoc(). This happens when loading "crash-7.doc" which has a different kind of field - a SwPageNameField - at that position. In the WW8 filter, the SwPostItField is inserted in Read_And(), the AnnotationMark in Read_AtnBook(), which look quite orthogonal. Since it doesn't look like a valid document model to have the AnnotationMark without its field, avoid inserting it in the filter. Change-Id: I960d346601522b1a4d8644e538cde174763e99ff diff --git a/sw/source/filter/basflt/fltshell.cxx b/sw/source/filter/basflt/fltshell.cxx index cb0991bf426c..79fcaaa67314 100644 --- a/sw/source/filter/basflt/fltshell.cxx +++ b/sw/source/filter/basflt/fltshell.cxx @@ -57,6 +57,8 @@ #include <ndtxt.hxx> #include <frmatr.hxx> #include <fldbas.hxx> +#include <docufld.hxx> +#include <txtfld.hxx> #include <charatr.hxx> #include <swtable.hxx> #include <tox.hxx> @@ -632,7 +634,30 @@ void SwFltControlStack::SetAttrInDoc(const SwPosition& rTmpPos, case RES_FLTR_ANNOTATIONMARK: { if (MakeBookRegionOrPoint(rEntry, pDoc, aRegion, true)) - pDoc->getIDocumentMarkAccess()->makeAnnotationMark(aRegion, OUString()); + { + SwTextNode const*const pTextNode( + aRegion.End()->nNode.GetNode().GetTextNode()); + assert(pTextNode); + SwTextField const*const pField(pTextNode->GetFieldTextAttrAt( + aRegion.End()->nContent.GetIndex() - 1, true)); + if (pField) + { + SwPostItField const*const pPostIt( + dynamic_cast<SwPostItField const*>(pField->GetFormatField().GetField())); + if (pPostIt) + { + pDoc->getIDocumentMarkAccess()->makeAnnotationMark(aRegion, OUString()); + } + else + { + SAL_WARN("sw", "RES_FLTR_ANNOTATIONMARK: unexpected field"); + } + } + else + { + SAL_WARN("sw", "RES_FLTR_ANNOTATIONMARK: missing field"); + } + } else SAL_WARN("sw", "failed to make book region or point"); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
