diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-10-21 15:04:57 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-10-22 12:43:56 +0200 |
commit | 78490b45c771a4c9632b324922f2c8e83f06153b (patch) | |
tree | 0e74de3a28bce5a7300f39aa36378d35eedc0afe /sw | |
parent | 5c147fc5fe0e77838b8e9bebd4ff215a80946980 (diff) |
pvs-studio: V668 no sense testing against null as memory was allocated by new
category V668 complete
Change-Id: I986d4cb89a7c72d54d71ea01fc598a9958deee24
Reviewed-on: https://gerrit.libreoffice.org/62138
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/text/itrform2.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/unocore/unofield.cxx | 87 |
2 files changed, 46 insertions, 46 deletions
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 225bce5af04f..87749f06b2de 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -1384,6 +1384,8 @@ SwLinePortion *SwTextFormatter::NewPortion( SwTextFormatInfo &rInf ) } } + assert(pPor && "can only reach here with pPor existing"); + // Special portions containing numbers (footnote anchor, footnote number, // numbering) can be contained in a rotated portion, if the user // choose a rotated character attribute. @@ -1458,8 +1460,7 @@ SwLinePortion *SwTextFormatter::NewPortion( SwTextFormatInfo &rInf ) m_pCurr->SetAscent( pPor->GetAscent() ); } - OSL_ENSURE( !pPor || pPor->Height(), - "SwTextFormatter::NewPortion: something went wrong"); + OSL_ENSURE(pPor->Height(), "SwTextFormatter::NewPortion: something went wrong"); if( pPor->IsPostItsPortion() && rInf.X() >= rInf.Width() && rInf.GetFly() ) { delete pPor; diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index bfde7f014f88..937ec468c5f3 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -1899,62 +1899,61 @@ void SAL_CALL SwXTextField::attach( break; default: OSL_FAIL("What kind of type is that?"); } + if (!xField) throw uno::RuntimeException("no SwField created?"); - if (xField) - { - xField->SetAutomaticLanguage(!m_pImpl->m_pProps->bBool4); - SwFormatField aFormat(*xField); - UnoActionContext aCont(pDoc); - if (aPam.HasMark() && - m_pImpl->m_nServiceId != SwServiceType::FieldTypeAnnotation) - { - pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); - } + xField->SetAutomaticLanguage(!m_pImpl->m_pProps->bBool4); + SwFormatField aFormat(*xField); - SwXTextCursor const*const pTextCursor(dynamic_cast<SwXTextCursor*>(pCursor)); - const bool bForceExpandHints( - pTextCursor - && pTextCursor->IsAtEndOfMeta() ); - const SetAttrMode nInsertFlags = - bForceExpandHints - ? SetAttrMode::FORCEHINTEXPAND - : SetAttrMode::DEFAULT; + UnoActionContext aCont(pDoc); + if (aPam.HasMark() && + m_pImpl->m_nServiceId != SwServiceType::FieldTypeAnnotation) + { + pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); + } - if (*aPam.GetPoint() != *aPam.GetMark() && - m_pImpl->m_nServiceId == SwServiceType::FieldTypeAnnotation) - { - // Make sure we always insert the field at the end - SwPaM aEnd(*aPam.End(), *aPam.End()); - pDoc->getIDocumentContentOperations().InsertPoolItem(aEnd, aFormat, nInsertFlags); - } - else - pDoc->getIDocumentContentOperations().InsertPoolItem(aPam, aFormat, nInsertFlags); + SwXTextCursor const*const pTextCursor(dynamic_cast<SwXTextCursor*>(pCursor)); + const bool bForceExpandHints( + pTextCursor + && pTextCursor->IsAtEndOfMeta() ); + const SetAttrMode nInsertFlags = + bForceExpandHints + ? SetAttrMode::FORCEHINTEXPAND + : SetAttrMode::DEFAULT; + + if (*aPam.GetPoint() != *aPam.GetMark() && + m_pImpl->m_nServiceId == SwServiceType::FieldTypeAnnotation) + { + // Make sure we always insert the field at the end + SwPaM aEnd(*aPam.End(), *aPam.End()); + pDoc->getIDocumentContentOperations().InsertPoolItem(aEnd, aFormat, nInsertFlags); + } + else + pDoc->getIDocumentContentOperations().InsertPoolItem(aPam, aFormat, nInsertFlags); - SwTextAttr* pTextAttr = aPam.GetNode().GetTextNode()->GetFieldTextAttrAt( aPam.GetPoint()->nContent.GetIndex()-1, true ); + SwTextAttr* pTextAttr = aPam.GetNode().GetTextNode()->GetFieldTextAttrAt( aPam.GetPoint()->nContent.GetIndex()-1, true ); - // What about updating the fields? (see fldmgr.cxx) - if (!pTextAttr) - throw uno::RuntimeException("no SwTextAttr inserted?"); // could theoretically happen, if paragraph is full + // What about updating the fields? (see fldmgr.cxx) + if (!pTextAttr) + throw uno::RuntimeException("no SwTextAttr inserted?"); // could theoretically happen, if paragraph is full - const SwFormatField& rField = pTextAttr->GetFormatField(); - m_pImpl->m_pFormatField = &rField; + const SwFormatField& rField = pTextAttr->GetFormatField(); + m_pImpl->m_pFormatField = &rField; - if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION - && *aPam.GetPoint() != *aPam.GetMark() ) + if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION + && *aPam.GetPoint() != *aPam.GetMark() ) + { + // create annotation mark + const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextAttr->GetFormatField().GetField()); + OSL_ENSURE( pPostItField != nullptr, "<SwXTextField::attachToRange(..)> - annotation field missing!" ); + if ( pPostItField != nullptr ) { - // create annotation mark - const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextAttr->GetFormatField().GetField()); - OSL_ENSURE( pPostItField != nullptr, "<SwXTextField::attachToRange(..)> - annotation field missing!" ); - if ( pPostItField != nullptr ) - { - IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess(); - pMarksAccess->makeAnnotationMark( aPam, pPostItField->GetName() ); - } + IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess(); + pMarksAccess->makeAnnotationMark( aPam, pPostItField->GetName() ); } - } + xField.reset(); assert(m_pImpl->m_pFormatField); |