Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: xfa/fee/fde_txtedtengine.cpp

Issue 1925363002: Do not check pointers before deleting them. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/fde_render.cpp ('k') | xfa/fee/fde_txtedtpage.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fee/fde_txtedtengine.h" 7 #include "xfa/fee/fde_txtedtengine.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 m_Param.pEventSink->On_SelChanged(this); 620 m_Param.pEventSink->On_SelChanged(this);
621 } 621 }
622 622
623 int32_t CFDE_TxtEdtEngine::CountSelRanges() { 623 int32_t CFDE_TxtEdtEngine::CountSelRanges() {
624 return m_SelRangePtrArr.GetSize(); 624 return m_SelRangePtrArr.GetSize();
625 } 625 }
626 int32_t CFDE_TxtEdtEngine::GetSelRange(int32_t nIndex, int32_t& nStart) { 626 int32_t CFDE_TxtEdtEngine::GetSelRange(int32_t nIndex, int32_t& nStart) {
627 nStart = m_SelRangePtrArr[nIndex]->nStart; 627 nStart = m_SelRangePtrArr[nIndex]->nStart;
628 return m_SelRangePtrArr[nIndex]->nCount; 628 return m_SelRangePtrArr[nIndex]->nCount;
629 } 629 }
630
630 void CFDE_TxtEdtEngine::ClearSelection() { 631 void CFDE_TxtEdtEngine::ClearSelection() {
631 int32_t nCount = m_SelRangePtrArr.GetSize(); 632 int32_t nCount = m_SelRangePtrArr.GetSize();
632 FDE_LPTXTEDTSELRANGE lpRange = NULL; 633 for (int i = 0; i < nCount; ++i)
633 int32_t i = 0; 634 delete m_SelRangePtrArr[i];
634 for (i = 0; i < nCount; i++) {
635 lpRange = m_SelRangePtrArr[i];
636 if (lpRange != NULL) {
637 delete lpRange;
638 lpRange = NULL;
639 }
640 }
641 m_SelRangePtrArr.RemoveAll(); 635 m_SelRangePtrArr.RemoveAll();
642 if (nCount && m_Param.pEventSink) { 636 if (nCount && m_Param.pEventSink)
643 m_Param.pEventSink->On_SelChanged(this); 637 m_Param.pEventSink->On_SelChanged(this);
644 }
645 } 638 }
639
646 FX_BOOL CFDE_TxtEdtEngine::Redo(const CFX_ByteStringC& bsRedo) { 640 FX_BOOL CFDE_TxtEdtEngine::Redo(const CFX_ByteStringC& bsRedo) {
647 if (IsLocked()) { 641 if (IsLocked()) {
648 return FALSE; 642 return FALSE;
649 } 643 }
650 if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) { 644 if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) {
651 return FALSE; 645 return FALSE;
652 } 646 }
653 IFDE_TxtEdtDoRecord* pDoRecord = IFDE_TxtEdtDoRecord::Create(bsRedo); 647 IFDE_TxtEdtDoRecord* pDoRecord = IFDE_TxtEdtDoRecord::Create(bsRedo);
654 ASSERT(pDoRecord); 648 ASSERT(pDoRecord);
655 if (pDoRecord == NULL) { 649 if (pDoRecord == NULL) {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[i]; 893 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[i];
900 pParag->CalcLines(); 894 pParag->CalcLines();
901 nTotalLineCount += pParag->m_nLineCount; 895 nTotalLineCount += pParag->m_nLineCount;
902 nTotalCharCount += pParag->m_nCharCount; 896 nTotalCharCount += pParag->m_nCharCount;
903 } 897 }
904 m_pTxtBuf->Delete(nStart, nCount); 898 m_pTxtBuf->Delete(nStart, nCount);
905 int32_t nNextParagIndex = (ParagPosBgn.nCharIndex == 0 && bLastParag) 899 int32_t nNextParagIndex = (ParagPosBgn.nCharIndex == 0 && bLastParag)
906 ? ParagPosBgn.nParagIndex 900 ? ParagPosBgn.nParagIndex
907 : (ParagPosBgn.nParagIndex + 1); 901 : (ParagPosBgn.nParagIndex + 1);
908 for (i = nNextParagIndex; i <= ParagPosEnd.nParagIndex; i++) { 902 for (i = nNextParagIndex; i <= ParagPosEnd.nParagIndex; i++) {
909 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[nNextParagIndex]; 903 delete m_ParagPtrArray[nNextParagIndex];
910 delete pParag;
911 m_ParagPtrArray.RemoveAt(nNextParagIndex); 904 m_ParagPtrArray.RemoveAt(nNextParagIndex);
912 } 905 }
913 if (!(bLastParag && ParagPosBgn.nCharIndex == 0)) { 906 if (!(bLastParag && ParagPosBgn.nCharIndex == 0)) {
914 pParag = m_ParagPtrArray[ParagPosBgn.nParagIndex]; 907 pParag = m_ParagPtrArray[ParagPosBgn.nParagIndex];
915 pParag->m_nCharCount = nTotalCharCount - nCount; 908 pParag->m_nCharCount = nTotalCharCount - nCount;
916 pParag->CalcLines(); 909 pParag->CalcLines();
917 nTotalLineCount -= pParag->m_nLineCount; 910 nTotalLineCount -= pParag->m_nLineCount;
918 } 911 }
919 int32_t nParagCount = m_ParagPtrArray.GetSize(); 912 int32_t nParagCount = m_ParagPtrArray.GetSize();
920 for (i = nNextParagIndex; i < nParagCount; i++) { 913 for (i = nNextParagIndex; i < nParagCount; i++) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 CFDE_TxtEdtParag* pParag = new CFDE_TxtEdtParag(this); 966 CFDE_TxtEdtParag* pParag = new CFDE_TxtEdtParag(this);
974 pParag->m_nCharStart = nParagStart; 967 pParag->m_nCharStart = nParagStart;
975 pParag->m_nCharCount = nIndex - nParagStart + 1; 968 pParag->m_nCharCount = nIndex - nParagStart + 1;
976 pParag->m_nLineCount = -1; 969 pParag->m_nLineCount = -1;
977 m_ParagPtrArray.Add(pParag); 970 m_ParagPtrArray.Add(pParag);
978 nParagStart = nIndex + 1; 971 nParagStart = nIndex + 1;
979 } 972 }
980 } while (pIter->Next()); 973 } while (pIter->Next());
981 pIter->Release(); 974 pIter->Release();
982 } 975 }
976
983 void CFDE_TxtEdtEngine::RemoveAllParags() { 977 void CFDE_TxtEdtEngine::RemoveAllParags() {
984 int32_t nCount = m_ParagPtrArray.GetSize(); 978 int32_t nCount = m_ParagPtrArray.GetSize();
985 int32_t i = 0; 979 for (int i = 0; i < nCount; ++i)
986 for (i = 0; i < nCount; i++) { 980 delete m_ParagPtrArray[i];
987 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[i];
988 if (pParag) {
989 delete pParag;
990 }
991 }
992 m_ParagPtrArray.RemoveAll(); 981 m_ParagPtrArray.RemoveAll();
993 } 982 }
983
994 void CFDE_TxtEdtEngine::RemoveAllPages() { 984 void CFDE_TxtEdtEngine::RemoveAllPages() {
995 int32_t nCount = m_PagePtrArray.GetSize(); 985 int32_t nCount = m_PagePtrArray.GetSize();
996 int32_t i = 0; 986 int32_t i = 0;
997 for (i = 0; i < nCount; i++) { 987 for (i = 0; i < nCount; i++) {
998 IFDE_TxtEdtPage* pPage = m_PagePtrArray[i]; 988 IFDE_TxtEdtPage* pPage = m_PagePtrArray[i];
999 if (pPage) { 989 if (pPage) {
1000 pPage->Release(); 990 pPage->Release();
1001 } 991 }
1002 } 992 }
1003 m_PagePtrArray.RemoveAll(); 993 m_PagePtrArray.RemoveAll();
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 FX_BOOL CFDE_TxtEdtEngine::IsSelect() { 1593 FX_BOOL CFDE_TxtEdtEngine::IsSelect() {
1604 return m_SelRangePtrArr.GetSize() > 0; 1594 return m_SelRangePtrArr.GetSize() > 0;
1605 } 1595 }
1606 void CFDE_TxtEdtEngine::DeleteSelect() { 1596 void CFDE_TxtEdtEngine::DeleteSelect() {
1607 int32_t nCountRange = CountSelRanges(); 1597 int32_t nCountRange = CountSelRanges();
1608 if (nCountRange > 0) { 1598 if (nCountRange > 0) {
1609 int32_t nSelStart; 1599 int32_t nSelStart;
1610 int32_t nSelCount; 1600 int32_t nSelCount;
1611 while (nCountRange > 0) { 1601 while (nCountRange > 0) {
1612 nSelCount = GetSelRange(--nCountRange, nSelStart); 1602 nSelCount = GetSelRange(--nCountRange, nSelStart);
1613 FDE_LPTXTEDTSELRANGE lpTemp = m_SelRangePtrArr[nCountRange]; 1603 delete m_SelRangePtrArr[nCountRange];
1614 delete lpTemp;
1615 m_SelRangePtrArr.RemoveAt(nCountRange); 1604 m_SelRangePtrArr.RemoveAt(nCountRange);
1616 DeleteRange_DoRecord(nSelStart, nSelCount, TRUE); 1605 DeleteRange_DoRecord(nSelStart, nSelCount, TRUE);
1617 } 1606 }
1618 ClearSelection(); 1607 ClearSelection();
1619 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); 1608 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo);
1620 m_Param.pEventSink->On_SelChanged(this); 1609 m_Param.pEventSink->On_SelChanged(this);
1621 SetCaretPos(nSelStart, TRUE); 1610 SetCaretPos(nSelStart, TRUE);
1622 return; 1611 return;
1623 } 1612 }
1624 } 1613 }
1614
1625 IFDE_TxtEdtDoRecord* IFDE_TxtEdtDoRecord::Create( 1615 IFDE_TxtEdtDoRecord* IFDE_TxtEdtDoRecord::Create(
1626 const CFX_ByteStringC& bsDoRecord) { 1616 const CFX_ByteStringC& bsDoRecord) {
1627 const FX_CHAR* lpBuf = bsDoRecord.c_str(); 1617 const FX_CHAR* lpBuf = bsDoRecord.c_str();
1628 int32_t nType = *((int32_t*)lpBuf); 1618 int32_t nType = *((int32_t*)lpBuf);
1629 switch (nType) { 1619 switch (nType) {
1630 case FDE_TXTEDT_DORECORD_INS: 1620 case FDE_TXTEDT_DORECORD_INS:
1631 return new CFDE_TxtEdtDoRecord_Insert(bsDoRecord); 1621 return new CFDE_TxtEdtDoRecord_Insert(bsDoRecord);
1632 case FDE_TXTEDT_DORECORD_DEL: 1622 case FDE_TXTEDT_DORECORD_DEL:
1633 return new CFDE_TxtEdtDoRecord_DeleteRange(bsDoRecord); 1623 return new CFDE_TxtEdtDoRecord_DeleteRange(bsDoRecord);
1634 default: 1624 default:
1635 break; 1625 return nullptr;
1636 } 1626 }
1637 return NULL;
1638 } 1627 }
1628
1639 CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert( 1629 CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert(
1640 const CFX_ByteStringC& bsDoRecord) { 1630 const CFX_ByteStringC& bsDoRecord) {
1641 Deserialize(bsDoRecord); 1631 Deserialize(bsDoRecord);
1642 } 1632 }
1643 CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert( 1633 CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert(
1644 CFDE_TxtEdtEngine* pEngine, 1634 CFDE_TxtEdtEngine* pEngine,
1645 int32_t nCaret, 1635 int32_t nCaret,
1646 const FX_WCHAR* lpText, 1636 const FX_WCHAR* lpText,
1647 int32_t nLength) 1637 int32_t nLength)
1648 : m_pEngine(pEngine), m_nCaret(nCaret) { 1638 : m_pEngine(pEngine), m_nCaret(nCaret) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 int32_t nEngine = 0; 1766 int32_t nEngine = 0;
1777 ArchiveLoader >> nEngine; 1767 ArchiveLoader >> nEngine;
1778 m_pEngine = (CFDE_TxtEdtEngine*)(uintptr_t)nEngine; 1768 m_pEngine = (CFDE_TxtEdtEngine*)(uintptr_t)nEngine;
1779 int32_t iSel = 0; 1769 int32_t iSel = 0;
1780 ArchiveLoader >> iSel; 1770 ArchiveLoader >> iSel;
1781 m_bSel = !!iSel; 1771 m_bSel = !!iSel;
1782 ArchiveLoader >> m_nIndex; 1772 ArchiveLoader >> m_nIndex;
1783 ArchiveLoader >> m_nCaret; 1773 ArchiveLoader >> m_nCaret;
1784 ArchiveLoader >> m_wsRange; 1774 ArchiveLoader >> m_wsRange;
1785 } 1775 }
OLDNEW
« no previous file with comments | « xfa/fde/fde_render.cpp ('k') | xfa/fee/fde_txtedtpage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698