OSDN Git Service

Improve Various ASSERTs related to "Ghost Buffers"
authorGreyMerlin <GreyMerlin@gmail.com>
Thu, 2 Aug 2018 18:01:48 +0000 (11:01 -0700)
committerGreyMerlin <GreyMerlin@gmail.com>
Thu, 2 Aug 2018 18:01:48 +0000 (11:01 -0700)
Externals/crystaledit/editlib/LineInfo.cpp
Externals/crystaledit/editlib/ccrystaltextbuffer.cpp
Src/GhostTextBuffer.cpp

index 06ecd59..620c947 100644 (file)
@@ -73,6 +73,7 @@ void LineInfo::Create(LPCTSTR pszLine, size_t nLength)
       return;
     }
 
+  ASSERT (nLength <= INT_MAX);         // assert "positive int"
   m_nLength = nLength;
   m_nMax = ALIGN_BUF_SIZE (m_nLength + 1);
   ASSERT (m_nMax < INT_MAX);
@@ -90,6 +91,7 @@ void LineInfo::Create(LPCTSTR pszLine, size_t nLength)
     nEols = 2;
   else if (nLength && IsEol(pszLine[nLength - 1]))
     nEols = 1;
+  ASSERT (nEols <= m_nLength);
   m_nLength -= nEols;
   m_nEolChars = nEols;
 }
@@ -115,6 +117,7 @@ void LineInfo::CreateEmpty()
  */
 void LineInfo::Append(LPCTSTR pszChars, size_t nLength)
 {
+  ASSERT (nLength <= INT_MAX);         // assert "positive int"
   size_t nBufNeeded = m_nLength + nLength + 1;
   if (nBufNeeded > m_nMax)
     {
@@ -141,6 +144,7 @@ void LineInfo::Append(LPCTSTR pszChars, size_t nLength)
       {
        m_nEolChars = 1;
       }
+   ASSERT (m_nEolChars <= m_nLength);
    m_nLength -= m_nEolChars;
    ASSERT (m_nLength + m_nEolChars <= m_nMax);
 }
@@ -227,6 +231,7 @@ void LineInfo::Delete(size_t nStartChar, size_t nEndChar)
 void LineInfo::DeleteEnd(size_t nStartChar)
 {
   m_nLength = nStartChar;
+  ASSERT (m_nLength <= INT_MAX);               // assert "positive int"
   if (m_pcLine)
     m_pcLine[nStartChar] = 0;
   m_nEolChars = 0;
index 42495cd..83a49aa 100644 (file)
@@ -1012,7 +1012,7 @@ InternalDeleteText (CCrystalTextView * pSource, int nStartLine, int nStartChar,
   ASSERT (nStartLine >= 0 && nStartLine < (int)m_aLines.size ());
   ASSERT (nStartChar >= 0 && nStartChar <= (int)m_aLines[nStartLine].Length());
   ASSERT (nEndLine >= 0 && nEndLine < (int)m_aLines.size ());
-  ASSERT (nEndChar >= 0 && nEndChar <= (int)m_aLines[nEndLine].Length());
+  ASSERT (nEndChar >= 0 && nEndChar <= (int)m_aLines[nEndLine].FullLength());
   ASSERT (nStartLine < nEndLine || nStartLine == nEndLine && nStartChar <= nEndChar);
   // some edit functions (delete...) should do nothing when there is no selection.
   // assert to be sure to catch these 'do nothing' cases.
@@ -1847,7 +1847,7 @@ FlushUndoGroup (CCrystalTextView * pSource)
   ASSERT (m_bUndoGroup);
   if (pSource != NULL)
     {
-      ASSERT (static_cast<size_t>(m_nUndoPosition) == m_aUndoBuf.size());
+      ASSERT (static_cast<size_t>(m_nUndoPosition) <= m_aUndoBuf.size());
       if (m_nUndoPosition > 0)
         {
           pSource->OnEditOperation (m_aUndoBuf[m_nUndoPosition - 1].m_nAction, m_aUndoBuf[m_nUndoPosition - 1].GetText (), m_aUndoBuf[m_nUndoPosition - 1].GetTextLength ());
index ed68c26..93704e5 100644 (file)
@@ -95,7 +95,8 @@ bool CGhostTextBuffer::InternalDeleteGhostLine (CCrystalTextView * pSource,
 {
        ASSERT (m_bInit);             //  Text buffer not yet initialized.
        //  You must call InitNew() or LoadFromFile() first!
-       ASSERT (nLine >= 0 && nLine <= static_cast<intptr_t>(m_aLines.size ()));
+       ASSERT (nCount >= 0);
+       ASSERT (nLine >= 0 && (nLine + nCount) <= static_cast<intptr_t>(m_aLines.size ()));
 
        if (nCount == 0)
                return true;