Kaydet (Commit) cb9d192f authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#120703 PVS: V547 Expression '!pRTLData' is always false

Let SbiInstance::GetRTLData() return reference

Change-Id: Iafe7e64f6f296b478003ce66ea66936a65ba9edc
Reviewed-on: https://gerrit.libreoffice.org/62855
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 16b73886
...@@ -184,7 +184,7 @@ public: ...@@ -184,7 +184,7 @@ public:
SbiDdeControl* GetDdeControl() { return pDdeCtrl.get(); } SbiDdeControl* GetDdeControl() { return pDdeCtrl.get(); }
StarBASIC* GetBasic() { return pBasic; } StarBASIC* GetBasic() { return pBasic; }
SbiDllMgr* GetDllMgr(); SbiDllMgr* GetDllMgr();
SbiRTLData* GetRTLData() const { return const_cast<SbiRTLData*>(&aRTLData); } SbiRTLData& GetRTLData() const { return const_cast<SbiRTLData&>(aRTLData); }
std::shared_ptr<SvNumberFormatter> const & GetNumberFormatter(); std::shared_ptr<SvNumberFormatter> const & GetNumberFormatter();
sal_uInt32 GetStdDateIdx() const { return nStdDateIdx; } sal_uInt32 GetStdDateIdx() const { return nStdDateIdx; }
......
...@@ -2521,15 +2521,15 @@ void SbRtl_IsMissing(StarBASIC *, SbxArray & rPar, bool) ...@@ -2521,15 +2521,15 @@ void SbRtl_IsMissing(StarBASIC *, SbxArray & rPar, bool)
} }
// Function looks for wildcards, removes them and always returns the pure path // Function looks for wildcards, removes them and always returns the pure path
static OUString implSetupWildcard( const OUString& rFileParam, SbiRTLData* pRTLData ) static OUString implSetupWildcard(const OUString& rFileParam, SbiRTLData& rRTLData)
{ {
static sal_Char cDelim1 = '/'; static sal_Char cDelim1 = '/';
static sal_Char cDelim2 = '\\'; static sal_Char cDelim2 = '\\';
static sal_Char cWild1 = '*'; static sal_Char cWild1 = '*';
static sal_Char cWild2 = '?'; static sal_Char cWild2 = '?';
pRTLData->pWildCard.reset(); rRTLData.pWildCard.reset();
pRTLData->sFullNameToBeChecked.clear(); rRTLData.sFullNameToBeChecked.clear();
OUString aFileParam = rFileParam; OUString aFileParam = rFileParam;
sal_Int32 nLastWild = aFileParam.lastIndexOf( cWild1 ); sal_Int32 nLastWild = aFileParam.lastIndexOf( cWild1 );
...@@ -2558,7 +2558,7 @@ static OUString implSetupWildcard( const OUString& rFileParam, SbiRTLData* pRTLD ...@@ -2558,7 +2558,7 @@ static OUString implSetupWildcard( const OUString& rFileParam, SbiRTLData* pRTLD
OUString aPathStr = getFullPath( aFileParam ); OUString aPathStr = getFullPath( aFileParam );
if( nLastDelim != aFileParam.getLength() - 1 ) if( nLastDelim != aFileParam.getLength() - 1 )
{ {
pRTLData->sFullNameToBeChecked = aPathStr; rRTLData.sFullNameToBeChecked = aPathStr;
} }
return aPathStr; return aPathStr;
} }
...@@ -2582,18 +2582,18 @@ static OUString implSetupWildcard( const OUString& rFileParam, SbiRTLData* pRTLD ...@@ -2582,18 +2582,18 @@ static OUString implSetupWildcard( const OUString& rFileParam, SbiRTLData* pRTLD
// invalid anyway because it was not accepted by OSL before // invalid anyway because it was not accepted by OSL before
if (aPureFileName != "*") if (aPureFileName != "*")
{ {
pRTLData->pWildCard = o3tl::make_unique<WildCard>( aPureFileName ); rRTLData.pWildCard = o3tl::make_unique<WildCard>(aPureFileName);
} }
return aPathStr; return aPathStr;
} }
static bool implCheckWildcard( const OUString& rName, SbiRTLData const * pRTLData ) static bool implCheckWildcard(const OUString& rName, SbiRTLData const& rRTLData)
{ {
bool bMatch = true; bool bMatch = true;
if( pRTLData->pWildCard ) if (rRTLData.pWildCard)
{ {
bMatch = pRTLData->pWildCard->Matches( rName ); bMatch = rRTLData.pWildCard->Matches(rName);
} }
return bMatch; return bMatch;
} }
...@@ -2641,14 +2641,8 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2641,14 +2641,8 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
} }
else else
{ {
SbiRTLData* pRTLData = GetSbData()->pInst->GetRTLData(); SbiRTLData& rRTLData = GetSbData()->pInst->GetRTLData();
// #34645: can also be called from the URL line via 'macro: Dir'
// there's no pRTLDate existing in that case and the method must be left
if( !pRTLData )
{
return;
}
if( hasUno() ) if( hasUno() )
{ {
const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess(); const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
...@@ -2658,8 +2652,8 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2658,8 +2652,8 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
{ {
OUString aFileParam = rPar.Get(1)->GetOUString(); OUString aFileParam = rPar.Get(1)->GetOUString();
OUString aFileURLStr = implSetupWildcard( aFileParam, pRTLData ); OUString aFileURLStr = implSetupWildcard(aFileParam, rRTLData);
if( !pRTLData->sFullNameToBeChecked.isEmpty()) if (!rRTLData.sFullNameToBeChecked.isEmpty())
{ {
bool bExists = false; bool bExists = false;
try { bExists = xSFI->exists( aFileURLStr ); } try { bExists = xSFI->exists( aFileURLStr ); }
...@@ -2693,16 +2687,17 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2693,16 +2687,17 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
SbAttributes nFlags = SbAttributes::NONE; SbAttributes nFlags = SbAttributes::NONE;
if ( nParCount > 2 ) if ( nParCount > 2 )
{ {
pRTLData->nDirFlags = nFlags = static_cast<SbAttributes>(rPar.Get(2)->GetInteger()); rRTLData.nDirFlags = nFlags
= static_cast<SbAttributes>(rPar.Get(2)->GetInteger());
} }
else else
{ {
pRTLData->nDirFlags = SbAttributes::NONE; rRTLData.nDirFlags = SbAttributes::NONE;
} }
// Read directory // Read directory
bool bIncludeFolders = bool(nFlags & SbAttributes::DIRECTORY); bool bIncludeFolders = bool(nFlags & SbAttributes::DIRECTORY);
pRTLData->aDirSeq = xSFI->getFolderContents( aDirURLStr, bIncludeFolders ); rRTLData.aDirSeq = xSFI->getFolderContents(aDirURLStr, bIncludeFolders);
pRTLData->nCurDirPos = 0; rRTLData.nCurDirPos = 0;
// #78651 Add "." and ".." directories for VB compatibility // #78651 Add "." and ".." directories for VB compatibility
if( bIncludeFolders ) if( bIncludeFolders )
...@@ -2715,7 +2710,7 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2715,7 +2710,7 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
// returned "." and for -1 ".." // returned "." and for -1 ".."
if( !bRoot ) if( !bRoot )
{ {
pRTLData->nCurDirPos = -2; rRTLData.nCurDirPos = -2;
} }
} }
} }
...@@ -2725,35 +2720,36 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2725,35 +2720,36 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
} }
if( pRTLData->aDirSeq.getLength() > 0 ) if (rRTLData.aDirSeq.getLength() > 0)
{ {
bool bFolderFlag = bool(pRTLData->nDirFlags & SbAttributes::DIRECTORY); bool bFolderFlag = bool(rRTLData.nDirFlags & SbAttributes::DIRECTORY);
SbiInstance* pInst = GetSbData()->pInst; SbiInstance* pInst = GetSbData()->pInst;
bool bCompatibility = ( pInst && pInst->IsCompatibility() ); bool bCompatibility = ( pInst && pInst->IsCompatibility() );
for( ;; ) for( ;; )
{ {
if( pRTLData->nCurDirPos < 0 ) if (rRTLData.nCurDirPos < 0)
{ {
if( pRTLData->nCurDirPos == -2 ) if (rRTLData.nCurDirPos == -2)
{ {
aPath = "."; aPath = ".";
} }
else if( pRTLData->nCurDirPos == -1 ) else if (rRTLData.nCurDirPos == -1)
{ {
aPath = ".."; aPath = "..";
} }
pRTLData->nCurDirPos++; rRTLData.nCurDirPos++;
} }
else if( pRTLData->nCurDirPos >= pRTLData->aDirSeq.getLength() ) else if (rRTLData.nCurDirPos >= rRTLData.aDirSeq.getLength())
{ {
pRTLData->aDirSeq.realloc( 0 ); rRTLData.aDirSeq.realloc(0);
aPath.clear(); aPath.clear();
break; break;
} }
else else
{ {
OUString aFile = pRTLData->aDirSeq.getConstArray()[pRTLData->nCurDirPos++]; OUString aFile
= rRTLData.aDirSeq.getConstArray()[rRTLData.nCurDirPos++];
if( bCompatibility ) if( bCompatibility )
{ {
...@@ -2784,7 +2780,7 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2784,7 +2780,7 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
INetURLObject::DecodeMechanism::WithCharset ); INetURLObject::DecodeMechanism::WithCharset );
} }
bool bMatch = implCheckWildcard( aPath, pRTLData ); bool bMatch = implCheckWildcard(aPath, rRTLData);
if( !bMatch ) if( !bMatch )
{ {
continue; continue;
...@@ -2802,31 +2798,32 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2802,31 +2798,32 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
{ {
OUString aFileParam = rPar.Get(1)->GetOUString(); OUString aFileParam = rPar.Get(1)->GetOUString();
OUString aDirURL = implSetupWildcard( aFileParam, pRTLData ); OUString aDirURL = implSetupWildcard(aFileParam, rRTLData);
SbAttributes nFlags = SbAttributes::NONE; SbAttributes nFlags = SbAttributes::NONE;
if ( nParCount > 2 ) if ( nParCount > 2 )
{ {
pRTLData->nDirFlags = nFlags = static_cast<SbAttributes>( rPar.Get(2)->GetInteger() ); rRTLData.nDirFlags = nFlags
= static_cast<SbAttributes>(rPar.Get(2)->GetInteger());
} }
else else
{ {
pRTLData->nDirFlags = SbAttributes::NONE; rRTLData.nDirFlags = SbAttributes::NONE;
} }
// Read directory // Read directory
bool bIncludeFolders = bool(nFlags & SbAttributes::DIRECTORY); bool bIncludeFolders = bool(nFlags & SbAttributes::DIRECTORY);
pRTLData->pDir = o3tl::make_unique<Directory>( aDirURL ); rRTLData.pDir = o3tl::make_unique<Directory>(aDirURL);
FileBase::RC nRet = pRTLData->pDir->open(); FileBase::RC nRet = rRTLData.pDir->open();
if( nRet != FileBase::E_None ) if( nRet != FileBase::E_None )
{ {
pRTLData->pDir.reset(); rRTLData.pDir.reset();
rPar.Get(0)->PutString( OUString() ); rPar.Get(0)->PutString( OUString() );
return; return;
} }
// #86950 Add "." and ".." directories for VB compatibility // #86950 Add "." and ".." directories for VB compatibility
pRTLData->nCurDirPos = 0; rRTLData.nCurDirPos = 0;
if( bIncludeFolders ) if( bIncludeFolders )
{ {
bool bRoot = isRootDir( aDirURL ); bool bRoot = isRootDir( aDirURL );
...@@ -2837,36 +2834,36 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2837,36 +2834,36 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
// returned "." and for -1 ".." // returned "." and for -1 ".."
if( !bRoot ) if( !bRoot )
{ {
pRTLData->nCurDirPos = -2; rRTLData.nCurDirPos = -2;
} }
} }
} }
if( pRTLData->pDir ) if (rRTLData.pDir)
{ {
bool bFolderFlag = bool(pRTLData->nDirFlags & SbAttributes::DIRECTORY); bool bFolderFlag = bool(rRTLData.nDirFlags & SbAttributes::DIRECTORY);
for( ;; ) for( ;; )
{ {
if( pRTLData->nCurDirPos < 0 ) if (rRTLData.nCurDirPos < 0)
{ {
if( pRTLData->nCurDirPos == -2 ) if (rRTLData.nCurDirPos == -2)
{ {
aPath = "."; aPath = ".";
} }
else if( pRTLData->nCurDirPos == -1 ) else if (rRTLData.nCurDirPos == -1)
{ {
aPath = ".."; aPath = "..";
} }
pRTLData->nCurDirPos++; rRTLData.nCurDirPos++;
} }
else else
{ {
DirectoryItem aItem; DirectoryItem aItem;
FileBase::RC nRet = pRTLData->pDir->getNextItem( aItem ); FileBase::RC nRet = rRTLData.pDir->getNextItem(aItem);
if( nRet != FileBase::E_None ) if( nRet != FileBase::E_None )
{ {
pRTLData->pDir.reset(); rRTLData.pDir.reset();
aPath.clear(); aPath.clear();
break; break;
} }
...@@ -2894,7 +2891,7 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool) ...@@ -2894,7 +2891,7 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
aPath = aFileStatus.getFileName(); aPath = aFileStatus.getFileName();
} }
bool bMatch = implCheckWildcard( aPath, pRTLData ); bool bMatch = implCheckWildcard(aPath, rRTLData);
if( !bMatch ) if( !bMatch )
{ {
continue; continue;
......
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