Skip to content

Commit acfca49

Browse files
committed
Fix issue WinMerge#2556: "Debug Assertion Failed!" Error When Refreshing After Deleting All Content in Left or Right Pane (2)
1 parent 42ef851 commit acfca49

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Src/MergeDocLineDiffs.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,18 @@ CMergeDoc::GetWordDiffArrayInRange(const int begin[3], const int end[3], bool ig
392392
}
393393
wd.beginline[i] = nLine;
394394
wd.begin[i] = it->begin[i] - nOffsets[file][nLine-nLineBegin];
395-
if (m_ptBuf[file]->GetLineLength(nLine) < wd.begin[i])
395+
const int nLineCount = m_ptBuf[file]->GetLineCount();
396+
const int nLineLength1 = nLine < nLineCount ? m_ptBuf[file]->GetLineLength(nLine) : 0;
397+
if (nLineLength1 < wd.begin[i])
396398
{
397-
if (wd.beginline[i] < m_ptBuf[file]->GetLineCount() - 1)
399+
if (wd.beginline[i] < nLineCount - 1)
398400
{
399401
wd.begin[i] = 0;
400402
wd.beginline[i]++;
401403
}
402404
else
403405
{
404-
wd.begin[i] = m_ptBuf[file]->GetLineLength(nLine);
406+
wd.begin[i] = nLineLength1;
405407
}
406408
}
407409

@@ -412,16 +414,17 @@ CMergeDoc::GetWordDiffArrayInRange(const int begin[3], const int end[3], bool ig
412414
}
413415
wd.endline[i] = nLine;
414416
wd.end[i] = it->end[i] + 1 - nOffsets[file][nLine-nLineBegin];
415-
if (m_ptBuf[file]->GetLineLength(nLine) < wd.end[i])
417+
const int nLineLength2 = nLine < nLineCount ? m_ptBuf[file]->GetLineLength(nLine) : 0;
418+
if (nLineLength2 < wd.end[i])
416419
{
417-
if (wd.endline[i] < m_ptBuf[file]->GetLineCount() - 1)
420+
if (wd.endline[i] < nLineCount - 1)
418421
{
419422
wd.end[i] = 0;
420423
wd.endline[i]++;
421424
}
422425
else
423426
{
424-
wd.end[i] = m_ptBuf[file]->GetLineLength(nLine);
427+
wd.end[i] = nLineLength2;
425428
}
426429
}
427430
}

0 commit comments

Comments
 (0)