sw/source/core/crsr/crstrvl.cxx |   71 +++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 32 deletions(-)

New commits:
commit 5528f9c8b8ea08ad0a347e9564e7ce98564bed30
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Dec 6 15:24:36 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat Dec 7 15:37:26 2024 +0100

    cid#1635776 Overflowed constant
    
    there is intended to be no logic change here, just rearrangement
    and acknowledgement that SwOutlineNodesInline::Seek_Entry always
    sets nEndPosInline to some value.
    
    Change-Id: I10d694e20c8619ae297a61f612590556c9a9effa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178037
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 910a62d05bbc..35ca30cf5bb8 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -1366,7 +1366,6 @@ SwOutlineNodes::size_type 
SwCursorShell::GetOutlinePos(sal_uInt8 nLevel, SwPaM*
 void SwCursorShell::MakeOutlineSel(SwOutlineNodes::size_type nSttPos, 
SwOutlineNodes::size_type nEndPos,
                                   bool bWithChildren , bool bKillPams, 
SwOutlineNodesInline* pOutlNdsInline)
 {
-    SwOutlineNodesInline::size_type nEndPosInline = SwOutlineNodesInline::npos;
     const SwNodes& rNds = GetDoc()->GetNodes();
     const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds();
     if( rOutlNds.empty() )
@@ -1384,47 +1383,55 @@ void 
SwCursorShell::MakeOutlineSel(SwOutlineNodes::size_type nSttPos, SwOutlineN
     SwNode* pSttNd = rOutlNds[ nSttPos ];
     SwNode* pEndNd = rOutlNds[ nEndPos ];
 
-    if( pOutlNdsInline )
+    if (pOutlNdsInline)
     {
         pSttNd = const_cast<SwNode*>(SwOutlineNodes::GetRootNode(pSttNd));
+
+        SwOutlineNodesInline::size_type nEndPosInline;
         pOutlNdsInline->Seek_Entry( pEndNd, &nEndPosInline );
-    }
+        assert(nEndPosInline != SwOutlineNodesInline::npos && "always sets 
some number <= pOutlNdsInline->size()");
 
-    if( bWithChildren && !pOutlNdsInline )
-    {
-        const int nLevel = pEndNd->GetTextNode()->GetAttrOutlineLevel()-1;
-        for( ++nEndPos; nEndPos < rOutlNds.size(); ++nEndPos )
+        // headings in flys
+        if (bWithChildren)
         {
-            pEndNd = rOutlNds[ nEndPos ];
-            const int nNxtLevel = 
pEndNd->GetTextNode()->GetAttrOutlineLevel()-1;
-            if( nNxtLevel <= nLevel )
-                break; // EndPos is now on the next one
+            const int nLevel = pEndNd->GetTextNode()->GetAttrOutlineLevel() - 
1;
+            for( ++nEndPosInline; nEndPosInline < pOutlNdsInline->size(); 
++nEndPosInline )
+            {
+                pEndNd = (*pOutlNdsInline)[ nEndPosInline ];
+                const int nNxtLevel = 
pEndNd->GetTextNode()->GetAttrOutlineLevel()-1;
+                if( nNxtLevel <= nLevel )
+                    break; // EndPos is now on the next one
+            }
+            // set anchor node of the fly node
+            if ( nEndPosInline < pOutlNdsInline->size() )
+                pEndNd = 
const_cast<SwNode*>(SwOutlineNodes::GetRootNode(pEndNd));
         }
+        else if (++nEndPosInline < pOutlNdsInline->size())
+            pEndNd = 
const_cast<SwNode*>(SwOutlineNodes::GetRootNode((*pOutlNdsInline)[nEndPosInline]));
+
+        if (nEndPosInline == pOutlNdsInline->size()) // no end found
+            pEndNd = &rNds.GetEndOfContent();
     }
-    // headings in flys
-    else if( bWithChildren && pOutlNdsInline )
+    else
     {
-        const int nLevel = pEndNd->GetTextNode()->GetAttrOutlineLevel() - 1;
-        for( ++nEndPosInline; nEndPosInline < pOutlNdsInline->size(); 
++nEndPosInline )
+        if (bWithChildren)
         {
-            pEndNd = (*pOutlNdsInline)[ nEndPosInline ];
-            const int nNxtLevel = 
pEndNd->GetTextNode()->GetAttrOutlineLevel()-1;
-            if( nNxtLevel <= nLevel )
-                break; // EndPos is now on the next one
+            const int nLevel = pEndNd->GetTextNode()->GetAttrOutlineLevel()-1;
+            for( ++nEndPos; nEndPos < rOutlNds.size(); ++nEndPos )
+            {
+                pEndNd = rOutlNds[ nEndPos ];
+                const int nNxtLevel = 
pEndNd->GetTextNode()->GetAttrOutlineLevel()-1;
+                if( nNxtLevel <= nLevel )
+                    break; // EndPos is now on the next one
+            }
         }
-        // set anchor node of the fly node
-        if ( nEndPosInline < pOutlNdsInline->size() )
-            pEndNd = const_cast<SwNode*>(SwOutlineNodes::GetRootNode(pEndNd));
-    }
-    // if without children then set onto next one
-    else if( !pOutlNdsInline && ++nEndPos < rOutlNds.size() )
-        pEndNd = rOutlNds[ nEndPos ];
-    else if( pOutlNdsInline && ++nEndPosInline < pOutlNdsInline->size() )
-        pEndNd = 
const_cast<SwNode*>(SwOutlineNodes::GetRootNode((*pOutlNdsInline)[nEndPosInline]));
-
-    if( ( pOutlNdsInline && nEndPosInline == pOutlNdsInline->size() ) ||
-        ( !pOutlNdsInline && nEndPos == rOutlNds.size() ) ) // no end found
-        pEndNd = &rNds.GetEndOfContent();
+        // if without children then set onto next one
+        else if (++nEndPos < rOutlNds.size())
+            pEndNd = rOutlNds[ nEndPos ];
+
+        if (nEndPos == rOutlNds.size()) // no end found
+            pEndNd = &rNds.GetEndOfContent();
+    }
 
     if( bKillPams )
         KillPams();

Reply via email to