[Libreoffice-commits] core.git: basic/source
Stephan Bergmann
sbergman at redhat.com
Fri Apr 6 12:56:44 UTC 2018
basic/source/runtime/methods.cxx | 62 ++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 36 deletions(-)
New commits:
commit cc20344010e94eda22fee662aab966d395a0796a
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Apr 6 13:48:11 2018 +0200
tdf#111313: Honor bWriteNoLenParam in !bCompatibility, too
e8deba22e887a972f60ff05551e93c334ac1e7b6 "INTEGRATION: CWS ab26" had added
the bCompatibility case with all the argument checking ("2006/05/04 08:33:46 ab
1.66.10.3: #111951# Changed Mid runtime behaviour only for
CompatibilityMode(true)"), and it was probably an oversight that, for
!bCompatibility, it left the bWriteNoLenParam case (triggered by Basic code like
s = "abc"
Mid(s,1) = "d"
) calling OUStringBuffer::remove with an illegal argument of len=-1.
Change that so that only setting ERRCODE_BASIC_BAD_ARGUMENT is controlled by
bCompatibility, while all the other checks (that are probably all necessary to
not call rtl string functions with illegal arguments) are done in both modes.
Also, the check
nStartPos + 1 > nArgLen
should probably be
nStartPos > nArgLen
instead, as nStartPos has already been decremented from the one-based Basic
index to the zero-baesd rtl string index.
Change-Id: I75deec0acf75b8677aa89f91897c06c1caa5614d
Reviewed-on: https://gerrit.libreoffice.org/52500
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index fed8450f8d5b..74c44259fd91 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -1137,54 +1137,44 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
}
if ( bWrite )
{
- OUStringBuffer aResultStr;
- SbiInstance* pInst = GetSbData()->pInst;
- bool bCompatibility = ( pInst && pInst->IsCompatibility() );
- if( bCompatibility )
+ sal_Int32 nArgLen = aArgStr.getLength();
+ if( nStartPos > nArgLen )
{
- sal_Int32 nArgLen = aArgStr.getLength();
- if( nStartPos + 1 > nArgLen )
+ SbiInstance* pInst = GetSbData()->pInst;
+ bool bCompatibility = ( pInst && pInst->IsCompatibility() );
+ if( bCompatibility )
{
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
return;
}
+ nStartPos = nArgLen;
+ }
- OUString aReplaceStr = rPar.Get(4)->GetOUString();
- sal_Int32 nReplaceStrLen = aReplaceStr.getLength();
- sal_Int32 nReplaceLen;
- if( bWriteNoLenParam )
+ OUString aReplaceStr = rPar.Get(4)->GetOUString();
+ sal_Int32 nReplaceStrLen = aReplaceStr.getLength();
+ sal_Int32 nReplaceLen;
+ if( bWriteNoLenParam )
+ {
+ nReplaceLen = nReplaceStrLen;
+ }
+ else
+ {
+ nReplaceLen = nLen;
+ if( nReplaceLen < 0 || nReplaceLen > nReplaceStrLen )
{
nReplaceLen = nReplaceStrLen;
}
- else
- {
- nReplaceLen = nLen;
- if( nReplaceLen < 0 || nReplaceLen > nReplaceStrLen )
- {
- nReplaceLen = nReplaceStrLen;
- }
- }
-
- sal_Int32 nReplaceEndPos = nStartPos + nReplaceLen;
- if( nReplaceEndPos > nArgLen )
- {
- nReplaceLen -= (nReplaceEndPos - nArgLen);
- }
- aResultStr = aArgStr;
- sal_Int32 nErase = nReplaceLen;
- aResultStr.remove( nStartPos, nErase );
- aResultStr.insert( nStartPos, aReplaceStr.getStr(), nReplaceLen);
}
- else
+
+ sal_Int32 nReplaceEndPos = nStartPos + nReplaceLen;
+ if( nReplaceEndPos > nArgLen )
{
- aResultStr = aArgStr;
- sal_Int32 nTmpStartPos = nStartPos;
- if ( nTmpStartPos > aArgStr.getLength() )
- nTmpStartPos = aArgStr.getLength();
- else
- aResultStr.remove( nTmpStartPos, nLen );
- aResultStr.insert( nTmpStartPos, rPar.Get(4)->GetOUString().getStr(), std::min(nLen, rPar.Get(4)->GetOUString().getLength()));
+ nReplaceLen -= (nReplaceEndPos - nArgLen);
}
+ OUStringBuffer aResultStr = aArgStr;
+ sal_Int32 nErase = nReplaceLen;
+ aResultStr.remove( nStartPos, nErase );
+ aResultStr.insert( nStartPos, aReplaceStr.getStr(), nReplaceLen);
rPar.Get(1)->PutString( aResultStr.makeStringAndClear() );
}
More information about the Libreoffice-commits
mailing list