sd/source/console/PresenterToolBar.cxx |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

New commits:
commit 8c5a81201e89e406b58f2db325373347ccc8e647
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri May 16 09:05:05 2025 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Mon May 19 12:11:11 2025 +0200

    tdf#160094 sd presenter: Don't use invalid iterator for RTL
    
    Use reverse iterators instead of manually iterating
    backwards and using an invalid iterator of
    `std::vector::begin() - 1` that triggered
    
        
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/debug/safe_iterator.h:1103:
        In function:
            _Self gnu_debug::operator-(const _Self &, difference_type)
    
        Error: attempt to retreat a dereferenceable (start-of-sequence) 
iterator 1
        steps, which falls outside its valid range.
    
        Objects involved in the operation:
            iterator @ 0x7ffe4f131df8 {
              type = 
gnu_cxx::normal_iterator<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>,
 std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > 
>*, 
std::vector<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>,
 std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > 
>, 
std::allocator<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>,
 std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > 
> > > > (mutable iterator);
              state = dereferenceable (start-of-sequence);
              references sequence with type 
'std::debug::vector<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>,
 std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > 
>, 
std::allocator<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>,
 std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > 
> > >' @ 0x55ee4e1a92a8
            }
    
    when starting Impress with SAL_RTL_ENABLED=1 and
    then starting a slideshow with Presenter Console
    enabled. for an `--enable-dbgutil` Linux build.
    
    Replace the hard-coded `nIndex=2` with
    `nIndex = aPartSizes.size() - 1` (there are 3
    vector elements) and rename `iBegin` to `iFirst`
    (as it no longer is the begin iterator, but points
    to the first element in the vector, i.e. the element
    at index 0, not the first one when reverse-iterating).
    
    Change-Id: Ibfc3b776391dae8b986964ef8f8d3c256f12d553
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185381
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 140fb3b98b4f8e1331634213a0825fbe92ccda15)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185427
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sd/source/console/PresenterToolBar.cxx 
b/sd/source/console/PresenterToolBar.cxx
index 825bfbe31224..13cd5279a26e 100644
--- a/sd/source/console/PresenterToolBar.cxx
+++ b/sd/source/console/PresenterToolBar.cxx
@@ -763,9 +763,9 @@ void PresenterToolBar::Layout (
         }
     }
     else {
-        ElementContainer::iterator iPart;
-        ElementContainer::iterator iBegin (maElementContainer.begin());
-        for (iPart=maElementContainer.end()-1, nIndex=2; iPart!=iBegin-1; 
--iPart, --nIndex)
+        ElementContainer::reverse_iterator iPart;
+        nIndex = aPartSizes.size() - 1;
+        for (iPart = maElementContainer.rbegin(); iPart != 
maElementContainer.rend(); ++iPart, --nIndex)
         {
             geometry::RealRectangle2D aBoundingBox(
                 nX, nY,
@@ -877,10 +877,10 @@ void PresenterToolBar::LayoutPart (
         }
     }
     else {
-        ElementContainerPart::const_iterator iElement;
-        ElementContainerPart::const_iterator iBegin (rpPart->begin());
+        ElementContainerPart::const_reverse_iterator iElement;
+        ElementContainerPart::const_reverse_iterator iFirst = rpPart->rend() - 
1;
 
-        for (iElement=rpPart->end()-1; iElement!=iBegin-1; --iElement)
+        for (iElement= rpPart->rbegin(); iElement!= rpPart->rend(); ++iElement)
         {
             if (iElement->get() == nullptr)
                 continue;
@@ -901,11 +901,11 @@ void PresenterToolBar::LayoutPart (
             else
             {
                 // reverse presentation time with current time
-                if (iElement==iBegin){
-                    iElement=iBegin+2;
+                if (iElement == iFirst){
+                    iElement = iFirst - 2;
                 }
-                else if (iElement==iBegin+2){
-                    iElement=iBegin;
+                else if (iElement == iFirst - 2){
+                    iElement = iFirst;
                 }
                 const awt::Size aNewElementSize 
((*iElement)->GetBoundingSize(rxCanvas));
                 if ((*iElement)->IsFilling())
@@ -919,10 +919,10 @@ void PresenterToolBar::LayoutPart (
                 nY += aNewElementSize.Height + nGap;
 
                 // return the index as it was before the reversing
-                if (iElement==iBegin)
-                    iElement=iBegin+2;
-                else if (iElement==iBegin+2)
-                    iElement=iBegin;
+                if (iElement == iFirst)
+                    iElement = iFirst - 2;
+                else if (iElement == iFirst - 2)
+                    iElement = iFirst;
             }
         }
     }

Reply via email to