Related: cool#16002 sw markdown import: fix MSVC C6011 warning

See
<https://gerrit.collaboraoffice.com/c/online/+/6580/2#message-b6fea69a9d25781be6080bace1334d8864d365cc>:
> 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 <vmiklos@collabora.com>
Change-Id: I696a962ca00017648acbe3b991659e075b8f2528
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/8558
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 91209a9bfa8a89c9825912ce4627c84272605ad9)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209248
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Miklos Vajna
2026-08-18 13:23:55 +02:00
committed by Xisco Fauli
parent 1182b28b15
commit 08252eb83f
+36 -31
View File
@@ -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();
}
}
}
}