From f4ff0ed55707078868415541c4a1aebd3db1e142 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 19 Jun 2022 23:10:57 +0300 Subject: tdf#149622: also clear return value before calling method from SbxObject::Call Moves the custom cleanup logic to overridden SbxMethod::Clear, to simplify the cleanup code and make sure it restores empty Variant correctly. Change-Id: I01fa0529acd9ac787ffcda60fd6836ade4afdcb1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136108 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- basic/source/sbx/sbxobj.cxx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'basic/source/sbx') diff --git a/basic/source/sbx/sbxobj.cxx b/basic/source/sbx/sbxobj.cxx index 7f3560a62003..a6cbeaba5ca7 100644 --- a/basic/source/sbx/sbxobj.cxx +++ b/basic/source/sbx/sbxobj.cxx @@ -29,6 +29,7 @@ #include #include #include +#include "sbxdec.hxx" #include "sbxres.hxx" @@ -262,6 +263,9 @@ bool SbxObject::Call( const OUString& rName, SbxArray* pParam ) SbxVariable* pMeth = FindQualified( rName, SbxClassType::DontCare); if( dynamic_cast( pMeth) ) { + // tdf#149622 - clear return value of the method before calling it + pMeth->Clear(); + // FindQualified() might have struck already! if( pParam ) { @@ -850,6 +854,36 @@ SbxClassType SbxMethod::GetClass() const return SbxClassType::Method; } +void SbxMethod::Clear() +{ + // Release referenced data, and reset data type to the function return type + // Implementation similar to SbxValue::SetType + // tdf#143582: Don't take "read-only" flag into account, allow clearing method return value + switch (aData.eType) + { + case SbxSTRING: + delete aData.pOUString; + break; + case SbxOBJECT: + if (aData.pObj) + { + if (aData.pObj != this) + { + bool bParentProp = (GetUserData() & 0xFFFF) == 5345; // See sbxvalue.cxx + if (!bParentProp) + aData.pObj->ReleaseRef(); + } + } + break; + case SbxDECIMAL: + releaseDecimalPtr(aData.pDecimal); + break; + default: + break; + } + aData.clear(IsFixed() ? aData.eType : SbxEMPTY); +} + SbxProperty::SbxProperty( const OUString& r, SbxDataType t ) : SbxVariable( t ) { -- cgit