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

Side by Side Diff: core/src/fxge/ge/fx_ge_path.cpp

Issue 1145843005: Revert "Remove FX_Alloc() null checks now that it can't return NULL." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 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 | « core/src/fxge/ge/fx_ge_fontmap.cpp ('k') | core/src/fxge/ge/fx_ge_ps.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 "../../../../third_party/base/numerics/safe_math.h"
8 #include "../../../include/fxcrt/fx_basic.h" 7 #include "../../../include/fxcrt/fx_basic.h"
9 #include "../../../include/fxge/fx_ge.h" 8 #include "../../../include/fxge/fx_ge.h"
10
11 CFX_ClipRgn::CFX_ClipRgn(int width, int height) 9 CFX_ClipRgn::CFX_ClipRgn(int width, int height)
12 { 10 {
13 m_Type = RectI; 11 m_Type = RectI;
14 m_Box.left = m_Box.top = 0; 12 m_Box.left = m_Box.top = 0;
15 m_Box.right = width; 13 m_Box.right = width;
16 m_Box.bottom = height; 14 m_Box.bottom = height;
17 } 15 }
18 CFX_ClipRgn::CFX_ClipRgn(const FX_RECT& rect) 16 CFX_ClipRgn::CFX_ClipRgn(const FX_RECT& rect)
19 { 17 {
20 m_Type = RectI; 18 m_Type = RectI;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 { 113 {
116 m_PointCount = m_AllocCount = 0; 114 m_PointCount = m_AllocCount = 0;
117 m_pPoints = NULL; 115 m_pPoints = NULL;
118 } 116 }
119 CFX_PathData::~CFX_PathData() 117 CFX_PathData::~CFX_PathData()
120 { 118 {
121 if (m_pPoints) { 119 if (m_pPoints) {
122 FX_Free(m_pPoints); 120 FX_Free(m_pPoints);
123 } 121 }
124 } 122 }
125 void CFX_PathData::SetPointCount(int nPoints) 123 FX_BOOL CFX_PathData::SetPointCount(int nPoints)
126 { 124 {
127 m_PointCount = nPoints; 125 m_PointCount = nPoints;
128 if (m_AllocCount < nPoints) { 126 if (m_AllocCount < nPoints) {
129 if (m_pPoints) { 127 if (m_pPoints) {
130 FX_Free(m_pPoints); 128 FX_Free(m_pPoints);
131 m_pPoints = NULL; 129 m_pPoints = NULL;
132 } 130 }
133 m_pPoints = FX_Alloc(FX_PATHPOINT, nPoints); 131 m_pPoints = FX_Alloc(FX_PATHPOINT, nPoints);
132 if (!m_pPoints) {
133 return FALSE;
134 }
134 m_AllocCount = nPoints; 135 m_AllocCount = nPoints;
135 } 136 }
137 return TRUE;
136 } 138 }
137 void CFX_PathData::AllocPointCount(int nPoints) 139 FX_BOOL CFX_PathData::AllocPointCount(int nPoints)
138 { 140 {
139 if (m_AllocCount < nPoints) { 141 if (m_AllocCount < nPoints) {
140 FX_PATHPOINT* pNewBuf = FX_Alloc(FX_PATHPOINT, nPoints); 142 FX_PATHPOINT* pNewBuf = FX_Alloc(FX_PATHPOINT, nPoints);
143 if (!pNewBuf) {
144 return FALSE;
145 }
141 if (m_PointCount) { 146 if (m_PointCount) {
142 FXSYS_memcpy32(pNewBuf, m_pPoints, m_PointCount * sizeof(FX_PATHPOIN T)); 147 FXSYS_memcpy32(pNewBuf, m_pPoints, m_PointCount * sizeof(FX_PATHPOIN T));
143 } 148 }
144 if (m_pPoints) { 149 if (m_pPoints) {
145 FX_Free(m_pPoints); 150 FX_Free(m_pPoints);
146 } 151 }
147 m_pPoints = pNewBuf; 152 m_pPoints = pNewBuf;
148 m_AllocCount = nPoints; 153 m_AllocCount = nPoints;
149 } 154 }
155 return TRUE;
150 } 156 }
151 CFX_PathData::CFX_PathData(const CFX_PathData& src) 157 CFX_PathData::CFX_PathData(const CFX_PathData& src)
152 { 158 {
159 m_pPoints = NULL;
153 m_PointCount = m_AllocCount = src.m_PointCount; 160 m_PointCount = m_AllocCount = src.m_PointCount;
154 m_pPoints = FX_Alloc(FX_PATHPOINT, src.m_PointCount); 161 m_pPoints = FX_Alloc(FX_PATHPOINT, src.m_PointCount);
162 if (!m_pPoints) {
163 return;
164 }
155 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount ); 165 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount );
156 } 166 }
157 void CFX_PathData::TrimPoints(int nPoints) 167 void CFX_PathData::TrimPoints(int nPoints)
158 { 168 {
159 if (m_PointCount <= nPoints) { 169 if (m_PointCount <= nPoints) {
160 return; 170 return;
161 } 171 }
162 SetPointCount(nPoints); 172 SetPointCount(nPoints);
163 } 173 }
164 void CFX_PathData::AddPointCount(int addPoints) 174 FX_BOOL CFX_PathData::AddPointCount(int addPoints)
165 { 175 {
166 pdfium::base::CheckedNumeric<int> new_count = m_PointCount; 176 int new_count = m_PointCount + addPoints;
167 new_count += addPoints; 177 if (!AllocPointCount(new_count)) {
168 m_PointCount = new_count.ValueOrDie(); 178 return FALSE;
169 AllocPointCount(m_PointCount); 179 }
180 m_PointCount = new_count;
181 return TRUE;
170 } 182 }
171 void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMat rix) 183 FX_BOOL CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* p Matrix)
172 { 184 {
173 int old_count = m_PointCount; 185 int old_count = m_PointCount;
174 AddPointCount(pSrc->m_PointCount); 186 if (!AddPointCount(pSrc->m_PointCount)) {
187 return FALSE;
188 }
175 FXSYS_memcpy32(m_pPoints + old_count, pSrc->m_pPoints, pSrc->m_PointCount * sizeof(FX_PATHPOINT)); 189 FXSYS_memcpy32(m_pPoints + old_count, pSrc->m_pPoints, pSrc->m_PointCount * sizeof(FX_PATHPOINT));
176 if (pMatrix) { 190 if (pMatrix == NULL) {
177 for (int i = 0; i < pSrc->m_PointCount; i ++) { 191 return TRUE;
178 pMatrix->Transform(m_pPoints[old_count + i].m_PointX, m_pPoints[old_ count + i].m_PointY);
179 }
180 } 192 }
193 for (int i = 0; i < pSrc->m_PointCount; i ++) {
194 pMatrix->Transform(m_pPoints[old_count + i].m_PointX, m_pPoints[old_coun t + i].m_PointY);
195 }
196 return TRUE;
181 } 197 }
182 void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag) 198 void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag)
183 { 199 {
184 ASSERT(index < m_PointCount); 200 ASSERT(index < m_PointCount);
185 m_pPoints[index].m_PointX = x; 201 m_pPoints[index].m_PointX = x;
186 m_pPoints[index].m_PointY = y; 202 m_pPoints[index].m_PointY = y;
187 m_pPoints[index].m_Flag = flag; 203 m_pPoints[index].m_Flag = flag;
188 } 204 }
189 void CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX _FLOAT top) 205 FX_BOOL CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top)
190 { 206 {
191 int old_count = m_PointCount; 207 int old_count = m_PointCount;
192 AddPointCount(5); 208 if (!AddPointCount(5)) {
209 return FALSE;
210 }
193 FX_PATHPOINT* pPoints = m_pPoints + old_count; 211 FX_PATHPOINT* pPoints = m_pPoints + old_count;
194 pPoints[0].m_PointX = pPoints[1].m_PointX = pPoints[4].m_PointX = left; 212 pPoints[0].m_PointX = pPoints[1].m_PointX = pPoints[4].m_PointX = left;
195 pPoints[2].m_PointX = pPoints[3].m_PointX = right; 213 pPoints[2].m_PointX = pPoints[3].m_PointX = right;
196 pPoints[0].m_PointY = pPoints[3].m_PointY = pPoints[4].m_PointY = bottom; 214 pPoints[0].m_PointY = pPoints[3].m_PointY = pPoints[4].m_PointY = bottom;
197 pPoints[1].m_PointY = pPoints[2].m_PointY = top; 215 pPoints[1].m_PointY = pPoints[2].m_PointY = top;
198 pPoints[0].m_Flag = FXPT_MOVETO; 216 pPoints[0].m_Flag = FXPT_MOVETO;
199 pPoints[1].m_Flag = pPoints[2].m_Flag = pPoints[3].m_Flag = FXPT_LINETO; 217 pPoints[1].m_Flag = pPoints[2].m_Flag = pPoints[3].m_Flag = FXPT_LINETO;
200 pPoints[4].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE; 218 pPoints[4].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE;
219 return TRUE;
201 } 220 }
202 CFX_FloatRect CFX_PathData::GetBoundingBox() const 221 CFX_FloatRect CFX_PathData::GetBoundingBox() const
203 { 222 {
204 CFX_FloatRect rect; 223 CFX_FloatRect rect;
205 if (m_PointCount) { 224 if (m_PointCount) {
206 rect.InitRect(m_pPoints[0].m_PointX, m_pPoints[0].m_PointY); 225 rect.InitRect(m_pPoints[0].m_PointX, m_pPoints[0].m_PointY);
207 for (int i = 1; i < m_PointCount; i ++) { 226 for (int i = 1; i < m_PointCount; i ++) {
208 rect.UpdateRect(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY); 227 rect.UpdateRect(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY);
209 } 228 }
210 } 229 }
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 583 }
565 if (pRect) { 584 if (pRect) {
566 pRect->left = x[0]; 585 pRect->left = x[0];
567 pRect->right = x[2]; 586 pRect->right = x[2];
568 pRect->bottom = y[0]; 587 pRect->bottom = y[0];
569 pRect->top = y[2]; 588 pRect->top = y[2];
570 pRect->Normalize(); 589 pRect->Normalize();
571 } 590 }
572 return TRUE; 591 return TRUE;
573 } 592 }
574 void CFX_PathData::Copy(const CFX_PathData &src) 593 FX_BOOL CFX_PathData::Copy(const CFX_PathData &src)
575 { 594 {
576 SetPointCount(src.m_PointCount); 595 if (!SetPointCount(src.m_PointCount)) {
596 return FALSE;
597 }
577 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount ); 598 FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount );
599 return TRUE;
578 } 600 }
579 CFX_GraphStateData::CFX_GraphStateData() 601 CFX_GraphStateData::CFX_GraphStateData()
580 { 602 {
581 m_LineCap = LineCapButt; 603 m_LineCap = LineCapButt;
582 m_DashCount = 0; 604 m_DashCount = 0;
583 m_DashArray = NULL; 605 m_DashArray = NULL;
584 m_DashPhase = 0; 606 m_DashPhase = 0;
585 m_LineJoin = LineJoinMiter; 607 m_LineJoin = LineJoinMiter;
586 m_MiterLimit = 10 * 1.0f; 608 m_MiterLimit = 10 * 1.0f;
587 m_LineWidth = 1.0f; 609 m_LineWidth = 1.0f;
(...skipping 10 matching lines...) Expand all
598 if (m_DashArray) { 620 if (m_DashArray) {
599 FX_Free(m_DashArray); 621 FX_Free(m_DashArray);
600 } 622 }
601 m_DashArray = NULL; 623 m_DashArray = NULL;
602 m_DashPhase = src.m_DashPhase; 624 m_DashPhase = src.m_DashPhase;
603 m_LineJoin = src.m_LineJoin; 625 m_LineJoin = src.m_LineJoin;
604 m_MiterLimit = src.m_MiterLimit; 626 m_MiterLimit = src.m_MiterLimit;
605 m_LineWidth = src.m_LineWidth; 627 m_LineWidth = src.m_LineWidth;
606 if (m_DashCount) { 628 if (m_DashCount) {
607 m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount); 629 m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount);
630 if (!m_DashArray) {
631 return;
632 }
608 FXSYS_memcpy32(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLO AT)); 633 FXSYS_memcpy32(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLO AT));
609 } 634 }
610 } 635 }
611 CFX_GraphStateData::~CFX_GraphStateData() 636 CFX_GraphStateData::~CFX_GraphStateData()
612 { 637 {
613 if (m_DashArray) { 638 if (m_DashArray) {
614 FX_Free(m_DashArray); 639 FX_Free(m_DashArray);
615 } 640 }
616 } 641 }
617 void CFX_GraphStateData::SetDashCount(int count) 642 void CFX_GraphStateData::SetDashCount(int count)
618 { 643 {
619 if (m_DashArray) { 644 if (m_DashArray) {
620 FX_Free(m_DashArray); 645 FX_Free(m_DashArray);
621 } 646 }
622 m_DashArray = NULL; 647 m_DashArray = NULL;
623 m_DashCount = count; 648 m_DashCount = count;
624 if (count == 0) { 649 if (count == 0) {
625 return; 650 return;
626 } 651 }
627 m_DashArray = FX_Alloc(FX_FLOAT, count); 652 m_DashArray = FX_Alloc(FX_FLOAT, count);
628 } 653 }
OLDNEW
« no previous file with comments | « core/src/fxge/ge/fx_ge_fontmap.cpp ('k') | core/src/fxge/ge/fx_ge_ps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698