From b8ba995f079add002ab9606168d31d5386993160 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 14 Dec 2017 14:17:03 +0100 Subject: editeng: fix RTF export of colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SfxItemPool may contain null pointers and return them from GetItem2(), even if non-null pointers follow, so have to use GetItemCount2() here. This later asserts when it can't find the items in aColorList. (cherry picked from commit 30504139af039d524ca0fd7158fc21ed38db2d9f) editeng: RTF export: another buggy GetItem2() loop, for fonts (cherry picked from commit 8ce353279caa84944971f22ec536433030e5d9c7) editeng: error: "remove_const_t" is not a member of "std" Manual type inference was an interesting oxymoronic curiosity that can probably only exist in C++, but it turns out our baseline compilers don't even support it yet. (cherry picked from commit 700e1e7fda6f0a415adbbd5bb190efa5c7435c4f) Change-Id: I976c95387b4c45e5a4371254f130df6b24370eaa Reviewed-on: https://gerrit.libreoffice.org/46469 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- editeng/source/editeng/impedit4.cxx | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'editeng/source') diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index f315141e9719..4b09582b99d1 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -315,10 +315,15 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) else if ( nScriptType == 2 ) nWhich = EE_CHAR_FONTINFO_CTL; - sal_uInt32 i = 0; - const SvxFontItem* pFontItem = static_cast(aEditDoc.GetItemPool().GetItem2( nWhich, i )); - while ( pFontItem ) + auto const nFonts(aEditDoc.GetItemPool().GetItemCount2(nWhich)); + for (sal_uInt32 i = 0; i < nFonts; ++i) { + SvxFontItem const*const pFontItem = static_cast( + aEditDoc.GetItemPool().GetItem2(nWhich, i)); + if (!pFontItem) + { + continue; + } bool bAlreadyExist = false; sal_uLong nTestMax = nScriptType ? aFontTable.size() : 1; for ( sal_uLong nTest = 0; !bAlreadyExist && ( nTest < nTestMax ); nTest++ ) @@ -328,8 +333,6 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) if ( !bAlreadyExist ) aFontTable.push_back( new SvxFontItem( *pFontItem ) ); - - pFontItem = static_cast(aEditDoc.GetItemPool().GetItem2( nWhich, ++i )); } } @@ -392,16 +395,14 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) { aColorList.push_back(rDefault.GetValue()); } - sal_uInt32 i = 0; - SvxColorItem const* pColorItem = aEditDoc.GetItemPool().GetItem2( EE_CHAR_COLOR, i); - while ( pColorItem ) + auto const nColors(aEditDoc.GetItemPool().GetItemCount2(EE_CHAR_COLOR)); + for (sal_uInt32 i = 0; i < nColors; ++i) { - ++i; - if ( pColorItem->GetValue() != COL_AUTO ) + SvxColorItem const*const pColorItem(aEditDoc.GetItemPool().GetItem2(EE_CHAR_COLOR, i)); + if (pColorItem && pColorItem->GetValue() != COL_AUTO) // may be null! { aColorList.push_back(pColorItem->GetValue()); } - pColorItem = aEditDoc.GetItemPool().GetItem2(EE_CHAR_COLOR, i); } rOutput.WriteChar( '{' ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_COLORTBL ); -- cgit