Kaydet (Commit) 29413c3a authored tarafından Zolnai Tamás's avatar Zolnai Tamás

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
üst fe272a75
......@@ -177,6 +177,7 @@ public:
sal_uLong GetDocFilePos() const;
bool SwapOut();
void SwapOutAsLink();
bool SwapOut( SvStream* pOStm );
bool SwapIn();
bool SwapIn( SvStream* pIStm );
......
......@@ -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 )
......
......@@ -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;
}
......
......@@ -143,6 +143,7 @@ private:
bool ImplSwapIn( SvStream* pIStm );
bool ImplSwapOut();
void ImplSwapOutAsLink();
bool ImplSwapOut( SvStream* pOStm );
bool ImplIsSwapOut() const { return mbSwapOut;}
......
......@@ -522,6 +522,12 @@ bool Graphic::SwapOut()
return mpImpGraphic->ImplSwapOut();
}
void Graphic::SwapOutAsLink()
{
ImplTestRefCount();
mpImpGraphic->ImplSwapOutAsLink();
}
bool Graphic::SwapOut( SvStream* pOStream )
{
ImplTestRefCount();
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment