include/comphelper/parallelsort.hxx |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit b0aa70c9565f5ef4467db1711519edc9859e9fdb
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sat Sep 28 19:37:59 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Sep 29 09:05:16 2024 +0200

    cid#1607243 Overflowed constant
    
    Change-Id: Ia5d57d8612d8a2a8079c22e5dd739c249fa9262d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174151
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/comphelper/parallelsort.hxx 
b/include/comphelper/parallelsort.hxx
index fd7bb83b1686..300e7ea4675a 100644
--- a/include/comphelper/parallelsort.hxx
+++ b/include/comphelper/parallelsort.hxx
@@ -124,12 +124,12 @@ private:
 
 constexpr size_t nMaxTreeArraySize = 64;
 
-size_t lcl_round_down_pow2(size_t nNum)
+size_t lcl_tree_array_size(size_t nNum)
 {
     size_t nPow2;
     for (nPow2 = 1; nPow2 <= nNum; nPow2 <<= 1)
         ;
-    return std::min((nPow2 >> 1), nMaxTreeArraySize);
+    return std::clamp((nPow2 >> 1), size_t(1), nMaxTreeArraySize);
 }
 
 template <class RandItr> struct Sampler
@@ -171,7 +171,7 @@ public:
     size_t maBinEnds[nMaxTreeArraySize];
 
     Binner(const ValueType* pSamples, size_t nSamples, size_t nBins, bool 
bThreaded)
-        : mnTreeArraySize(lcl_round_down_pow2(nBins))
+        : mnTreeArraySize(lcl_tree_array_size(nBins))
         , mnDividers(mnTreeArraySize - 1)
         , mbThreaded(bThreaded)
     {
@@ -299,7 +299,7 @@ void s3sort(const RandItr aBegin, const RandItr aEnd, 
Compare aComp = Compare(),
     using ValueType = typename std::iterator_traits<RandItr>::value_type;
     auto pOut = std::make_unique<ValueType[]>(nLen);
 
-    const size_t nBins = lcl_round_down_pow2(nThreadCount);
+    const size_t nBins = lcl_tree_array_size(nThreadCount);
     assert(nBins >= 1);
     const size_t nOverSamplingFactor = std::max(1.0, 
std::sqrt(static_cast<double>(nLen) / 64));
     const size_t nSamples = nOverSamplingFactor * nBins;

Reply via email to