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

Unified Diff: core/src/fxge/ge/fx_ge_path.cpp

Issue 1142713005: Remove FX_Alloc() null checks now that it can't return NULL. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix missing FX_Alloc2D, check overflow on add, remove unused enum. 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxge/ge/fx_ge_path.cpp
diff --git a/core/src/fxge/ge/fx_ge_path.cpp b/core/src/fxge/ge/fx_ge_path.cpp
index b96a2f1163acd3d9d49d7229f35de1258aa948da..5982082f7b16074a70865c47cdb83590d747a9db 100644
--- a/core/src/fxge/ge/fx_ge_path.cpp
+++ b/core/src/fxge/ge/fx_ge_path.cpp
@@ -4,8 +4,10 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "../../../../third_party/base/numerics/safe_math.h"
#include "../../../include/fxcrt/fx_basic.h"
#include "../../../include/fxge/fx_ge.h"
+
CFX_ClipRgn::CFX_ClipRgn(int width, int height)
{
m_Type = RectI;
@@ -120,7 +122,7 @@ CFX_PathData::~CFX_PathData()
FX_Free(m_pPoints);
}
}
-FX_BOOL CFX_PathData::SetPointCount(int nPoints)
+void CFX_PathData::SetPointCount(int nPoints)
{
m_PointCount = nPoints;
if (m_AllocCount < nPoints) {
@@ -129,20 +131,13 @@ FX_BOOL CFX_PathData::SetPointCount(int nPoints)
m_pPoints = NULL;
}
m_pPoints = FX_Alloc(FX_PATHPOINT, nPoints);
- if (!m_pPoints) {
- return FALSE;
- }
m_AllocCount = nPoints;
}
- return TRUE;
}
-FX_BOOL CFX_PathData::AllocPointCount(int nPoints)
+void CFX_PathData::AllocPointCount(int nPoints)
{
if (m_AllocCount < nPoints) {
FX_PATHPOINT* pNewBuf = FX_Alloc(FX_PATHPOINT, nPoints);
- if (!pNewBuf) {
- return FALSE;
- }
if (m_PointCount) {
FXSYS_memcpy32(pNewBuf, m_pPoints, m_PointCount * sizeof(FX_PATHPOINT));
}
@@ -152,16 +147,11 @@ FX_BOOL CFX_PathData::AllocPointCount(int nPoints)
m_pPoints = pNewBuf;
m_AllocCount = nPoints;
}
- return TRUE;
}
CFX_PathData::CFX_PathData(const CFX_PathData& src)
{
- m_pPoints = NULL;
m_PointCount = m_AllocCount = src.m_PointCount;
m_pPoints = FX_Alloc(FX_PATHPOINT, src.m_PointCount);
- if (!m_pPoints) {
- return;
- }
FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount);
}
void CFX_PathData::TrimPoints(int nPoints)
@@ -171,29 +161,23 @@ void CFX_PathData::TrimPoints(int nPoints)
}
SetPointCount(nPoints);
}
-FX_BOOL CFX_PathData::AddPointCount(int addPoints)
+void CFX_PathData::AddPointCount(int addPoints)
{
- int new_count = m_PointCount + addPoints;
- if (!AllocPointCount(new_count)) {
- return FALSE;
- }
- m_PointCount = new_count;
- return TRUE;
+ pdfium::base::CheckedNumeric<int> new_count = m_PointCount;
+ new_count += addPoints;
+ m_PointCount = new_count.ValueOrDie();
+ AllocPointCount(m_PointCount);
}
-FX_BOOL CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMatrix)
+void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMatrix)
{
int old_count = m_PointCount;
- if (!AddPointCount(pSrc->m_PointCount)) {
- return FALSE;
- }
+ AddPointCount(pSrc->m_PointCount);
FXSYS_memcpy32(m_pPoints + old_count, pSrc->m_pPoints, pSrc->m_PointCount * sizeof(FX_PATHPOINT));
- if (pMatrix == NULL) {
- return TRUE;
- }
- for (int i = 0; i < pSrc->m_PointCount; i ++) {
- pMatrix->Transform(m_pPoints[old_count + i].m_PointX, m_pPoints[old_count + i].m_PointY);
+ if (pMatrix) {
+ for (int i = 0; i < pSrc->m_PointCount; i ++) {
+ pMatrix->Transform(m_pPoints[old_count + i].m_PointX, m_pPoints[old_count + i].m_PointY);
+ }
}
- return TRUE;
}
void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag)
{
@@ -202,12 +186,10 @@ void CFX_PathData::SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag)
m_pPoints[index].m_PointY = y;
m_pPoints[index].m_Flag = flag;
}
-FX_BOOL CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top)
+void CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top)
{
int old_count = m_PointCount;
- if (!AddPointCount(5)) {
- return FALSE;
- }
+ AddPointCount(5);
FX_PATHPOINT* pPoints = m_pPoints + old_count;
pPoints[0].m_PointX = pPoints[1].m_PointX = pPoints[4].m_PointX = left;
pPoints[2].m_PointX = pPoints[3].m_PointX = right;
@@ -216,7 +198,6 @@ FX_BOOL CFX_PathData::AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right,
pPoints[0].m_Flag = FXPT_MOVETO;
pPoints[1].m_Flag = pPoints[2].m_Flag = pPoints[3].m_Flag = FXPT_LINETO;
pPoints[4].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE;
- return TRUE;
}
CFX_FloatRect CFX_PathData::GetBoundingBox() const
{
@@ -590,13 +571,10 @@ FX_BOOL CFX_PathData::IsRect(const CFX_AffineMatrix* pMatrix, CFX_FloatRect* pRe
}
return TRUE;
}
-FX_BOOL CFX_PathData::Copy(const CFX_PathData &src)
+void CFX_PathData::Copy(const CFX_PathData &src)
{
- if (!SetPointCount(src.m_PointCount)) {
- return FALSE;
- }
+ SetPointCount(src.m_PointCount);
FXSYS_memcpy32(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount);
- return TRUE;
}
CFX_GraphStateData::CFX_GraphStateData()
{
@@ -627,9 +605,6 @@ void CFX_GraphStateData::Copy(const CFX_GraphStateData& src)
m_LineWidth = src.m_LineWidth;
if (m_DashCount) {
m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount);
- if (!m_DashArray) {
- return;
- }
FXSYS_memcpy32(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLOAT));
}
}
« 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