From 08252eb83ff97aefb7894def14cdc81184188efc Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 3 Aug 2026 16:46:28 +0200 Subject: [PATCH] Related: cool#16002 sw markdown import: fix MSVC C6011 warning See : > sw\source\filter\basflt\shellio.cxx(720) : warning C6011: Dereferencing NULL pointer 'pDelNd'. : Lines: 687, 688, 689, 694, 695, 697, 699, 702, 705, 709, 716, 720 Once pDelNd is fetched, we can't dereference is unconditionally. The code was inconsistent, with a check for a nullptr at one location, and two others didn't check. Fix the problem by moving the accessing locations inside a checked block. Signed-off-by: Miklos Vajna Change-Id: I696a962ca00017648acbe3b991659e075b8f2528 Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/8558 Reviewed-by: Noel Grandin Tested-by: Jenkins CPCI (cherry picked from commit 91209a9bfa8a89c9825912ce4627c84272605ad9) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209248 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sw/source/filter/basflt/shellio.cxx | 67 ++++++++++++++++------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/sw/source/filter/basflt/shellio.cxx b/sw/source/filter/basflt/shellio.cxx index 2f67f12e9647..ffa41df1cd1c 100644 --- a/sw/source/filter/basflt/shellio.cxx +++ b/sw/source/filter/basflt/shellio.cxx @@ -696,36 +696,39 @@ void Reader::EndPaste(SwPasteInfo& rPasteInfo) if (pTextNode && pTextNode->CanJoinNext(&aNxtIdx) && rPasteInfo.m_pSttNdIdx->GetIndex() + 1 == aNxtIdx.GetIndex()) { - SwTextNode* pDelNd = aNxtIdx.GetNode().GetTextNode(); - // Don't join when the cursor was at the end of a list item and - // the first pasted paragraph is itself a list item. - bool bBothLists = rPasteInfo.m_bStartAtEndOfPara && pDelNd - && pTextNode->GetNoCondAttr(RES_PARATR_NUMRULE, /*bInParents=*/false) - && pDelNd->GetNoCondAttr(RES_PARATR_NUMRULE, /*bInParents=*/false); - if (!bBothLists) + if (SwTextNode* pDelNd = aNxtIdx.GetNode().GetTextNode()) { - // If the PaM points to the first new node, move the PaM to the - // end of the previous node. - if (aPam.GetPoint()->GetNode() == aNxtIdx.GetNode()) + // Don't join when the cursor was at the end of a list item and + // the first pasted paragraph is itself a list item. + bool bBothLists + = rPasteInfo.m_bStartAtEndOfPara + && pTextNode->GetNoCondAttr(RES_PARATR_NUMRULE, /*bInParents=*/false) + && pDelNd->GetNoCondAttr(RES_PARATR_NUMRULE, /*bInParents=*/false); + if (!bBothLists) { - aPam.GetPoint()->Assign(*pTextNode, pTextNode->GetText().getLength()); - } - // If the first new node isn't empty, convert the node's text - // attributes into hints. Otherwise, set the new node's - // paragraph style at the previous (empty) node. - if (pTextNode->GetText().getLength()) - pDelNd->FormatToTextAttr(pTextNode); - else - { - pTextNode->ChgFormatColl(pDelNd->GetTextColl()); - if (!pDelNd->GetNoCondAttr(RES_PARATR_LIST_ID, /*bInParents=*/false)) + // If the PaM points to the first new node, move the PaM to the + // end of the previous node. + if (aPam.GetPoint()->GetNode() == aNxtIdx.GetNode()) { - // Lists would need manual merging, but copy paragraph direct formatting - // otherwise. - pDelNd->CopyCollFormat(*pTextNode); + aPam.GetPoint()->Assign(*pTextNode, pTextNode->GetText().getLength()); } + // If the first new node isn't empty, convert the node's text + // attributes into hints. Otherwise, set the new node's + // paragraph style at the previous (empty) node. + if (pTextNode->GetText().getLength()) + pDelNd->FormatToTextAttr(pTextNode); + else + { + pTextNode->ChgFormatColl(pDelNd->GetTextColl()); + if (!pDelNd->GetNoCondAttr(RES_PARATR_LIST_ID, /*bInParents=*/false)) + { + // Lists would need manual merging, but copy paragraph direct + // formatting otherwise. + pDelNd->CopyCollFormat(*pTextNode); + } + } + pTextNode->JoinNext(); } - pTextNode->JoinNext(); } } } @@ -743,12 +746,14 @@ void Reader::EndPaste(SwPasteInfo& rPasteInfo) // If the last new node isn't empty, convert the node's text // attributes into hints. Otherwise, set the new node's // paragraph style at the next (empty) node. - SwTextNode* pDelNd = aPrevIdx.GetNode().GetTextNode(); - if (pTextNode->GetText().getLength()) - pDelNd->FormatToTextAttr(pTextNode); - else - pTextNode->ChgFormatColl(pDelNd->GetTextColl()); - pTextNode->JoinPrev(); + if (SwTextNode* pDelNd = aPrevIdx.GetNode().GetTextNode()) + { + if (pTextNode->GetText().getLength()) + pDelNd->FormatToTextAttr(pTextNode); + else + pTextNode->ChgFormatColl(pDelNd->GetTextColl()); + pTextNode->JoinPrev(); + } } } }