summaryrefslogtreecommitdiff
path: root/core/src/fxge/ge
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-05-20 09:50:37 -0700
committerTom Sepez <tsepez@chromium.org>2015-05-20 09:50:37 -0700
commitd50b172a9d3a05704748f0798b5aaa422485abbd (patch)
tree0289d99b370b8526c539fc676004bf622f5228a3 /core/src/fxge/ge
parent90a4181194dd8eca153cf2a101ec27e382b27a58 (diff)
downloadpdfium-d50b172a9d3a05704748f0798b5aaa422485abbd.tar.xz
Merge to XFA: Remove FX_Alloc() null checks now that it can't return NULL.
Original Review URL: https://codereview.chromium.org/1142713005 R=thestig@chromium.org TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1143663008
Diffstat (limited to 'core/src/fxge/ge')
-rw-r--r--core/src/fxge/ge/fx_ge_font.cpp6
-rw-r--r--core/src/fxge/ge/fx_ge_fontmap.cpp19
-rw-r--r--core/src/fxge/ge/fx_ge_path.cpp62
-rw-r--r--core/src/fxge/ge/fx_ge_ps.cpp10
-rw-r--r--core/src/fxge/ge/fx_ge_text.cpp3
5 files changed, 22 insertions, 78 deletions
diff --git a/core/src/fxge/ge/fx_ge_font.cpp b/core/src/fxge/ge/fx_ge_font.cpp
index 57580f4799..46eecff323 100644
--- a/core/src/fxge/ge/fx_ge_font.cpp
+++ b/core/src/fxge/ge/fx_ge_font.cpp
@@ -140,9 +140,6 @@ extern "C" {
FX_BOOL _LoadFile(FXFT_Library library, FXFT_Face* Face, IFX_FileRead* pFile, FXFT_Stream* stream, FX_INT32 faceIndex = 0)
{
FXFT_Stream stream1 = (FXFT_Stream)FX_Alloc(FX_BYTE, sizeof (FXFT_StreamRec));
- if (!stream1) {
- return FALSE;
- }
stream1->base = NULL;
stream1->size = (unsigned long)pFile->GetSize();
stream1->pos = 0;
@@ -213,9 +210,6 @@ static FXFT_Face FT_LoadFont(FX_LPBYTE pData, int size)
FX_BOOL CFX_Font::LoadEmbedded(FX_LPCBYTE data, FX_DWORD size)
{
m_pFontDataAllocation = FX_Alloc(FX_BYTE, size);
- if (!m_pFontDataAllocation) {
- return FALSE;
- }
FXSYS_memcpy32(m_pFontDataAllocation, data, size);
m_Face = FT_LoadFont((FX_LPBYTE)m_pFontDataAllocation, size);
m_pFontData = (FX_LPBYTE)m_pFontDataAllocation;
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp
index c668f54834..ec4530b8ed 100644
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp
@@ -581,9 +581,6 @@ CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont)
FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0);
if (size) {
FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size);
- if (!buffer) {
- return result;
- }
m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size);
result = _FPDF_GetNameFromTT(buffer, 6);
FX_Free(buffer);
@@ -1229,21 +1226,15 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, FX_BOOL bTru
face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_size, pFontData);
if (face == NULL) {
pFontData = FX_Alloc(FX_BYTE, ttc_size);
- if (pFontData) {
- m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size);
- face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size,
- ttc_size - font_size);
- }
+ m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size);
+ face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size,
+ ttc_size - font_size);
}
} else {
FX_LPBYTE pFontData;
face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
if (face == NULL) {
pFontData = FX_Alloc(FX_BYTE, font_size);
- if (!pFontData) {
- m_pFontInfo->DeleteFont(hFont);
- return NULL;
- }
m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData, font_size, m_pFontInfo->GetFaceIndex(hFont));
}
@@ -1477,10 +1468,6 @@ void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path)
}
FX_DWORD face_bytes = nFaces * 4;
FX_LPBYTE offsets = FX_Alloc(FX_BYTE, face_bytes);
- if (!offsets) {
- FXSYS_fclose(pFile);
- return;
- }
readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile);
if (readCnt != face_bytes) {
FX_Free(offsets);
diff --git a/core/src/fxge/ge/fx_ge_path.cpp b/core/src/fxge/ge/fx_ge_path.cpp
index b96a2f1163..51d5908a81 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,24 @@ 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;
- }
+ pdfium::base::CheckedNumeric<int> safe_new_count = m_PointCount;
+ safe_new_count += addPoints;
+ int new_count = safe_new_count.ValueOrDie();
+ AllocPointCount(new_count);
m_PointCount = new_count;
- return TRUE;
}
-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 +187,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 +199,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 +572,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 +606,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));
}
}
diff --git a/core/src/fxge/ge/fx_ge_ps.cpp b/core/src/fxge/ge/fx_ge_ps.cpp
index 9da224602e..6522309f37 100644
--- a/core/src/fxge/ge/fx_ge_ps.cpp
+++ b/core/src/fxge/ge/fx_ge_ps.cpp
@@ -349,9 +349,6 @@ FX_BOOL CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, FX_DWORD color,
int pitch = (width + 7) / 8;
FX_DWORD src_size = height * pitch;
FX_LPBYTE src_buf = FX_Alloc(FX_BYTE, src_size);
- if (!src_buf) {
- return FALSE;
- }
for (int row = 0; row < height; row ++) {
FX_LPCBYTE src_scan = pSource->GetScanline(row);
FXSYS_memcpy32(src_buf + row * pitch, src_scan, pitch);
@@ -425,13 +422,6 @@ FX_BOOL CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, FX_DWORD color,
int src_pitch = width * Bpp;
output_size = height * src_pitch;
output_buf = FX_Alloc(FX_BYTE, output_size);
- if (!output_buf) {
- if (pConverted != pSource) {
- delete pConverted;
- pConverted = NULL;
- }
- return FALSE;
- }
for (int row = 0; row < height; row ++) {
FX_LPCBYTE src_scan = pConverted->GetScanline(row);
FX_LPBYTE dest_scan = output_buf + row * src_pitch;
diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp
index e20d6bc4bd..88f2967132 100644
--- a/core/src/fxge/ge/fx_ge_text.cpp
+++ b/core/src/fxge/ge/fx_ge_text.cpp
@@ -199,9 +199,6 @@ FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, const FXTEXT_CHARPOS* pChar
CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont);
FX_FONTCACHE_DEFINE(pCache, pFont);
FXTEXT_GLYPHPOS* pGlyphAndPos = FX_Alloc(FXTEXT_GLYPHPOS, nChars);
- if (!pGlyphAndPos) {
- return FALSE;
- }
int iChar;
deviceCtm = char2device;
CFX_AffineMatrix matrixCTM = GetCTM();