summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-06-14 12:24:41 +0100
committerAndras Timar <andras.timar@collabora.com>2022-06-24 13:42:26 +0200
commit8a7f9a07395e229a54e11ac8cb4f617a90de2669 (patch)
tree86f33bc19b35613eba4e337319ccb711337f2cc7 /sc/source
parentcfeaab203d7cdfef7aa4ee6a15a32746e4478d41 (diff)
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>
Diffstat (limited to 'sc/source')
-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 5dbb833999cf..52c7c6b55788 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -542,8 +542,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;