summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2024-04-07 20:23:26 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-04-08 23:16:25 +0200
commite7bb3a52067c426eedffddf86e7d5f0903562da2 (patch)
treea655ee4aed8ceedc61dde01f68619f7202344045 /sc
parentc16f7ca43bb338f23895733ee499505ee6a6e72e (diff)
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 <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/app/transobj.cxx4
-rw-r--r--sc/source/ui/view/gridwin.cxx2
-rw-r--r--sc/source/ui/view/viewfun3.cxx24
-rw-r--r--sc/source/ui/view/viewfun4.cxx4
-rw-r--r--sc/source/ui/view/viewfun5.cxx9
5 files changed, 19 insertions, 24 deletions
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.