diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2020-03-09 11:53:50 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-04-02 12:57:57 +0200 |
commit | 84b884135ee419fe7abfefa7b4b651a649cf9ad9 (patch) | |
tree | a5ba5d8e81d832c30099e7fe76764a48caf43f4e /basic/source | |
parent | 0ec042dd2488989e7a9c45309b408ec8b8326208 (diff) |
tdf#79426, tdf#125180 - Don't convert missing parameters to requested type
If a particular parameter type is requested during the
construction of a parameter list, don't convert missing
parameters to avoid implicit casting to the specified
data type and value of the method.
Missing parameters are handled in StepEMPTY, where
additional information about missing parameters is added.
Change-Id: Ia413b2996d7d1feecedc1dfefaf6baf0fd9d917e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90215
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/source')
-rw-r--r-- | basic/source/inc/runtime.hxx | 5 | ||||
-rw-r--r-- | basic/source/runtime/runtime.cxx | 38 |
2 files changed, 39 insertions, 4 deletions
diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx index 1b0a3309367d..3b59a5b18341 100644 --- a/basic/source/inc/runtime.hxx +++ b/basic/source/inc/runtime.hxx @@ -348,6 +348,11 @@ public: sal_Int32 nLine,nCol1,nCol2; SbiRuntime* pNext; // Stack-Chain + // tdf#79426, tdf#125180 - adds the information about a missing parameter + static void SetIsMissing( SbxVariable* ); + // tdf#79426, tdf#125180 - checks if a variable contains the information about a missing parameter + static bool IsMissing( SbxVariable*, sal_uInt16 ); + SbiRuntime( SbModule*, SbMethod*, sal_uInt32 ); ~SbiRuntime(); void Error( ErrCode, bool bVBATranslationAlreadyDone = false ); // set error if != 0 diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 15b45ec736a0..279f26f48971 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -621,6 +621,20 @@ void SbiRuntime::SetVBAEnabled(bool bEnabled ) } } +// tdf#79426, tdf#125180 - adds the information about a missing parameter +void SbiRuntime::SetIsMissing( SbxVariable* pVar ) +{ + SbxInfo* pInfo = pVar->GetInfo() ? pVar->GetInfo() : new SbxInfo(); + pInfo->AddParam( pVar->GetName(), SbxMISSING, pVar->GetFlags() ); + pVar->SetInfo( pInfo ); +} + +// tdf#79426, tdf#125180 - checks if a variable contains the information about a missing parameter +bool SbiRuntime::IsMissing( SbxVariable* pVar, sal_uInt16 nIdx ) +{ + return pVar->GetInfo() && pVar->GetInfo()->GetParam( nIdx ) && pVar->GetInfo()->GetParam( nIdx )->eType & SbxMISSING; +} + // Construction of the parameter list. All ByRef-parameters are directly // taken over; copies of ByVal-parameters are created. If a particular // data type is requested, it is converted. @@ -671,7 +685,11 @@ void SbiRuntime::SetParameters( SbxArray* pParams ) if( p ) { bByVal |= ( p->eType & SbxBYREF ) == 0; - t = static_cast<SbxDataType>( p->eType & 0x0FFF ); + // tdf#79426, tdf#125180 - don't convert missing arguments to the requested parameter type + if ( t != SbxEMPTY && !IsMissing( v, 1 ) ) + { + t = static_cast<SbxDataType>( p->eType & 0x0FFF ); + } if( !bByVal && t != SbxVARIANT && (!v->IsFixed() || static_cast<SbxDataType>(v->GetType() & 0x0FFF ) != t) ) @@ -683,18 +701,25 @@ void SbiRuntime::SetParameters( SbxArray* pParams ) } if( bByVal ) { - if( bTargetTypeIsArray ) + // tdf#79426, tdf#125180 - don't convert missing arguments to the requested parameter type + if( bTargetTypeIsArray && !IsMissing( v, 1 ) ) { t = SbxOBJECT; } SbxVariable* v2 = new SbxVariable( t ); v2->SetFlag( SbxFlagBits::ReadWrite ); + // tdf#79426, tdf#125180 - if parameter was missing, readd additional information about a missing parameter + if ( IsMissing( v, 1 ) ) + { + SetIsMissing( v2 ); + } *v2 = *v; refParams->Put32( v2, i ); } else { - if( t != SbxVARIANT && t != ( v->GetType() & 0x0FFF ) ) + // tdf#79426, tdf#125180 - don't convert missing arguments to the requested parameter type + if( t != SbxVARIANT && !IsMissing( v, 1 ) && t != ( v->GetType() & 0x0FFF ) ) { if( p && (p->eType & SbxARRAY) ) { @@ -2749,6 +2774,8 @@ void SbiRuntime::StepEMPTY() // to simplify matters. SbxVariableRef xVar = new SbxVariable( SbxVARIANT ); xVar->PutErr( 448 ); + // tdf#79426, tdf#125180 - add additional information about a missing parameter + SetIsMissing( xVar.get() ); PushVar( xVar.get() ); } @@ -4047,13 +4074,16 @@ void SbiRuntime::StepPARAM( sal_uInt32 nOp1, sal_uInt32 nOp2 ) { pVar = new SbxVariable(); pVar->PutErr( 448 ); // like in VB: Error-Code 448 (ERRCODE_BASIC_NAMED_NOT_FOUND) + // tdf#79426, tdf#125180 - add additional information about a missing parameter + SetIsMissing( pVar ); refParams->Put32( pVar, iLoop ); iLoop--; } } pVar = refParams->Get32( nIdx ); - if( pVar->GetType() == SbxERROR && nIdx ) + // tdf#79426, tdf#125180 - check for optionals only if the parameter is actually missing + if( pVar->GetType() == SbxERROR && IsMissing( pVar, 1 ) && nIdx ) { // if there's a parameter missing, it can be OPTIONAL bool bOpt = false; |