summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-06-14 12:24:41 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2022-09-23 14:27:39 +0200
commit7e36b83030e81cc771c8e0c9fdf1b0c5b453de1c (patch)
treeb89600f8a0a22e876286462b0287717982009cbe
parentcrashtesting: assert seen on loading forum-en-38962.ods (diff)
downloadcore-7e36b83030e81cc771c8e0c9fdf1b0c5b453de1c.tar.gz
core-7e36b83030e81cc771c8e0c9fdf1b0c5b453de1c.zip
crashtesting: negative index seen on loading forum-de3-15472.ods
Change-Id: I737e6132f117a85c4d7e5df4a33561d09eff86af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135837 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> (cherry picked from commit d26e960fb3cb6dcff887654b3ec51e5cdea5a878)
-rw-r--r--sc/source/core/data/colorscale.cxx6
1 files changed, 4 insertions, 2 deletions
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 4ea3606e48b8..a257fae0a87d 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -484,8 +484,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;