diff options
author | Justin Luth <justin_luth@sil.org> | 2016-03-21 08:41:19 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-21 07:50:20 +0000 |
commit | feafa40e30505a1740272f2036441f1ca23cbfd6 (patch) | |
tree | cb2eb9922a1307be38910e5b9790992bc2b7bf91 | |
parent | 46bb02de2ec35e818ab84bd87d1f041bc9db0ef6 (diff) |
avoid null pointer crash during mail-merge
It is possible to have a null TextNode in a FieldMark when
copying bookmarks between documents. The logic was tweaked
to add a test preventing the exception.
Change-Id: Ifaf779b9adc4bb07584bf6362cfe9d32aef315bc
Reviewed-on: https://gerrit.libreoffice.org/23389
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r-- | sw/source/core/crsr/bookmrk.cxx | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index d4947963a2a1..39d1a480a581 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -73,8 +73,9 @@ namespace SwPosition rStart = pField->GetMarkStart(); SwTextNode const*const pStartTextNode = rStart.nNode.GetNode().GetTextNode(); - const sal_Unicode ch_start = ( rStart.nContent.GetIndex() >= pStartTextNode->GetText().getLength() ) ? 0 : - pStartTextNode->GetText()[rStart.nContent.GetIndex()]; + sal_Unicode ch_start = 0; + if( pStartTextNode && ( rStart.nContent.GetIndex() < pStartTextNode->GetText().getLength() ) ) + ch_start = pStartTextNode->GetText()[rStart.nContent.GetIndex()]; if( ( ch_start != aStartMark ) && ( aEndMark != CH_TXT_ATR_FORMELEMENT ) ) { SwPaM aStartPaM(rStart); @@ -87,7 +88,9 @@ namespace SwTextNode const*const pEndTextNode = rEnd.nNode.GetNode().GetTextNode(); const sal_Int32 nEndPos = ( rEnd == rStart || rEnd.nContent.GetIndex() == 0 ) ? rEnd.nContent.GetIndex() : rEnd.nContent.GetIndex() - 1; - const sal_Unicode ch_end = nEndPos >= pEndTextNode->GetText().getLength() ? 0 : pEndTextNode->GetText()[nEndPos]; + sal_Unicode ch_end = 0; + if ( pEndTextNode && ( nEndPos < pEndTextNode->GetText().getLength() ) ) + ch_end = pEndTextNode->GetText()[nEndPos]; if ( aEndMark && ( ch_end != aEndMark ) ) { SwPaM aEndPaM(rEnd); @@ -107,8 +110,9 @@ namespace const SwPosition& rStart = pField->GetMarkStart(); SwTextNode const*const pStartTextNode = rStart.nNode.GetNode().GetTextNode(); - const sal_Unicode ch_start = - pStartTextNode->GetText()[rStart.nContent.GetIndex()]; + sal_Unicode ch_start = 0; + if( pStartTextNode ) + ch_start = pStartTextNode->GetText()[rStart.nContent.GetIndex()]; if( ch_start == aStartMark ) { @@ -122,7 +126,9 @@ namespace const sal_Int32 nEndPos = ( rEnd == rStart || rEnd.nContent.GetIndex() == 0 ) ? rEnd.nContent.GetIndex() : rEnd.nContent.GetIndex() - 1; - const sal_Unicode ch_end = pEndTextNode->GetText()[nEndPos]; + sal_Unicode ch_end = 0; + if ( pEndTextNode ) + ch_end = pEndTextNode->GetText()[nEndPos]; if ( ch_end == aEndMark ) { SwPaM aEnd(rEnd, rEnd); |