Add a null pointer check to CPDF_CalRGB::v_Load().
[pdfium.git] / core / src / fpdfapi / fpdf_page / fpdf_page_parser.cpp
index 879c2f3..fdc4a27 100644 (file)
@@ -1,7 +1,7 @@
 // Copyright 2014 PDFium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include "../../../include/fpdfapi/fpdf_page.h"
@@ -20,7 +20,7 @@ CPDF_StreamContentParser::CPDF_StreamContentParser()
     m_PathCurrentX = m_PathCurrentY = 0.0f;
     m_bResourceMissing = FALSE;
     m_bColored = FALSE;
-    FXSYS_memset32(m_Type3Data, 0, sizeof(FX_FLOAT) * 6);
+    FXSYS_memset(m_Type3Data, 0, sizeof(FX_FLOAT) * 6);
     m_ParamCount = 0;
     m_ParamStartPos = 0;
     m_bAbort = FALSE;
@@ -44,9 +44,7 @@ CPDF_StreamContentParser::~CPDF_StreamContentParser()
     if (m_pPathPoints) {
         FX_Free(m_pPathPoints);
     }
-    if (m_pCurStates) {
-        delete m_pCurStates;
-    }
+    delete m_pCurStates;
     if (m_pLastImageDict) {
         m_pLastImageDict->Release();
     }
@@ -83,7 +81,7 @@ void CPDF_StreamContentParser::PrepareParse(CPDF_Document* pDocument,
         m_BBox = *pBBox;
     }
     m_Level = level;
-    m_pCurStates = FX_NEW CPDF_AllStates;
+    m_pCurStates = new CPDF_AllStates;
     if (pStates) {
         m_pCurStates->Copy(*pStates);
     } else {
@@ -113,7 +111,7 @@ int CPDF_StreamContentParser::GetNextParamPos()
     m_ParamCount ++;
     return index;
 }
-void CPDF_StreamContentParser::AddNameParam(FX_LPCSTR name, int len)
+void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len)
 {
     int index = GetNextParamPos();
     if (len > 32) {
@@ -122,16 +120,16 @@ void CPDF_StreamContentParser::AddNameParam(FX_LPCSTR name, int len)
     } else {
         m_ParamBuf1[index].m_Type = PDFOBJ_NAME;
         if (FXSYS_memchr(name, '#', len) == NULL) {
-            FXSYS_memcpy32(m_ParamBuf1[index].m_Name.m_Buffer, name, len);
+            FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, name, len);
             m_ParamBuf1[index].m_Name.m_Len = len;
         } else {
             CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len));
-            FXSYS_memcpy32(m_ParamBuf1[index].m_Name.m_Buffer, (FX_LPCSTR)str, str.GetLength());
+            FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, str.c_str(), str.GetLength());
             m_ParamBuf1[index].m_Name.m_Len = str.GetLength();
         }
     }
 }
-void CPDF_StreamContentParser::AddNumberParam(FX_LPCSTR str, int len)
+void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len)
 {
     int index = GetNextParamPos();
     m_ParamBuf1[index].m_Type = PDFOBJ_NUMBER;
@@ -321,7 +319,7 @@ const struct _OpCode {
     {FXBSTR_ID('w', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetLineWidth},
     {FXBSTR_ID('y', 0, 0, 0),          &CPDF_StreamContentParser::Handle_CurveTo_13},
 };
-FX_BOOL CPDF_StreamContentParser::OnOperator(FX_LPCSTR op)
+FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op)
 {
     int i = 0;
     FX_DWORD opid = 0;
@@ -410,7 +408,7 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent()
     m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
 }
 struct _FX_BSTR {
-    FX_LPCSTR  m_Ptr;
+    const FX_CHAR*     m_Ptr;
     int                        m_Size;
 };
 #define _FX_BSTRC(str) {str, sizeof(str)-1}
@@ -438,11 +436,11 @@ const _FX_BSTR _PDF_InlineValueAbbr[] = {
     _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"),
     _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"),
 };
-static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table, int count, FX_BSTR abbr)
+static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table, int count, const CFX_ByteStringC& abbr)
 {
     int i = 0;
     while (i < count) {
-        if (abbr.GetLength() == table[i + 1].m_Size && FXSYS_memcmp32(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) == 0) {
+        if (abbr.GetLength() == table[i + 1].m_Size && FXSYS_memcmp(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) == 0) {
             return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size);
         }
         i += 2;
@@ -496,11 +494,11 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj)
             }
     }
 }
