diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2014-12-30 21:48:21 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-02-12 11:57:58 +0000 |
commit | 82a505aae7fdb532e250b6acce1d33431cedfa88 (patch) | |
tree | 9f20e628abf7cbcf85f39c725a629aaa90b3da7d | |
parent | 39c9223b933f8585ed5d1a4014596aa8d4c94db3 (diff) |
Resolves fdo#87834: strange behavior of mid()-function
See https://bugs.freedesktop.org/show_bug.cgi?id=87834
Thank you Michael Büssow for pointing these cases
Change-Id: I3a9b58360ddab529d1fb2f7eeba7f1c7ae69ba7c
Reviewed-on: https://gerrit.libreoffice.org/13707
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit b7d02d7a5a374da3e01e0abc4022fba35daa1840)
Reviewed-on: https://gerrit.libreoffice.org/14145
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | basic/source/runtime/methods.cxx | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index f27e77146407..51df75b74bd2 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -1205,7 +1205,7 @@ RTLFUNC(Mid) } OUString aArgStr = rPar.Get(1)->GetOUString(); sal_Int32 nStartPos = rPar.Get(2)->GetLong(); - if ( nStartPos == 0 ) + if ( nStartPos < 1 ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); } @@ -1279,12 +1279,18 @@ RTLFUNC(Mid) else { OUString aResultStr; - if(nLen < 0) + if (nStartPos > aArgStr.getLength()) + { + aResultStr = ""; + } + else if(nArgCount == 2) { aResultStr = aArgStr.copy( nStartPos); } else { + if (nLen < 0) + nLen = 0; if(nStartPos + nLen > aArgStr.getLength()) { nLen = aArgStr.getLength() - nStartPos; |