From acfca49ee1cf814e3bf369cffe0897b81ef79394 Mon Sep 17 00:00:00 2001 From: sdottaka Date: Tue, 26 Nov 2024 22:12:53 +0900 Subject: [PATCH] Fix issue #2556: "Debug Assertion Failed!" Error When Refreshing After Deleting All Content in Left or Right Pane (2) --- Src/MergeDocLineDiffs.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Src/MergeDocLineDiffs.cpp b/Src/MergeDocLineDiffs.cpp index 64556331664..165fb96983d 100644 --- a/Src/MergeDocLineDiffs.cpp +++ b/Src/MergeDocLineDiffs.cpp @@ -392,16 +392,18 @@ CMergeDoc::GetWordDiffArrayInRange(const int begin[3], const int end[3], bool ig } wd.beginline[i] = nLine; wd.begin[i] = it->begin[i] - nOffsets[file][nLine-nLineBegin]; - if (m_ptBuf[file]->GetLineLength(nLine) < wd.begin[i]) + const int nLineCount = m_ptBuf[file]->GetLineCount(); + const int nLineLength1 = nLine < nLineCount ? m_ptBuf[file]->GetLineLength(nLine) : 0; + if (nLineLength1 < wd.begin[i]) { - if (wd.beginline[i] < m_ptBuf[file]->GetLineCount() - 1) + if (wd.beginline[i] < nLineCount - 1) { wd.begin[i] = 0; wd.beginline[i]++; } else { - wd.begin[i] = m_ptBuf[file]->GetLineLength(nLine); + wd.begin[i] = nLineLength1; } } @@ -412,16 +414,17 @@ CMergeDoc::GetWordDiffArrayInRange(const int begin[3], const int end[3], bool ig } wd.endline[i] = nLine; wd.end[i] = it->end[i] + 1 - nOffsets[file][nLine-nLineBegin]; - if (m_ptBuf[file]->GetLineLength(nLine) < wd.end[i]) + const int nLineLength2 = nLine < nLineCount ? m_ptBuf[file]->GetLineLength(nLine) : 0; + if (nLineLength2 < wd.end[i]) { - if (wd.endline[i] < m_ptBuf[file]->GetLineCount() - 1) + if (wd.endline[i] < nLineCount - 1) { wd.end[i] = 0; wd.endline[i]++; } else { - wd.end[i] = m_ptBuf[file]->GetLineLength(nLine); + wd.end[i] = nLineLength2; } } }