summaryrefslogtreecommitdiffstats
path: root/basic/source/runtime/methods.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-02-20 12:40:49 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-02-20 15:59:49 +0100
commit5fc8b470f22bc7a8a5dc9a6bd86a591090abfcf3 (patch)
tree7aaa4c57c6b39068ed699f5032827589913901b4 /basic/source/runtime/methods.cxx
parenttdf#129529 sw_redlinehide: infinite loop in SwLayHelper::CheckInsert() (diff)
downloadcore-5fc8b470f22bc7a8a5dc9a6bd86a591090abfcf3.tar.gz
core-5fc8b470f22bc7a8a5dc9a6bd86a591090abfcf3.zip
tdf#130426 Support Basic Chr(&H8000), ..., Chr(&HFFFF) again
...after it had been broken by d5b7627a0e738c0866b819910153b96b611813f8 "tdf#62326 - Macros: Converting Hex strings of negative value". The corresponding help update is <https://gerrit.libreoffice.org/c/help/+/89100> "tdf#130426 Update documentation for Basic Chr and ChrW functions". Change-Id: I5f08b1ef907d840b491315a1f445f729b4999d0d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89090 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'basic/source/runtime/methods.cxx')
-rw-r--r--basic/source/runtime/methods.cxx11
1 files changed, 9 insertions, 2 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 8543c0817762..3214dd28602c 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -330,8 +330,15 @@ static void implChr( SbxArray& rPar, bool bChrW )
}
else
{
- sal_Unicode aCh = static_cast<sal_Unicode>(pArg->GetUShort());
- aStr = OUString(aCh);
+ // Map negative 16-bit values to large positive ones, so that code like Chr(&H8000)
+ // still works after the fix for tdf#62326 changed those four-digit hex notations to
+ // produce negative values:
+ sal_Int32 aCh = pArg->GetLong();
+ if (aCh < -0x8000 || aCh > 0xFFFF) {
+ StarBASIC::Error(ERRCODE_BASIC_MATH_OVERFLOW);
+ aCh = 0;
+ }
+ aStr = OUString(static_cast<sal_Unicode>(aCh));
}
rPar.Get32(0)->PutString( aStr );
}