summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-10-19 18:25:23 +0200
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-11-07 10:45:06 +0100
commit29413c3ae9dfe99048580710f0b1d95c9663d508 (patch)
treebbdda483bea2820e7e3f318f24239191e76ba828
parentfe272a757b60fdf267539102b0a9927f68e1526a (diff)
Avoid using null pointer as a special indicator
When ImpGraphic::ImplSwapOut() is called with null pointer it was assumed that it is becase the graphic is a link and so we don't need to swap out it actually (we can load it anytime using the link), only clear the graphic's internal data. The problem with that it can happen that ImplSwapOut() is called with null pointer accidentally on a non-link graphic object which leads to that we loose the graphic. Seems more robust to use an explicit indicator (GRFMGR_AUTOSWAPSTREAM_LINK) for links swapout. indicator Change-Id: Icf31524a192c7866278ba6a13eb85648aa69f554
-rw-r--r--include/vcl/graph.hxx1
-rw-r--r--svtools/source/graphic/grfmgr.cxx13
-rw-r--r--sw/source/core/graphic/ndgrf.cxx2
-rw-r--r--vcl/inc/impgraph.hxx1
-rw-r--r--vcl/source/gdi/graph.cxx6
-rw-r--r--vcl/source/gdi/impgraph.cxx9
6 files changed, 27 insertions, 5 deletions
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index 24d9e427de3b..b55e79015cec 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -177,6 +177,7 @@ public:
sal_uLong GetDocFilePos() const;
bool SwapOut();
+ void SwapOutAsLink();
bool SwapOut( SvStream* pOStm );
bool SwapIn();
bool SwapIn( SvStream* pIStm );
diff --git a/svtools/source/graphic/grfmgr.cxx b/svtools/source/graphic/grfmgr.cxx
index 6c7c93326529..f02b185b4bda 100644
--- a/svtools/source/graphic/grfmgr.cxx
+++ b/svtools/source/graphic/grfmgr.cxx
@@ -1099,7 +1099,16 @@ bool GraphicObject::SwapOut()
bool GraphicObject::SwapOut( SvStream* pOStm )
{
- const bool bRet = !mbAutoSwapped && maGraphic.SwapOut( pOStm );
+ bool bRet = !mbAutoSwapped;
+ // swap out as a link
+ if( pOStm == GRFMGR_AUTOSWAPSTREAM_LINK )
+ {
+ maGraphic.SwapOutAsLink();
+ }
+ else
+ {
+ bRet = bRet && maGraphic.SwapOut( pOStm );
+ }
if( bRet && mpMgr )
mpMgr->ImplGraphicObjectWasSwappedOut( *this );
@@ -1158,7 +1167,7 @@ IMPL_LINK_NOARG(GraphicObject, ImplAutoSwapOutHdl)
if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
{
if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
- mbAutoSwapped = SwapOut( NULL );
+ mbAutoSwapped = SwapOut( GRFMGR_AUTOSWAPSTREAM_LINK );
else
{
if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx
index 280c6d45b7e1..4b7152b422ad 100644
--- a/sw/source/core/graphic/ndgrf.cxx
+++ b/sw/source/core/graphic/ndgrf.cxx
@@ -621,7 +621,7 @@ bool SwGrfNode::SwapOut()
return false;
}
// written graphics and links are removed here
- return maGrfObj.SwapOut( NULL );
+ return maGrfObj.SwapOut( GRFMGR_AUTOSWAPSTREAM_LINK );
}
return true;
}
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index 2242b44ea574..513074d1d286 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -143,6 +143,7 @@ private:
bool ImplSwapIn( SvStream* pIStm );
bool ImplSwapOut();
+ void ImplSwapOutAsLink();
bool ImplSwapOut( SvStream* pOStm );
bool ImplIsSwapOut() const { return mbSwapOut;}
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index 4fe916ac5ade..2e39e5e81f94 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -522,6 +522,12 @@ bool Graphic::SwapOut()
return mpImpGraphic->ImplSwapOut();
}
+void Graphic::SwapOutAsLink()
+{
+ ImplTestRefCount();
+ mpImpGraphic->ImplSwapOutAsLink();
+}
+
bool Graphic::SwapOut( SvStream* pOStream )
{
ImplTestRefCount();
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 9dc49081b468..9a1b818ffafd 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1349,6 +1349,12 @@ bool ImpGraphic::ImplSwapOut()
return bRet;
}
+void ImpGraphic::ImplSwapOutAsLink()
+{
+ ImplClearGraphics( true );
+ mbSwapOut = true;
+}
+
bool ImpGraphic::ImplSwapOut( SvStream* pOStm )
{
bool bRet = false;
@@ -1370,8 +1376,7 @@ bool ImpGraphic::ImplSwapOut( SvStream* pOStm )
}
else
{
- ImplClearGraphics( true );
- bRet = mbSwapOut = true;
+ SAL_WARN("vcl.gdi", "Graphic SwapOut: No stream for swap out!");
}
return bRet;