summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAron Budea <aron.budea@collabora.com>2024-01-28 21:46:32 +1030
committerAron Budea <aron.budea@collabora.com>2024-02-09 00:30:21 +0100
commit8318337c3e30075acc72fa8c9d5051c33319fdf5 (patch)
tree74b977b78a98e59dbbc95e509b38fa8198fd2062
parentClone Formatting in Impress: Include list attribute (diff)
downloadcore-8318337c3e30075acc72fa8c9d5051c33319fdf5.tar.gz
core-8318337c3e30075acc72fa8c9d5051c33319fdf5.zip
tdf#147132 tdf#154285 basic: Flatten and check param count of Is* fns
Change-Id: I6d27dd49613a5cc26f4244dadc9bdd65361a0475 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162657 Tested-by: Jenkins Reviewed-by: Aron Budea <aron.budea@collabora.com>
-rw-r--r--basic/source/runtime/methods.cxx190
1 files changed, 81 insertions, 109 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index ad3b638805a2..d58a2cef9ee0 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -2272,162 +2272,134 @@ void SbRtl_Date(StarBASIC *, SbxArray & rPar, bool bWrite)
void SbRtl_IsArray(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- rPar.Get(0)->PutBool((rPar.Get(1)->GetType() & SbxARRAY) != 0);
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ rPar.Get(0)->PutBool((rPar.Get(1)->GetType() & SbxARRAY) != 0);
}
void SbRtl_IsObject(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- SbxVariable* pVar = rPar.Get(1);
- bool bObject = pVar->IsObject();
- SbxBase* pObj = (bObject ? pVar->GetObject() : nullptr);
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- if( auto pUnoClass = dynamic_cast<SbUnoClass*>( pObj) )
- {
- bObject = pUnoClass->getUnoClass().is();
- }
- rPar.Get(0)->PutBool(bObject);
+ SbxVariable* pVar = rPar.Get(1);
+ bool bObject = pVar->IsObject();
+ SbxBase* pObj = (bObject ? pVar->GetObject() : nullptr);
+
+ if( auto pUnoClass = dynamic_cast<SbUnoClass*>( pObj) )
+ {
+ bObject = pUnoClass->getUnoClass().is();
}
+ rPar.Get(0)->PutBool(bObject);
}
void SbRtl_IsDate(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ // #46134 only string is converted, all other types result in sal_False
+ SbxVariableRef xArg = rPar.Get(1);
+ SbxDataType eType = xArg->GetType();
+ bool bDate = false;
+
+ if( eType == SbxDATE )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ bDate = true;
}
- else
+ else if( eType == SbxSTRING )
{
- // #46134 only string is converted, all other types result in sal_False
- SbxVariableRef xArg = rPar.Get(1);
- SbxDataType eType = xArg->GetType();
- bool bDate = false;
-
- if( eType == SbxDATE )
- {
- bDate = true;
- }
- else if( eType == SbxSTRING )
- {
- ErrCode nPrevError = SbxBase::GetError();
- SbxBase::ResetError();
+ ErrCode nPrevError = SbxBase::GetError();
+ SbxBase::ResetError();
- // force conversion of the parameter to SbxDATE
- xArg->SbxValue::GetDate();
+ // force conversion of the parameter to SbxDATE
+ xArg->SbxValue::GetDate();
- bDate = !SbxBase::IsError();
+ bDate = !SbxBase::IsError();
- SbxBase::ResetError();
- SbxBase::SetError( nPrevError );
- }
- rPar.Get(0)->PutBool(bDate);
+ SbxBase::ResetError();
+ SbxBase::SetError( nPrevError );
}
+ rPar.Get(0)->PutBool(bDate);
}
void SbRtl_IsEmpty(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pVar = nullptr;
+ if( SbiRuntime::isVBAEnabled() )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ pVar = getDefaultProp(rPar.Get(1));
+ }
+ if ( pVar )
+ {
+ pVar->Broadcast( SfxHintId::BasicDataWanted );
+ rPar.Get(0)->PutBool(pVar->IsEmpty());
}
else
{
- SbxVariable* pVar = nullptr;
- if( SbiRuntime::isVBAEnabled() )
- {
- pVar = getDefaultProp(rPar.Get(1));
- }
- if ( pVar )
- {
- pVar->Broadcast( SfxHintId::BasicDataWanted );
- rPar.Get(0)->PutBool(pVar->IsEmpty());
- }
- else
- {
- rPar.Get(0)->PutBool(rPar.Get(1)->IsEmpty());
- }
+ rPar.Get(0)->PutBool(rPar.Get(1)->IsEmpty());
}
}
void SbRtl_IsError(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pVar = rPar.Get(1);
+ SbUnoObject* pObj = dynamic_cast<SbUnoObject*>( pVar );
+ if ( !pObj )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ if ( SbxBase* pBaseObj = (pVar->IsObject() ? pVar->GetObject() : nullptr) )
+ {
+ pObj = dynamic_cast<SbUnoObject*>( pBaseObj );
+ }
+ }
+ uno::Reference< script::XErrorQuery > xError;
+ if ( pObj )
+ {
+ xError.set( pObj->getUnoAny(), uno::UNO_QUERY );
+ }
+ if ( xError.is() )
+ {
+ rPar.Get(0)->PutBool(xError->hasError());
}
else
{
- SbxVariable* pVar = rPar.Get(1);
- SbUnoObject* pObj = dynamic_cast<SbUnoObject*>( pVar );
- if ( !pObj )
- {
- if ( SbxBase* pBaseObj = (pVar->IsObject() ? pVar->GetObject() : nullptr) )
- {
- pObj = dynamic_cast<SbUnoObject*>( pBaseObj );
- }
- }
- uno::Reference< script::XErrorQuery > xError;
- if ( pObj )
- {
- xError.set( pObj->getUnoAny(), uno::UNO_QUERY );
- }
- if ( xError.is() )
- {
- rPar.Get(0)->PutBool(xError->hasError());
- }
- else
- {
- rPar.Get(0)->PutBool(rPar.Get(1)->IsErr());
- }
+ rPar.Get(0)->PutBool(rPar.Get(1)->IsErr());
}
}
void SbRtl_IsNull(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ // #51475 because of Uno-objects return true
+ // even if the pObj value is NULL
+ SbxVariableRef pArg = rPar.Get(1);
+ bool bNull = rPar.Get(1)->IsNull();
+ if( !bNull && pArg->GetType() == SbxOBJECT )
{
- // #51475 because of Uno-objects return true
- // even if the pObj value is NULL
- SbxVariableRef pArg = rPar.Get(1);
- bool bNull = rPar.Get(1)->IsNull();
- if( !bNull && pArg->GetType() == SbxOBJECT )
+ SbxBase* pObj = pArg->GetObject();
+ if( !pObj )
{
- SbxBase* pObj = pArg->GetObject();
- if( !pObj )
- {
- bNull = true;
- }
+ bNull = true;
}
- rPar.Get(0)->PutBool(bNull);
}
+ rPar.Get(0)->PutBool(bNull);
}
void SbRtl_IsNumeric(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- rPar.Get(0)->PutBool(rPar.Get(1)->IsNumericRTL());
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ rPar.Get(0)->PutBool(rPar.Get(1)->IsNumericRTL());
}