From f1251c1ff2b3452854681d0648b4c1ca4180ff0d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 20 Oct 2015 16:24:45 -0400 Subject: [Merge to XFA] Revert "Revert "Add type cast definitions for CPDF_Dictionary."" This reverts commit 937840e1722d1f2b77d80575d6e710d760662c9c. Add type cast definitions for CPDF_Dictionary. This CL adds ToCPDFDictionary type definitions and updates one file to use instead of straight casts. I had to fix two places where we'd casted off the constness of the original pointer. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1420583003 . (cherry picked from commit 39869b641511c882d78e17548293cdb458c36f38) Review URL: https://codereview.chromium.org/1410343003 . --- .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to '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 35c1a5892b..6839c07c07 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -277,8 +277,8 @@ FX_DWORD CPDF_Parser::SetEncryptHandler() { } CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt")); if (pEncryptObj) { - if (pEncryptObj->GetType() == PDFOBJ_DICTIONARY) { - SetEncryptDictionary((CPDF_Dictionary*)pEncryptObj); + if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { + SetEncryptDictionary(pEncryptDict); } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) { pEncryptObj = m_pDocument->GetIndirectObject( ((CPDF_Reference*)pEncryptObj)->GetRefObjNum()); @@ -804,7 +804,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { if (m_pTrailer) { m_pTrailer->Release(); } - m_pTrailer = (CPDF_Dictionary*)pDict->Clone(); + m_pTrailer = ToDictionary(pDict->Clone()); } } } @@ -857,15 +857,14 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset); CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0); if (pObj) { - if (pObj->GetType() != PDFOBJ_DICTIONARY && - pObj->GetType() != PDFOBJ_STREAM) { + if (!pObj->IsDictionary() && pObj->GetType() != PDFOBJ_STREAM) { pObj->Release(); } else { CPDF_Dictionary* pTrailer = NULL; if (pObj->GetType() == PDFOBJ_STREAM) { pTrailer = ((CPDF_Stream*)pObj)->GetDict(); } else { - pTrailer = (CPDF_Dictionary*)pObj; + pTrailer = pObj->AsDictionary(); } if (pTrailer) { if (m_pTrailer) { @@ -890,7 +889,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { } } else { if (pObj->GetType() == PDFOBJ_STREAM) { - m_pTrailer = (CPDF_Dictionary*)pTrailer->Clone(); + m_pTrailer = ToDictionary(pTrailer->Clone()); pObj->Release(); } else { m_pTrailer = pTrailer; @@ -1034,13 +1033,13 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, return FALSE; } if (bMainXRef) { - m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone(); + m_pTrailer = ToDictionary(pStream->GetDict()->Clone()); m_CrossRef.SetSize(size); if (m_V5Type.SetSize(size)) { FXSYS_memset(m_V5Type.GetData(), 0, size); } } else { - m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone()); + m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); } std::vector > arrIndex; CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index")); @@ -1490,9 +1489,9 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { nonstd::unique_ptr> pObj( m_Syntax.GetObject(m_pDocument, 0, 0, 0)); - if (!pObj || pObj->GetType() != PDFOBJ_DICTIONARY) + if (!ToDictionary(pObj.get())) return nullptr; - return static_cast(pObj.release()); + return pObj.release()->AsDictionary(); } FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) { @@ -3496,7 +3495,7 @@ FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { } } } - if (pObj->GetType() != PDFOBJ_DICTIONARY) { + if (!pObj->IsDictionary()) { pObj->Release(); continue; } @@ -4049,7 +4048,7 @@ FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) { pHints->AddSegment(m_Pos, iTrailerSize); return FALSE; } - if (pTrailer->GetType() != PDFOBJ_DICTIONARY) + if (!pTrailer->IsDictionary()) return FALSE; CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); @@ -4164,7 +4163,7 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, pPage->Release(); return TRUE; } - if (pPage->GetType() != PDFOBJ_DICTIONARY) { + if (!pPage->IsDictionary()) { pPage->Release(); m_docStatus = PDF_DATAAVAIL_ERROR; return FALSE; -- cgit v1.2.3