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

Unified Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 361553002: Remove "this==NULL" and adjust corresponding callers (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: fix if check warning Created 6 years, 6 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
Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index c705ea73576de248cec87e003635782a35a5ae99..5e926c31b940b9dd68e0d77e6097b5d7a937c8b0 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -78,7 +78,7 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse)
}
ReleaseEncryptHandler();
SetEncryptDictionary(NULL);
- if (m_bOwnFileRead && m_Syntax.m_pFileAccess != NULL) {
+ if (m_bOwnFileRead && m_Syntax.m_pFileAccess) {
m_Syntax.m_pFileAccess->Release();
m_Syntax.m_pFileAccess = NULL;
}
@@ -96,7 +96,8 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse)
m_ObjVersion.RemoveAll();
FX_INT32 iLen = m_Trailers.GetSize();
for (FX_INT32 i = 0; i < iLen; ++i) {
- m_Trailers.GetAt(i)->Release();
+ if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i))
+ trailer->Release();
}
m_Trailers.RemoveAll();
if (m_pLinearized) {
@@ -1110,7 +1111,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL
}
CPDF_Array* CPDF_Parser::GetIDArray()
{
- CPDF_Object* pID = m_pTrailer->GetElement(FX_BSTRC("ID"));
+ CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL;
if (pID == NULL) {
return NULL;
}
@@ -1125,7 +1126,7 @@ CPDF_Array* CPDF_Parser::GetIDArray()
}
FX_DWORD CPDF_Parser::GetRootObjNum()
{
- CPDF_Reference* pRef = (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Root"));
+ CPDF_Reference* pRef = m_pTrailer ? (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL;
if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
return 0;
}
@@ -1133,7 +1134,7 @@ FX_DWORD CPDF_Parser::GetRootObjNum()
}
FX_DWORD CPDF_Parser::GetInfoObjNum()
{
- CPDF_Reference* pRef = (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Info"));
+ CPDF_Reference* pRef = m_pTrailer ? (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Info")) : NULL;
if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
return 0;
}
@@ -1491,7 +1492,7 @@ FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset
if (!m_pLinearized) {
return FALSE;
}
- if (m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) {
+ if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) {
m_Syntax.GetNextWord(bIsNumber);
CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L"));
if (!pLen) {
@@ -2150,7 +2151,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
FX_BOOL bIsNumber;
CFX_ByteString key = GetNextWord(bIsNumber);
if (key.IsEmpty()) {
- pDict->Release();
+ if (pDict)
+ pDict->Release();
return NULL;
}
FX_FILESIZE SavedPos = m_Pos - key.GetLength();
@@ -2206,7 +2208,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
if (pStream) {
return pStream;
}
- pDict->Release();
+ if (pDict)
+ pDict->Release();
return NULL;
} else {
m_Pos = SavedPos;
@@ -2307,7 +2310,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
if (m_WordBuffer[0] == ']') {
return pArray;
}
- pArray->Release();
+ if (pArray)
+ pArray->Release();
return NULL;
}
pArray->Add(pObj);
@@ -2332,7 +2336,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
FX_FILESIZE SavedPos = m_Pos;
CFX_ByteString key = GetNextWord(bIsNumber);
if (key.IsEmpty()) {
- pDict->Release();
+ if (pDict)
+ pDict->Release();
return NULL;
}
if (key == FX_BSTRC(">>")) {
@@ -2348,7 +2353,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
key = PDF_NameDecode(key);
CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, level + 1);
if (pObj == NULL) {
- pDict->Release();
+ if (pDict)
+ pDict->Release();
FX_BYTE ch;
while (1) {
if (!GetNextChar(ch)) {
@@ -2380,7 +2386,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
if (pStream) {
return pStream;
}
- pDict->Release();
+ if (pDict)
+ pDict->Release();
return NULL;
} else {
m_Pos = SavedPos;
@@ -2835,7 +2842,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePa
pObj = pObj->GetDict();
case PDFOBJ_DICTIONARY: {
CPDF_Dictionary *pDict = pObj->GetDict();
- if (pDict->GetString("Type") == "Page" && !bParsePage) {
+ if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) {
continue;
}
FX_POSITION pos = pDict->GetStartPos();
@@ -3157,7 +3164,7 @@ FX_BOOL CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints)
FX_BOOL CPDF_DataAvail::PreparePageItem()
{
CPDF_Dictionary *pRoot = m_pDocument->GetRoot();
- CPDF_Reference* pRef = (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages"));
+ CPDF_Reference* pRef = pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) : NULL;
if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
@@ -3270,7 +3277,8 @@ FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages)
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
}
- CPDF_Object *pKids = pPages->GetDict()->GetElement(FX_BSTRC("Kids"));
+ CPDF_Dictionary* pDict = pPages->GetDict();
+ CPDF_Object *pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL;
if (!pKids) {
return TRUE;
}
@@ -3344,17 +3352,18 @@ FX_BOOL CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints)
FX_BOOL CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints)
{
FX_DWORD dwFirstPageEndOffset = 0;
- CPDF_Object *pEndOffSet = m_pLinearized->GetDict()->GetElement(FX_BSTRC("E"));
+ CPDF_Dictionary* pDict = m_pLinearized->GetDict();
+ CPDF_Object *pEndOffSet = pDict ? pDict->GetElement(FX_BSTRC("E")) : NULL;
if (!pEndOffSet) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
}
- CPDF_Object *pXRefOffset = m_pLinearized->GetDict()->GetElement(FX_BSTRC("T"));
+ CPDF_Object *pXRefOffset = pDict ? pDict->GetElement(FX_BSTRC("T")) : NULL;
if (!pXRefOffset) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
}
- CPDF_Object *pFileLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L"));
+ CPDF_Object *pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL;
if (!pFileLen) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
@@ -3473,7 +3482,7 @@ FX_BOOL CPDF_DataAvail::IsLinearizedFile(FX_LPBYTE pData, FX_DWORD dwLen)
if (!m_pLinearized) {
return FALSE;
}
- if (m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) {
+ if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) {
CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L"));
if (!pLen) {
return FALSE;
@@ -3548,7 +3557,8 @@ FX_DWORD CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILES
m_Pos += m_parser.m_Syntax.SavePos();
return 0;
}
- CPDF_Object *pName = pObj->GetDict()->GetElement(FX_BSTRC("Type"));
+ CPDF_Dictionary* pDict = pObj->GetDict();
+ CPDF_Object *pName = pDict ? pDict->GetElement(FX_BSTRC("Type")) : NULL;
if (pName && pName->GetType() == PDFOBJ_NAME) {
if (pName->GetString() == FX_BSTRC("XRef")) {
m_Pos += m_parser.m_Syntax.SavePos();
@@ -3908,10 +3918,11 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pP
return FALSE;
}
pPageNode->m_dwPageNo = dwPageNo;
- CFX_ByteString type = pPage->GetDict()->GetString(FX_BSTRC("Type"));
+ CPDF_Dictionary* pDict = pPage->GetDict();
+ CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteString();
if (type == FX_BSTRC("Pages")) {
pPageNode->m_type = PDF_PAGENODE_PAGES;
- CPDF_Object *pKids = pPage->GetDict()->GetElement(FX_BSTRC("Kids"));
+ CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids"));
if (!pKids) {
m_docStatus = PDF_DATAAVAIL_PAGE;
return TRUE;
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698