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

New commits:
commit 2af4b268032a52905f75684c5b5a226b5dbc3027
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jun 15 09:59:46 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jun 16 11:04:42 2022 +0200

    Negative percentile should be treated as 0
    
    Change-Id: I460cd2ea6950cf9f8bc656a94c71973bd93c1fae
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135879
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit fdde571c6a5ec65a24c496af4c5928e22bd89ba2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135945
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/core/data/colorscale.cxx 
b/sc/source/core/data/colorscale.cxx
index 96aeef2819c1..75f94d3bc2ed 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -540,10 +540,14 @@ Color CalcColor( double nVal, double nVal1, const Color& 
rCol1, double nVal2, co
  */
 double GetPercentile( const std::vector<double>& rArray, double fPercentile )
 {
+    assert(!rArray.empty());
+    SAL_WARN_IF(fPercentile < 0, "sc", "negative percentile");
+    if (fPercentile < 0)
+        return rArray.front();
+    assert(fPercentile <= 1);
     size_t nSize = rArray.size();
     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;
+    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)

Reply via email to