sc/source/core/data/colorscale.cxx |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

New commits:
commit 9a406a8ce660fb01010d3f13d263c1c8d8389dd9
Author:     Markus Mohrhard <markus.mohrh...@googlemail.com>
AuthorDate: Thu Aug 14 22:59:34 2025 +0800
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Aug 14 21:37:07 2025 +0200

    prevent crash during colorscale calculation
    
    This should fix 
https://crashreport.libreoffice.org/stats/signature/static%20double%20%60anonymous%20namespace'::GetPercentile(const%20class%20std::vector%3Cdouble,std::allocator%3Cdouble%3E%20%3E%20&%20const,%20double)
    
    Change-Id: Ifb4cc3a8120e9f85eb2029e88268e11f4ae2526a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189613
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com>
    (cherry picked from commit 9d03d31dabc31902be18aa6b4905b155d06e3afa)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189620
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/core/data/colorscale.cxx 
b/sc/source/core/data/colorscale.cxx
index 9d7df4506c4f..0947971a73ee 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -612,13 +612,15 @@ double GetPercentile( const std::vector<double>& rArray, 
double fPercentile )
     SAL_WARN_IF(fPercentile < 0, "sc", "negative percentile");
     if (fPercentile < 0)
         return rArray.front();
-    assert(fPercentile <= 1);
+
+    fPercentile = std::min(1.0, fPercentile);
+
     size_t nSize = rArray.size();
     double fFloor = ::rtl::math::approxFloor(fPercentile * (nSize-1));
     size_t nIndex = static_cast<size_t>(fFloor);
     double fDiff = fPercentile * (nSize-1) - fFloor;
     std::vector<double>::const_iterator iter = rArray.begin() + nIndex;
-    if (fDiff == 0.0)
+    if (fDiff == 0.0 || nIndex == nSize - 1)
         return *iter;
     else
     {

Reply via email to