-static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table, int count, FX_BSTR fullName)
+static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table, int count, const CFX_ByteStringC& fullName)
 {
     int i = 0;
     while (i < count) {
-        if (fullName.GetLength() == table[i].m_Size && FXSYS_memcmp32(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) == 0) {
+        if (fullName.GetLength() == table[i].m_Size && FXSYS_memcmp(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) == 0) {
             return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);
         }
         i += 2;
@@ -731,8 +729,8 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream)
         parser.Parse(stream.GetData(), stream.GetSize(), 0);
         return;
     }
-    CPDF_FormObject* pFormObj = FX_NEW CPDF_FormObject;
-    pFormObj->m_pForm = FX_NEW CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);
+    CPDF_FormObject* pFormObj = new CPDF_FormObject;
+    pFormObj->m_pForm = new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);
     pFormObj->m_FormMatrix = m_pCurStates->m_CTM;
     pFormObj->m_FormMatrix.Concat(m_mtContentToUser);
     CPDF_AllStates status;
@@ -756,13 +754,13 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, CPDF_
     CFX_AffineMatrix ImageMatrix;
     ImageMatrix.Copy(m_pCurStates->m_CTM);
     ImageMatrix.Concat(m_mtContentToUser);
-    CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
+    CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
     if (pImage) {
         pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pImage->GetStream());
     } else if (pStream->GetObjNum()) {
         pImageObj->m_pImage = m_pDocument->LoadImageF(pStream);
     } else {
-        pImageObj->m_pImage = FX_NEW CPDF_Image(m_pDocument);
+        pImageObj->m_pImage = new CPDF_Image(m_pDocument);
         pImageObj->m_pImage->LoadImageF(pStream, bInline);
     }
     SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE);
@@ -801,9 +799,7 @@ void CPDF_StreamContentParser::Handle_EndText()
     if (m_pCurStates->m_TextState.GetObject()->m_TextMode < 4) {
         for (int i = 0; i < count; i ++) {
             CPDF_TextObject* pText = (CPDF_TextObject*)m_ClipTextList.GetAt(i);
-            if (pText) {
-                delete pText;
-            }
+            delete pText;
         }
     } else {
         m_pCurStates->m_ClipPath.AppendTexts((CPDF_TextObject**)m_ClipTextList.GetData(), count);
@@ -942,7 +938,7 @@ void CPDF_StreamContentParser::Handle_EndPath()
 }
 void CPDF_StreamContentParser::Handle_SaveGraphState()
 {
-    CPDF_AllStates* pStates = FX_NEW CPDF_AllStates;
+    CPDF_AllStates* pStates = new CPDF_AllStates;
     pStates->Copy(*m_pCurStates);
     m_StateStack.Add(pStates);
 }
@@ -1129,7 +1125,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill()
     if (!pShading->Load()) {
         return;
     }
-    CPDF_ShadingObject* pObj = FX_NEW CPDF_ShadingObject;
+    CPDF_ShadingObject* pObj = new CPDF_ShadingObject;
     pObj->m_pShading = pShading;
     SetGraphicStates(pObj, FALSE, FALSE, FALSE);
     pObj->m_Matrix = m_pCurStates->m_CTM;
@@ -1178,7 +1174,7 @@ void CPDF_StreamContentParser::Handle_SetFont()
         m_pCurStates->m_TextState.SetFont(pFont);
     }
 }
