From 0d0c8bf3b35d588f4a0fed9c7f938f7449fd034e Mon Sep 17 00:00:00 2001 From: GreyMerlin Date: Thu, 2 Aug 2018 15:10:34 -0700 Subject: [PATCH] Last Line of Files vs "Ghost Lines" (3) `LineInfo::Delete()` was not correctly handling the case of deleting all text in a line _including_ the CRLF at the end. This particular situation exists because of deleting text at the very end of a file. --- Externals/crystaledit/editlib/LineInfo.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Externals/crystaledit/editlib/LineInfo.cpp b/Externals/crystaledit/editlib/LineInfo.cpp index 620c9475a..b3ea2fe61 100644 --- a/Externals/crystaledit/editlib/LineInfo.cpp +++ b/Externals/crystaledit/editlib/LineInfo.cpp @@ -219,7 +219,19 @@ void LineInfo::Delete(size_t nStartChar, size_t nEndChar) memcpy (m_pcLine + nStartChar, m_pcLine + nEndChar, sizeof (TCHAR) * (FullLength() - nEndChar)); } - m_nLength -= (nEndChar - nStartChar); + size_t nDelete = (nEndChar - nStartChar); + if (nDelete <= m_nLength) + { + m_nLength -= nDelete; + } + else + { + ASSERT( (m_nLength + m_nEolChars) <= nDelete ); + nDelete -= m_nLength; + m_nLength = 0; + m_nEolChars -= static_cast(nDelete); + } + ASSERT (m_nLength <= INT_MAX); // assert "positive int" if (m_pcLine) m_pcLine[FullLength()] = '\0'; } -- 2.11.0