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

Side by Side Diff: core/fxcrt/fx_basic_list.cpp

Issue 1991123002: Fix a potential nullptr deref in CFX_MapPtrToPtr. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments 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 | « no previous file | core/fxcrt/fx_basic_maps.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 "core/fxcrt/include/fx_basic.h" 7 #include "core/fxcrt/include/fx_basic.h"
8 #include "core/fxcrt/plex.h" 8 #include "core/fxcrt/plex.h"
9 9
10 CFX_PtrList::CFX_PtrList(int nBlockSize) 10 CFX_PtrList::CFX_PtrList(int nBlockSize)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 FreeNode(pOldNode); 66 FreeNode(pOldNode);
67 } 67 }
68 void CFX_PtrList::FreeNode(CFX_PtrList::CNode* pNode) { 68 void CFX_PtrList::FreeNode(CFX_PtrList::CNode* pNode) {
69 pNode->pNext = m_pNodeFree; 69 pNode->pNext = m_pNodeFree;
70 m_pNodeFree = pNode; 70 m_pNodeFree = pNode;
71 m_nCount--; 71 m_nCount--;
72 if (m_nCount == 0) { 72 if (m_nCount == 0) {
73 RemoveAll(); 73 RemoveAll();
74 } 74 }
75 } 75 }
76
76 void CFX_PtrList::RemoveAll() { 77 void CFX_PtrList::RemoveAll() {
77 m_nCount = 0; 78 m_nCount = 0;
78 m_pNodeHead = m_pNodeTail = m_pNodeFree = NULL; 79 m_pNodeHead = nullptr;
79 m_pBlocks->FreeDataChain(); 80 m_pNodeTail = nullptr;
80 m_pBlocks = NULL; 81 m_pNodeFree = nullptr;
82 if (m_pBlocks) {
83 m_pBlocks->FreeDataChain();
84 m_pBlocks = nullptr;
85 }
81 } 86 }
87
82 CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev, 88 CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev,
83 CFX_PtrList::CNode* pNext) { 89 CFX_PtrList::CNode* pNext) {
84 if (!m_pNodeFree) { 90 if (!m_pNodeFree) {
85 CFX_Plex* pNewBlock = 91 CFX_Plex* pNewBlock =
86 CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode)); 92 CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode));
87 CNode* pNode = (CNode*)pNewBlock->data(); 93 CNode* pNode = (CNode*)pNewBlock->data();
88 pNode += m_nBlockSize - 1; 94 pNode += m_nBlockSize - 1;
89 for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) { 95 for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) {
90 pNode->pNext = m_pNodeFree; 96 pNode->pNext = m_pNodeFree;
91 m_pNodeFree = pNode; 97 m_pNodeFree = pNode;
(...skipping 24 matching lines...) Expand all
116 } 122 }
117 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const { 123 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const {
118 CNode* pNode = (CNode*)startAfter; 124 CNode* pNode = (CNode*)startAfter;
119 pNode = pNode ? pNode->pNext : m_pNodeHead; 125 pNode = pNode ? pNode->pNext : m_pNodeHead;
120 for (; pNode; pNode = pNode->pNext) { 126 for (; pNode; pNode = pNode->pNext) {
121 if (pNode->data == searchValue) 127 if (pNode->data == searchValue)
122 return (FX_POSITION)pNode; 128 return (FX_POSITION)pNode;
123 } 129 }
124 return NULL; 130 return NULL;
125 } 131 }
OLDNEW
« no previous file with comments | « no previous file | core/fxcrt/fx_basic_maps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698