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

New commits:
commit 0ce654a5858eee15a319526b996a6368c145888f
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Jun 14 12:24:41 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Jun 15 09:47:45 2022 +0200

    crashtesting: negative index seen on loading forum-de3-15472.ods
    
    Change-Id: I737e6132f117a85c4d7e5df4a33561d09eff86af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135823
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/source/core/data/colorscale.cxx 
b/sc/source/core/data/colorscale.cxx
index ee8bf407ba0e..96aeef2819c1 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -541,8 +541,10 @@ Color CalcColor( double nVal, double nVal1, const Color& 
rCol1, double nVal2, co
 double GetPercentile( const std::vector<double>& rArray, double fPercentile )
 {
     size_t nSize = rArray.size();
-    size_t nIndex = static_cast<size_t>(::rtl::math::approxFloor( fPercentile 
* (nSize-1)));
-    double fDiff = fPercentile * (nSize-1) - ::rtl::math::approxFloor( 
fPercentile * (nSize-1));
+    double fFloor = ::rtl::math::approxFloor(fPercentile * (nSize-1));
+    SAL_WARN_IF(fFloor < 0, "sc", "negative percentile");
+    size_t nIndex = fFloor >= 0 ? static_cast<size_t>(fFloor) : 0;
+    double fDiff = fPercentile * (nSize-1) - fFloor;
     std::vector<double>::const_iterator iter = rArray.begin() + nIndex;
     if (fDiff == 0.0)
         return *iter;

Reply via email to