-CPDF_Object* CPDF_StreamContentParser::FindResourceObj(FX_BSTR type, const CFX_ByteString& name)
+CPDF_Object* CPDF_StreamContentParser::FindResourceObj(const CFX_ByteStringC& type, const CFX_ByteString& name)
 {
     if (m_pResources == NULL) {
         return NULL;
@@ -1289,7 +1285,7 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, FX_FLOAT fIn
     } else {
         textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode;
     }
-    CPDF_TextObject* pText = FX_NEW CPDF_TextObject;
+    CPDF_TextObject* pText = new CPDF_TextObject;
     m_pLastTextObject = pText;
     SetGraphicStates(pText, TRUE, TRUE, TRUE);
     if (textmode && textmode != 3 && textmode != 4 && textmode != 7) {
@@ -1308,7 +1304,7 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, FX_FLOAT fIn
     m_pCurStates->m_TextX += x_advance;
     m_pCurStates->m_TextY += y_advance;
     if (textmode > 3) {
-        CPDF_TextObject* pCopy = FX_NEW CPDF_TextObject;
+        CPDF_TextObject* pCopy = new CPDF_TextObject;
         pCopy->Copy(pText);
         m_ClipTextList.Add(pCopy);
     }
@@ -1348,8 +1344,7 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning()
         };
         return;
     }
-    CFX_ByteString* pStrs;
-    FX_NEW_VECTOR(pStrs, CFX_ByteString, nsegs);
+    CFX_ByteString* pStrs = new CFX_ByteString[nsegs];
     FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs);
     int iSegment = 0;
     FX_FLOAT fInitKerning = 0;
@@ -1372,7 +1367,7 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning()
         }
     }
     AddTextObject(pStrs, fInitKerning, pKerning, iSegment);
-    FX_DELETE_VECTOR(pStrs, CFX_ByteString, nsegs);
+    delete[] pStrs;
     FX_Free(pKerning);
 }
 void CPDF_StreamContentParser::Handle_SetTextLeading()
@@ -1496,7 +1491,7 @@ void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag)
         int newsize = m_PathPointCount + 256;
         FX_PATHPOINT* pNewPoints = FX_Alloc(FX_PATHPOINT, newsize);
         if (m_PathAllocSize) {
-            FXSYS_memcpy32(pNewPoints, m_pPathPoints, m_PathAllocSize * sizeof(FX_PATHPOINT));
+            FXSYS_memcpy(pNewPoints, m_pPathPoints, m_PathAllocSize * sizeof(FX_PATHPOINT));
             FX_Free(m_pPathPoints);
         }
         m_pPathPoints = pNewPoints;
@@ -1525,11 +1520,11 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke)
     CPDF_Path Path;
     CFX_PathData* pPathData = Path.New();
     pPathData->SetPointCount(PathPointCount);
-    FXSYS_memcpy32(pPathData->GetPoints(), m_pPathPoints, sizeof(FX_PATHPOINT) * PathPointCount);
+    FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, sizeof(FX_PATHPOINT) * PathPointCount);
     CFX_AffineMatrix matrix = m_pCurStates->m_CTM;
     matrix.Concat(m_mtContentToUser);
     if (bStroke || FillType) {
-        CPDF_PathObject* pPathObj = FX_NEW CPDF_PathObject;
+        CPDF_PathObject* pPathObj = new CPDF_PathObject;
         pPathObj->m_bStroke = bStroke;
         pPathObj->m_FillType = FillType;
         pPathObj->m_Path = Path;
@@ -1551,10 +1546,10 @@ CFX_ByteString _FPDF_ByteStringFromHex(CFX_BinaryBuf& src_buf)
     CFX_ByteTextBuf buf;
     FX_BOOL bFirst = TRUE;
     int code = 0;
-    FX_LPCBYTE str = src_buf.GetBuffer();
+    const uint8_t* str = src_buf.GetBuffer();
     FX_DWORD size = src_buf.GetSize();
     for (FX_DWORD i = 0; i < size; i ++) {
-        FX_BYTE ch = str[i];
+        uint8_t ch = str[i];
         if (ch >= '0' && ch <= '9') {
             if (bFirst) {
                 code = (ch - '0') * 16;