sal/rtl/strtmpl.hxx |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit ea5dbb6e3dd2fdb84cf68d95174c183aae34488c
Author:     Vladislav Tarakanov <[email protected]>
AuthorDate: Thu Jul 20 14:45:51 2023 +0400
Commit:     Eike Rathke <[email protected]>
CommitDate: Fri Jul 21 13:19:08 2023 +0200

    tdf#139306 Incorrect nDecPlaces value after clamping
    
    nDecPlaces clamping diap changed from +-20 to +-309 and buffer is resized 
for new value
    
    Change-Id: Icb2130891598cf02623bbf5bd0273edab529d124
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153815
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <[email protected]>
    (cherry picked from commit 9655e14663419780a74deb87f393ce11e03d0843)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154693

diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index eece825ec082..bb49cfaf0aa4 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -1540,7 +1540,7 @@ void doubleToString(rtl_tString** pResult, sal_Int32* 
pResultCapacity, sal_Int32
     // rtl_math_DecimalPlaces_Max was passed with rtl_math_StringFormat_F or
     // others, but we don't want to allocate/deallocate 2GB just to fill it
     // with trailing '0' characters..
-    nDecPlaces = std::clamp<sal_Int32>(nDecPlaces, -20, 20);
+    nDecPlaces = std::clamp<sal_Int32>(nDecPlaces, -309, 309);
 
     sal_Int32 nDigits = nDecPlaces + 1;
 
@@ -1566,9 +1566,9 @@ void doubleToString(rtl_tString** pResult, sal_Int32* 
pResultCapacity, sal_Int32
     sal_Int32 nBuf
         = (nDigits <= 0 ? std::max<sal_Int32>(nDecPlaces, std::abs(nExp)) : 
nDigits + nDecPlaces)
           + 10 + (pGroups ? std::abs(nDigits) * 2 : 0);
-    // max(nDigits) = max(nDecPlaces) + 1 + max(nExp) + 1 = 20 + 1 + 308 + 1 = 
330
-    // max(nBuf) = max(nDigits) + max(nDecPlaces) + 10 + max(nDigits) * 2 = 
330 * 3 + 20 + 10 = 1020
-    assert(nBuf <= 1024);
+    // max(nDigits) = max(nDecPlaces) + 1 + max(nExp) + 1 = 309 + 1 + 308 + 1 
= 619
+    // max(nBuf) = max(nDigits) + max(nDecPlaces) + 10 + max(nDigits) * 2 = 
619 * 3 + 309 + 10 = 2176
+    assert(nBuf <= 2176);
     auto* const pBuf = static_cast<Char_T<rtl_tString>*>(alloca(nBuf * 
sizeof(Char_T<rtl_tString>)));
     auto* p = pBuf;
     if (bSign)

Reply via email to