Kaydet (Commit) cc203440 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

tdf#111313: Honor bWriteNoLenParam in !bCompatibility, too

e8deba22 "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/52500Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst e66d7dbb
......@@ -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() );
}
......
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