From 495bda110a6ea8e7a6fc313ec0232a9ca6e3cfdc Mon Sep 17 00:00:00 2001 From: thestig Date: Thu, 28 Apr 2016 17:29:19 -0700 Subject: Do not check pointers before deleting them. XFA edition. Review-Url: https://codereview.chromium.org/1925363002 --- xfa/fee/fde_txtedtengine.cpp | 38 +++++++++++------------------- xfa/fee/fde_txtedtpage.cpp | 56 ++++++++++++++++++-------------------------- 2 files changed, 37 insertions(+), 57 deletions(-) (limited to 'xfa/fee') diff --git a/xfa/fee/fde_txtedtengine.cpp b/xfa/fee/fde_txtedtengine.cpp index 98d7841b40..1dc03dcc85 100644 --- a/xfa/fee/fde_txtedtengine.cpp +++ b/xfa/fee/fde_txtedtengine.cpp @@ -627,22 +627,16 @@ int32_t CFDE_TxtEdtEngine::GetSelRange(int32_t nIndex, int32_t& nStart) { nStart = m_SelRangePtrArr[nIndex]->nStart; return m_SelRangePtrArr[nIndex]->nCount; } + void CFDE_TxtEdtEngine::ClearSelection() { int32_t nCount = m_SelRangePtrArr.GetSize(); - FDE_LPTXTEDTSELRANGE lpRange = NULL; - int32_t i = 0; - for (i = 0; i < nCount; i++) { - lpRange = m_SelRangePtrArr[i]; - if (lpRange != NULL) { - delete lpRange; - lpRange = NULL; - } - } + for (int i = 0; i < nCount; ++i) + delete m_SelRangePtrArr[i]; m_SelRangePtrArr.RemoveAll(); - if (nCount && m_Param.pEventSink) { + if (nCount && m_Param.pEventSink) m_Param.pEventSink->On_SelChanged(this); - } } + FX_BOOL CFDE_TxtEdtEngine::Redo(const CFX_ByteStringC& bsRedo) { if (IsLocked()) { return FALSE; @@ -906,8 +900,7 @@ void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) { ? ParagPosBgn.nParagIndex : (ParagPosBgn.nParagIndex + 1); for (i = nNextParagIndex; i <= ParagPosEnd.nParagIndex; i++) { - CFDE_TxtEdtParag* pParag = m_ParagPtrArray[nNextParagIndex]; - delete pParag; + delete m_ParagPtrArray[nNextParagIndex]; m_ParagPtrArray.RemoveAt(nNextParagIndex); } if (!(bLastParag && ParagPosBgn.nCharIndex == 0)) { @@ -980,17 +973,14 @@ void CFDE_TxtEdtEngine::RebuildParagraphs() { } while (pIter->Next()); pIter->Release(); } + void CFDE_TxtEdtEngine::RemoveAllParags() { int32_t nCount = m_ParagPtrArray.GetSize(); - int32_t i = 0; - for (i = 0; i < nCount; i++) { - CFDE_TxtEdtParag* pParag = m_ParagPtrArray[i]; - if (pParag) { - delete pParag; - } - } + for (int i = 0; i < nCount; ++i) + delete m_ParagPtrArray[i]; m_ParagPtrArray.RemoveAll(); } + void CFDE_TxtEdtEngine::RemoveAllPages() { int32_t nCount = m_PagePtrArray.GetSize(); int32_t i = 0; @@ -1610,8 +1600,7 @@ void CFDE_TxtEdtEngine::DeleteSelect() { int32_t nSelCount; while (nCountRange > 0) { nSelCount = GetSelRange(--nCountRange, nSelStart); - FDE_LPTXTEDTSELRANGE lpTemp = m_SelRangePtrArr[nCountRange]; - delete lpTemp; + delete m_SelRangePtrArr[nCountRange]; m_SelRangePtrArr.RemoveAt(nCountRange); DeleteRange_DoRecord(nSelStart, nSelCount, TRUE); } @@ -1622,6 +1611,7 @@ void CFDE_TxtEdtEngine::DeleteSelect() { return; } } + IFDE_TxtEdtDoRecord* IFDE_TxtEdtDoRecord::Create( const CFX_ByteStringC& bsDoRecord) { const FX_CHAR* lpBuf = bsDoRecord.c_str(); @@ -1632,10 +1622,10 @@ IFDE_TxtEdtDoRecord* IFDE_TxtEdtDoRecord::Create( case FDE_TXTEDT_DORECORD_DEL: return new CFDE_TxtEdtDoRecord_DeleteRange(bsDoRecord); default: - break; + return nullptr; } - return NULL; } + CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert( const CFX_ByteStringC& bsDoRecord) { Deserialize(bsDoRecord); diff --git a/xfa/fee/fde_txtedtpage.cpp b/xfa/fee/fde_txtedtpage.cpp index 5faafebd55..c50f66e2ff 100644 --- a/xfa/fee/fde_txtedtpage.cpp +++ b/xfa/fee/fde_txtedtpage.cpp @@ -139,21 +139,15 @@ CFDE_TxtEdtPage::CFDE_TxtEdtPage(IFDE_TxtEdtEngine* pEngine, int32_t nPageIndex) FXSYS_memset(&m_rtPageCanvas, 0, sizeof(CFX_RectF)); m_pEditEngine = (CFDE_TxtEdtEngine*)pEngine; } + CFDE_TxtEdtPage::~CFDE_TxtEdtPage() { m_PieceMassArr.RemoveAll(TRUE); - if (m_pTextSet) { - delete m_pTextSet; - m_pTextSet = NULL; - } - if (m_pCharWidth) { - delete[] m_pCharWidth; - m_pCharWidth = NULL; - } - if (m_pIter != NULL) { + delete m_pTextSet; + delete[] m_pCharWidth; + if (m_pIter) m_pIter->Release(); - m_pIter = NULL; - } } + void CFDE_TxtEdtPage::Release() { delete this; } @@ -555,32 +549,28 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, m_bLoaded = TRUE; return 0; } + void CFDE_TxtEdtPage::UnloadPage(const CFX_RectF* pClipBox) { ASSERT(m_nRefCount > 0); m_nRefCount--; - if (m_nRefCount == 0) { - m_PieceMassArr.RemoveAll(); - if (m_pTextSet) { - delete m_pTextSet; - m_pTextSet = NULL; - } - if (m_pCharWidth) { - delete[] m_pCharWidth; - m_pCharWidth = NULL; - } - if (m_pBgnParag) { - m_pBgnParag->UnloadParag(); - } - if (m_pEndParag) { - m_pEndParag->UnloadParag(); - } - if (m_pIter) { - m_pIter->Release(); - m_pIter = NULL; - } - m_pBgnParag = NULL; - m_pEndParag = NULL; + if (m_nRefCount != 0) + return; + + m_PieceMassArr.RemoveAll(); + delete m_pTextSet; + m_pTextSet = nullptr; + delete[] m_pCharWidth; + m_pCharWidth = nullptr; + if (m_pBgnParag) + m_pBgnParag->UnloadParag(); + if (m_pEndParag) + m_pEndParag->UnloadParag(); + if (m_pIter) { + m_pIter->Release(); + m_pIter = nullptr; } + m_pBgnParag = nullptr; + m_pEndParag = nullptr; } const CFX_RectF& CFDE_TxtEdtPage::GetContentsBox() { -- cgit v1.2.3