sc/source/core/data/attrib.cxx |    4 +++-
 svl/source/inc/poolio.hxx      |    4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

New commits:
commit 0d402556af53790adb06380b4b04ea421d14d09e
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Sun Feb 20 18:34:13 2022 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Sun Feb 20 20:46:58 2022 +0100

    fix usage of std::lower_bound() in SfxItemPool (tdf#81765)
    
    The function expects elements starting from smallest to the biggest,
    and finds the first one that is not smaller than the one searched for.
    That means that all items remaining will not be smaller, and thus
    end of search is when items compare larger. Comparing remaining
    items as smaller means searching until the end.
    
    Change-Id: If5cf5c18951abf987ddbbf201f49cfb195e36d32
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130220
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/data/attrib.cxx b/sc/source/core/data/attrib.cxx
index e7cf37d4b741..7173bcb61217 100644
--- a/sc/source/core/data/attrib.cxx
+++ b/sc/source/core/data/attrib.cxx
@@ -717,7 +717,7 @@ bool ScCondFormatItem::operator==( const SfxPoolItem& rCmp 
) const
     auto const & other = static_cast<const ScCondFormatItem&>(rCmp);
     if (maIndex.empty() && other.maIndex.empty())
         return true;
-    // memcmp is faster than operator< on std::vector
+    // memcmp is faster than operator== on std::vector
     return maIndex.size() == other.maIndex.size()
         && memcmp(&maIndex.front(), &other.maIndex.front(), maIndex.size() * 
sizeof(sal_uInt32)) == 0;
 }
@@ -732,6 +732,8 @@ bool ScCondFormatItem::operator<( const SfxPoolItem& rCmp ) 
const
     if (maIndex.empty() && other.maIndex.empty())
         return false;
     // memcmp is faster than operator< on std::vector
+    // Note that on little-endian this results in a confusing ordering (256 < 
1),
+    // which technically doesn't matter as the ordering may be arbitrary.
     return memcmp(&maIndex.front(), &other.maIndex.front(), maIndex.size() * 
sizeof(sal_uInt32)) < 0;
 }
 
diff --git a/svl/source/inc/poolio.hxx b/svl/source/inc/poolio.hxx
index b2819cc46bd5..1080672b09ff 100644
--- a/svl/source/inc/poolio.hxx
+++ b/svl/source/inc/poolio.hxx
@@ -86,7 +86,7 @@ public:
         {
             if (it == maSortablePoolItems.end())
                 return nullptr;
-            if (**it < *pNeedle)
+            if (*pNeedle < **it)
                 return nullptr;
             if (*pNeedle == **it)
                 return *it;
@@ -130,7 +130,7 @@ public:
                     assert(false && "did not find item?");
                     break;
                 }
-                if (**sortIt < *pNeedle)
+                if (*pNeedle < **sortIt)
                 {
                     assert(false && "did not find item?");
                     break;

Reply via email to