chart2/source/controller/main/ChartController_Tools.cxx | 6 - dbaccess/source/ui/misc/TableCopyHelper.cxx | 15 +-- dbaccess/source/ui/tabledesign/TEditControl.cxx | 5 - include/vcl/transfer.hxx | 4 sc/source/ui/app/transobj.cxx | 4 sc/source/ui/view/gridwin.cxx | 2 sc/source/ui/view/viewfun3.cxx | 24 ++--- sc/source/ui/view/viewfun4.cxx | 4 sc/source/ui/view/viewfun5.cxx | 9 -- sd/source/ui/view/sdview3.cxx | 36 ++------ svx/source/gallery2/galtheme.cxx | 4 sw/source/uibase/dochdl/swdtflvr.cxx | 9 -- vcl/source/treelist/transfer.cxx | 67 +++++++--------- 13 files changed, 78 insertions(+), 111 deletions(-)
New commits: commit e7bb3a52067c426eedffddf86e7d5f0903562da2 Author: Noel Grandin <[email protected]> AuthorDate: Sun Apr 7 20:23:26 2024 +0100 Commit: Noel Grandin <[email protected]> CommitDate: Mon Apr 8 23:16:25 2024 +0200 cid#1596254 Null pointer dereferences in GetSotStorageStream Re-arrange the calling convention to make it obvious that a valid stream is the same as a good (true) result. Change-Id: I974b023a8e7231e70ab649628fdbe43c33001e5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165874 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index 539516de7466..5774ff1350d4 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -266,8 +266,7 @@ void ChartController::executeDispatch_Paste() { if ( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) ) { - std::unique_ptr<SvStream> xStm; - if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING) ) { xStm->Seek( 0 ); Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) ); @@ -284,8 +283,7 @@ void ChartController::executeDispatch_Paste() else if ( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) ) { // graphic exchange format (graphic manager bitmap format?) - std::unique_ptr<SvStream> xStm; - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm )) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB )) { TypeSerializer aSerializer(*xStm); aSerializer.readGraphic(aGraphic); diff --git a/dbaccess/source/ui/misc/TableCopyHelper.cxx b/dbaccess/source/ui/misc/TableCopyHelper.cxx index 9da2cb100f3d..5d22c90468c8 100644 --- a/dbaccess/source/ui/misc/TableCopyHelper.cxx +++ b/dbaccess/source/ui/misc/TableCopyHelper.cxx @@ -180,16 +180,15 @@ void OTableCopyHelper::pasteTable( SotClipboardFormatId _nFormatId try { DropDescriptor aTrans; - bool bOk; if ( _nFormatId != SotClipboardFormatId::RTF ) - bOk = _rTransData.GetSotStorageStream(SotClipboardFormatId::HTML ,aTrans.aHtmlRtfStorage); + aTrans.aHtmlRtfStorage = _rTransData.GetSotStorageStream(SotClipboardFormatId::HTML); else - bOk = _rTransData.GetSotStorageStream(SotClipboardFormatId::RTF,aTrans.aHtmlRtfStorage); + aTrans.aHtmlRtfStorage = _rTransData.GetSotStorageStream(SotClipboardFormatId::RTF); aTrans.nType = E_TABLE; aTrans.bHtml = SotClipboardFormatId::HTML == _nFormatId; aTrans.sDefaultTableName = GetTableNameForAppend(); - if ( !bOk || !copyTagTable(aTrans,false,_xConnection) ) + if ( !aTrans.aHtmlRtfStorage || !copyTagTable(aTrans,false,_xConnection) ) m_pController->showError(SQLException(DBA_RES(STR_NO_TABLE_FORMAT_INSIDE), *m_pController, "S1000", 0, Any())); } catch(const SQLException&) @@ -254,16 +253,12 @@ bool OTableCopyHelper::copyTagTable(const TransferableDataHelper& _aDroppedData bool bHtml = _aDroppedData.HasFormat(SotClipboardFormatId::HTML); if ( bHtml || _aDroppedData.HasFormat(SotClipboardFormatId::RTF) ) { - bool bOk; - if ( bHtml ) - bOk = _aDroppedData.GetSotStorageStream(SotClipboardFormatId::HTML ,_rAsyncDrop.aHtmlRtfStorage); - else - bOk = _aDroppedData.GetSotStorageStream(SotClipboardFormatId::RTF,_rAsyncDrop.aHtmlRtfStorage); + _rAsyncDrop.aHtmlRtfStorage = _aDroppedData.GetSotStorageStream(bHtml ? SotClipboardFormatId::HTML : SotClipboardFormatId::RTF); _rAsyncDrop.bHtml = bHtml; _rAsyncDrop.bError = !copyTagTable(_rAsyncDrop,true,_xConnection); - bRet = ( !_rAsyncDrop.bError && bOk && _rAsyncDrop.aHtmlRtfStorage ); + bRet = ( !_rAsyncDrop.bError && _rAsyncDrop.aHtmlRtfStorage ); if ( bRet ) { // now we need to copy the stream diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx b/dbaccess/source/ui/tabledesign/TEditControl.cxx index 32e298445e14..b9328604b277 100644 --- a/dbaccess/source/ui/tabledesign/TEditControl.cxx +++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx @@ -770,9 +770,8 @@ void OTableEditorCtrl::InsertRows( sal_Int32 nRow ) TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent())); if(aTransferData.HasFormat(SotClipboardFormatId::SBA_TABED)) { - std::unique_ptr<SvStream> aStreamRef; - bool bOk = aTransferData.GetSotStorageStream(SotClipboardFormatId::SBA_TABED,aStreamRef); - if (bOk && aStreamRef) + std::unique_ptr<SvStream> aStreamRef = aTransferData.GetSotStorageStream(SotClipboardFormatId::SBA_TABED); + if (aStreamRef) { aStreamRef->Seek(STREAM_SEEK_TO_BEGIN); aStreamRef->ResetError(); diff --git a/include/vcl/transfer.hxx b/include/vcl/transfer.hxx index 93bd892daa3d..3f07a9f6aab9 100644 --- a/include/vcl/transfer.hxx +++ b/include/vcl/transfer.hxx @@ -351,8 +351,8 @@ public: css::uno::Sequence<sal_Int8> GetSequence( SotClipboardFormatId nFormat, const OUString& rDestDoc ) const; css::uno::Sequence<sal_Int8> GetSequence( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) const; - bool GetSotStorageStream( SotClipboardFormatId nFormat, std::unique_ptr<SvStream>& rStreamRef ) const; - bool GetSotStorageStream( const css::datatransfer::DataFlavor& rFlavor, std::unique_ptr<SvStream>& rStreamRef ) const; + std::unique_ptr<SvStream> GetSotStorageStream( SotClipboardFormatId nFormat ) const; + std::unique_ptr<SvStream> GetSotStorageStream( const css::datatransfer::DataFlavor& rFlavor ) const; css::uno::Reference<css::io::XInputStream> GetInputStream( SotClipboardFormatId nFormat, const OUString& rDestDoc ) const; css::uno::Reference<css::io::XInputStream> GetInputStream( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) const; diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx index 5d5cd26090c8..1a97a01d049b 100644 --- a/sc/source/ui/app/transobj.cxx +++ b/sc/source/ui/app/transobj.cxx @@ -497,8 +497,8 @@ bool ScTransferObj::WriteObject( SvStream& rOStm, void* pUserObject, sal_uInt32 uno::Reference<datatransfer::XTransferable> xEditTrans = pEngine->CreateTransferable( aSel ); TransferableDataHelper aEditHelper( xEditTrans ); - std::unique_ptr<SvStream> xStrm; - bRet = aEditHelper.GetSotStorageStream( rFlavor, xStrm ); + std::unique_ptr<SvStream> xStrm = aEditHelper.GetSotStorageStream( rFlavor ); + bRet = bool(xStrm); rOStm.WriteStream(*xStrm); } } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 35e36339edc1..1b7c16f1884b 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -4371,7 +4371,7 @@ static SotClipboardFormatId lcl_GetDropFormatId( const uno::Reference<datatransf std::unique_ptr<SvStream> xStm; TransferableObjectDescriptor aObjDesc; if( aDataHelper.GetTransferableObjectDescriptor( SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDesc ) && - aDataHelper.GetSotStorageStream( SotClipboardFormatId::EMBED_SOURCE, xStm ) ) + (xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::EMBED_SOURCE )) ) { bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) || aObjDesc.maClassName == SvGlobalName( SO3_SWWEB_CLASSID ) ) diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index 07a9205fc427..ee2cccf72f35 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -776,22 +776,20 @@ bool ScViewFunc::PasteOnDrawObjectLinked( if ( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) ) { - std::unique_ptr<SvStream> xStm; - ScDrawView* pScDrawView = GetScDrawView(); - - if( pScDrawView && aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ) ) - { - Graphic aGraphic; - TypeSerializer aSerializer(*xStm); - aSerializer.readGraphic(aGraphic); + if (ScDrawView* pScDrawView = GetScDrawView()) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB ) ) + { + Graphic aGraphic; + TypeSerializer aSerializer(*xStm); + aSerializer.readGraphic(aGraphic); - const OUString aBeginUndo(ScResId(STR_UNDO_DRAGDROP)); + const OUString aBeginUndo(ScResId(STR_UNDO_DRAGDROP)); - if(pScDrawView->ApplyGraphicToObject( rHitObj, aGraphic, aBeginUndo, "" )) - { - return true; + if(pScDrawView->ApplyGraphicToObject( rHitObj, aGraphic, aBeginUndo, "" )) + { + return true; + } } - } } else if ( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ) ) { diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx index 339cff8978dd..fc7da221eae7 100644 --- a/sc/source/ui/view/viewfun4.cxx +++ b/sc/source/ui/view/viewfun4.cxx @@ -162,12 +162,12 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow, OUString aStr; std::unique_ptr<SvStream> xStream; - if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::RTF, xStream ) && xStream ) + if ( (xStream = aDataHelper.GetSotStorageStream( SotClipboardFormatId::RTF )) ) // mba: clipboard always must contain absolute URLs (could be from alien source) aImpEx.ImportStream( *xStream, OUString(), SotClipboardFormatId::RTF ); else if ( aDataHelper.GetString( SotClipboardFormatId::RTF, aStr ) ) aImpEx.ImportString( aStr, SotClipboardFormatId::RTF ); - else if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::RICHTEXT, xStream ) && xStream ) + else if ( (xStream = aDataHelper.GetSotStorageStream( SotClipboardFormatId::RICHTEXT)) ) aImpEx.ImportStream( *xStream, OUString(), SotClipboardFormatId::RICHTEXT ); else if ( aDataHelper.GetString( SotClipboardFormatId::RICHTEXT, aStr ) ) aImpEx.ImportString( aStr, SotClipboardFormatId::RICHTEXT ); diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx index 9f82c96df810..25e89487f96f 100644 --- a/sc/source/ui/view/viewfun5.cxx +++ b/sc/source/ui/view/viewfun5.cxx @@ -231,8 +231,7 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId, } else if (nFormatId == SotClipboardFormatId::SVXB) { - std::unique_ptr<SvStream> xStm; - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB ) ) { Graphic aGraphic; TypeSerializer aSerializer(*xStm); @@ -242,8 +241,7 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId, } else if ( nFormatId == SotClipboardFormatId::DRAWING ) { - std::unique_ptr<SvStream> xStm; - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING )) { MakeDrawLayer(); // before loading model, so 3D factory has been created @@ -676,8 +674,7 @@ bool ScViewFunc::PasteDataFormatFormattedText( SotClipboardFormatId nFormatId, pObj->SetOverwriting( true ); auto pStrBuffer = std::make_shared<OUString>(); - std::unique_ptr<SvStream> xStream; - if ( rDataHelper.GetSotStorageStream( nFormatId, xStream ) && xStream ) + if (std::unique_ptr<SvStream> xStream = rDataHelper.GetSotStorageStream( nFormatId ) ) { // Static variables for per-session storage. This could be // changed to longer-term storage in future. diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx index c14010708079..a9e82b3ec4b7 100644 --- a/sd/source/ui/view/sdview3.cxx +++ b/sd/source/ui/view/sdview3.cxx @@ -321,9 +321,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, // ImageMap? if( !pOwnData && aDataHelper.HasFormat( SotClipboardFormatId::SVIM ) ) { - std::unique_ptr<SvStream> xStm; - - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVIM, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVIM ) ) { pImageMap.reset(new ImageMap); // mba: clipboard always must contain absolute URLs (could be from alien source) @@ -340,9 +338,8 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if( ( bIsRTF || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) ) && ! aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) ) { - std::unique_ptr<SvStream> xStm; - - if( aDataHelper.GetSotStorageStream( bIsRTF ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT, xStm ) ) + auto nFormatId = bIsRTF ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT; + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( nFormatId )) { xStm->Seek( 0 ); @@ -684,8 +681,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if(!bReturn && CHECK_FORMAT_TRANS( SotClipboardFormatId::PDF )) { - std::unique_ptr<SvStream> xStm; - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::PDF, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::PDF )) { Point aInsertPos(rPos); Graphic aGraphic; @@ -704,9 +700,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if(!bReturn && CHECK_FORMAT_TRANS( SotClipboardFormatId::DRAWING )) { - std::unique_ptr<SvStream> xStm; - - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING )) { DrawDocShellRef xShell = new DrawDocShell(SfxObjectCreateMode::INTERNAL, false, DocumentType::Impress); xShell->DoInitNew(); @@ -1226,9 +1220,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if(!bReturn && (!bLink || pPickObj) && CHECK_FORMAT_TRANS(SotClipboardFormatId::SVXB)) { - std::unique_ptr<SvStream> xStm; - - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB )) { Point aInsertPos( rPos ); Graphic aGraphic; @@ -1415,9 +1407,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if(!bReturn && !bLink && CHECK_FORMAT_TRANS(SotClipboardFormatId::HTML)) { - std::unique_ptr<SvStream> xStm; - - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::HTML, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::HTML )) { xStm->Seek( 0 ); // mba: clipboard always must contain absolute URLs (could be from alien source) @@ -1427,8 +1417,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if(!bReturn && !bLink && CHECK_FORMAT_TRANS(SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT)) { - std::unique_ptr<SvStream> xStm; - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT )) { OutlinerView* pOLV = GetTextEditOutlinerView(); @@ -1458,9 +1447,8 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, bool bIsRTF = CHECK_FORMAT_TRANS(SotClipboardFormatId::RTF); if (bIsRTF || CHECK_FORMAT_TRANS(SotClipboardFormatId::RICHTEXT)) { - std::unique_ptr<SvStream> xStm; - - if( aDataHelper.GetSotStorageStream( bIsRTF ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT, xStm ) ) + auto nFormatId = bIsRTF ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT; + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( nFormatId )) { xStm->Seek( 0 ); @@ -1495,9 +1483,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, bool bIsHtmlSimple = CHECK_FORMAT_TRANS(SotClipboardFormatId::HTML_SIMPLE); if (bIsHtmlSimple) { - std::unique_ptr<SvStream> xStm; - - if (aDataHelper.GetSotStorageStream(SotClipboardFormatId::HTML_SIMPLE, xStm)) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream(SotClipboardFormatId::HTML_SIMPLE)) { xStm->Seek(0); diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 857de6ecd413..2194fdd4d4a6 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -542,9 +542,7 @@ bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTrans if( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) ) { - std::unique_ptr<SvStream> xModelStm; - - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xModelStm ) ) + if (std::unique_ptr<SvStream> xModelStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING ) ) bRet = InsertModelStream( *xModelStm, nInsertPos ); } else if( aDataHelper.HasFormat( SotClipboardFormatId::FILE_LIST ) || diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 7e3ea868c816..e1a82a48bd86 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -2177,7 +2177,7 @@ bool SwTransferable::PasteFileContent( const TransferableDataHelper& rData, [[fallthrough]]; // because then test if we get a stream default: - if( rData.GetSotStorageStream( nFormat, xStrm ) ) + if( (xStrm = rData.GetSotStorageStream( nFormat )) ) { if( ( SotClipboardFormatId::HTML_SIMPLE == nFormat ) || ( SotClipboardFormatId::HTML_NO_COMMENT == nFormat ) ) @@ -2767,8 +2767,7 @@ bool SwTransferable::PasteSdrFormat( const TransferableDataHelper& rData, const Point* pPt, SotExchangeActionFlags nActionFlags, bool bNeedToSelectBeforePaste) { bool bRet = false; - std::unique_ptr<SvStream> xStrm; - if( rData.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStrm )) + if( std::unique_ptr<SvStream> xStrm = rData.GetSotStorageStream( SotClipboardFormatId::DRAWING )) { xStrm->SetVersion( SOFFICE_FILEFORMAT_50 ); @@ -2808,9 +2807,7 @@ bool SwTransferable::PasteGrf( const TransferableDataHelper& rData, SwWrtShell& case SotClipboardFormatId::SVXB: { - std::unique_ptr<SvStream> xStm; - - if(rData.GetSotStorageStream(SotClipboardFormatId::SVXB, xStm)) + if (std::unique_ptr<SvStream> xStm = rData.GetSotStorageStream(SotClipboardFormatId::SVXB)) { TypeSerializer aSerializer(*xStm); aSerializer.readGraphic(aGraphic); diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx index 1a1c4781ed22..e99e470312e2 100644 --- a/vcl/source/treelist/transfer.cxx +++ b/vcl/source/treelist/transfer.cxx @@ -1568,29 +1568,32 @@ bool TransferableDataHelper::GetBitmapEx( SotClipboardFormatId nFormat, BitmapEx bool TransferableDataHelper::GetBitmapEx( const DataFlavor& rFlavor, BitmapEx& rBmpEx ) const { - std::unique_ptr<SvStream> xStm; + std::unique_ptr<SvStream> xStm = GetSotStorageStream(rFlavor); DataFlavor aSubstFlavor; - bool bRet(GetSotStorageStream(rFlavor, xStm)); + bool bRet(xStm); bool bSuppressPNG(false); // #122982# If PNG stream not accessed, but BMP one, suppress trying to load PNG bool bSuppressJPEG(false); if(!bRet && HasFormat(SotClipboardFormatId::PNG) && SotExchange::GetFormatDataFlavor(SotClipboardFormatId::PNG, aSubstFlavor)) { // when no direct success, try if PNG is available - bRet = GetSotStorageStream(aSubstFlavor, xStm); + xStm = GetSotStorageStream(aSubstFlavor); + bRet = bool(xStm); bSuppressJPEG = bRet; } if(!bRet && HasFormat(SotClipboardFormatId::JPEG) && SotExchange::GetFormatDataFlavor(SotClipboardFormatId::JPEG, aSubstFlavor)) { - bRet = GetSotStorageStream(aSubstFlavor, xStm); + xStm = GetSotStorageStream(aSubstFlavor); + bRet = bool(xStm); bSuppressPNG = bRet; } if(!bRet && HasFormat(SotClipboardFormatId::BMP) && SotExchange::GetFormatDataFlavor(SotClipboardFormatId::BMP, aSubstFlavor)) { // when no direct success, try if BMP is available - bRet = GetSotStorageStream(aSubstFlavor, xStm); + xStm = GetSotStorageStream(aSubstFlavor); + bRet = bool(xStm); bSuppressPNG = bRet; bSuppressJPEG = bRet; } @@ -1683,7 +1686,7 @@ bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaF DataFlavor aSubstFlavor; bool bRet = false; - if( GetSotStorageStream( rFlavor, xStm ) ) + if( (xStm = GetSotStorageStream( rFlavor )) ) { SvmReader aReader( *xStm ); aReader.Read( rMtf ); @@ -1693,7 +1696,7 @@ bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaF if( !bRet && HasFormat( SotClipboardFormatId::EMF ) && SotExchange::GetFormatDataFlavor( SotClipboardFormatId::EMF, aSubstFlavor ) && - GetSotStorageStream( aSubstFlavor, xStm ) ) + (xStm = GetSotStorageStream( aSubstFlavor)) ) { Graphic aGraphic; @@ -1707,7 +1710,7 @@ bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaF if( !bRet && HasFormat( SotClipboardFormatId::WMF ) && SotExchange::GetFormatDataFlavor( SotClipboardFormatId::WMF, aSubstFlavor ) && - GetSotStorageStream( aSubstFlavor, xStm ) ) + (xStm = GetSotStorageStream( aSubstFlavor ) ) ) { Graphic aGraphic; @@ -1762,8 +1765,7 @@ bool TransferableDataHelper::GetGraphic( const css::datatransfer::DataFlavor& rF TransferableDataHelper::IsEqual(aFlavor, rFlavor)) { Graphic aGraphic; - std::unique_ptr<SvStream> xStm; - if (GetSotStorageStream(rFlavor, xStm)) + if (std::unique_ptr<SvStream> xStm = GetSotStorageStream(rFlavor)) { if (GraphicConverter::Import(*xStm, aGraphic) == ERRCODE_NONE) { @@ -1800,9 +1802,7 @@ bool TransferableDataHelper::GetGraphic( const css::datatransfer::DataFlavor& rF } else { - std::unique_ptr<SvStream> xStm; - - if( GetSotStorageStream( rFlavor, xStm ) ) + if (std::unique_ptr<SvStream> xStm = GetSotStorageStream( rFlavor) ) { TypeSerializer aSerializer(*xStm); aSerializer.readGraphic(rGraphic); @@ -1823,14 +1823,12 @@ bool TransferableDataHelper::GetImageMap( SotClipboardFormatId nFormat, ImageMap bool TransferableDataHelper::GetImageMap( const css::datatransfer::DataFlavor& rFlavor, ImageMap& rIMap ) const { - std::unique_ptr<SvStream> xStm; - bool bRet = GetSotStorageStream( rFlavor, xStm ); + std::unique_ptr<SvStream> xStm = GetSotStorageStream( rFlavor); + if (!xStm) + return false; - if( bRet ) - { - rIMap.Read( *xStm ); - bRet = ( xStm->GetError() == ERRCODE_NONE ); - } + rIMap.Read( *xStm ); + bool bRet = ( xStm->GetError() == ERRCODE_NONE ); return bRet; } @@ -2018,11 +2016,11 @@ bool TransferableDataHelper::GetINetImage( const css::datatransfer::DataFlavor& rFlavor, INetImage& rINtImg ) const { - std::unique_ptr<SvStream> xStm; - bool bRet = GetSotStorageStream( rFlavor, xStm ); + std::unique_ptr<SvStream> xStm = GetSotStorageStream( rFlavor ); + if (!xStm) + return false; - if( bRet ) - bRet = rINtImg.Read( *xStm, SotExchange::GetFormat( rFlavor ) ); + bool bRet = rINtImg.Read( *xStm, SotExchange::GetFormat( rFlavor ) ); return bRet; } @@ -2037,7 +2035,6 @@ bool TransferableDataHelper::GetFileList( SotClipboardFormatId nFormat, bool TransferableDataHelper::GetFileList( FileList& rFileList ) const { - std::unique_ptr<SvStream> xStm; bool bRet = false; for( sal_uInt32 i = 0, nFormatCount = GetFormatCount(); ( i < nFormatCount ) && !bRet; ++i ) @@ -2046,7 +2043,7 @@ bool TransferableDataHelper::GetFileList( FileList& rFileList ) const { const DataFlavor aFlavor( GetFormatDataFlavor( i ) ); - if( GetSotStorageStream( aFlavor, xStm ) ) + if (std::unique_ptr<SvStream> xStm = GetSotStorageStream( aFlavor )) { if( aFlavor.MimeType.indexOf( "text/uri-list" ) > -1 ) { @@ -2087,22 +2084,24 @@ Sequence<sal_Int8> TransferableDataHelper::GetSequence( const DataFlavor& rFlavo return aSeq; } -bool TransferableDataHelper::GetSotStorageStream( SotClipboardFormatId nFormat, std::unique_ptr<SvStream>& rxStream ) const +std::unique_ptr<SvStream> TransferableDataHelper::GetSotStorageStream( SotClipboardFormatId nFormat ) const { DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSotStorageStream( aFlavor, rxStream ) ); + if (!SotExchange::GetFormatDataFlavor( nFormat, aFlavor )) + return nullptr; + return GetSotStorageStream( aFlavor ); } -bool TransferableDataHelper::GetSotStorageStream( const DataFlavor& rFlavor, std::unique_ptr<SvStream>& rxStream ) const +std::unique_ptr<SvStream> TransferableDataHelper::GetSotStorageStream( const DataFlavor& rFlavor ) const { Sequence<sal_Int8> aSeq = GetSequence(rFlavor, OUString()); if (!aSeq.hasElements()) - return false; + return nullptr; - rxStream = SotTempStream::Create( "" ); - rxStream->WriteBytes( aSeq.getConstArray(), aSeq.getLength() ); - rxStream->Seek(0); - return true; + std::unique_ptr<SvStream> xStream = SotTempStream::Create( "" ); + xStream->WriteBytes( aSeq.getConstArray(), aSeq.getLength() ); + xStream->Seek(0); + return xStream; } Reference<XInputStream> TransferableDataHelper::GetInputStream( SotClipboardFormatId nFormat, const OUString& rDestDoc ) const
