diff options
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 124 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 90 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_form.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_baseform.cpp | 6 |
4 files changed, 90 insertions, 132 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index 46875d88a5..cfd76aef40 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -244,7 +244,8 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, const CPDF_Array* pThis = AsArray(); int n = pThis->GetCount(); for (int i = 0; i < n; i++) { - CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i); + CPDF_Object* value = + static_cast<CPDF_Object*>(pThis->m_Objects.GetAt(i)); pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); } return pCopy; @@ -443,44 +444,34 @@ CFX_AffineMatrix CPDF_Array::GetMatrix() { return matrix; } CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const { - if (i >= (FX_DWORD)m_Objects.GetSize()) { - return NULL; - } - return (CPDF_Object*)m_Objects.GetAt(i); + if (i >= (FX_DWORD)m_Objects.GetSize()) + return nullptr; + return static_cast<CPDF_Object*>(m_Objects.GetAt(i)); } CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const { - if (i >= (FX_DWORD)m_Objects.GetSize()) { - return NULL; - } - return ((CPDF_Object*)m_Objects.GetAt(i))->GetDirect(); + if (i >= (FX_DWORD)m_Objects.GetSize()) + return nullptr; + return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetDirect(); } CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const { - if (i < (FX_DWORD)m_Objects.GetSize()) { - CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); - return p->GetString(); - } + if (i < (FX_DWORD)m_Objects.GetSize()) + return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetString(); return CFX_ByteString(); } CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const { - if (i < (FX_DWORD)m_Objects.GetSize()) { - CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); - return p->GetConstString(); - } + if (i < (FX_DWORD)m_Objects.GetSize()) + return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetConstString(); return CFX_ByteStringC(); } int CPDF_Array::GetInteger(FX_DWORD i) const { - if (i >= (FX_DWORD)m_Objects.GetSize()) { + if (i >= (FX_DWORD)m_Objects.GetSize()) return 0; - } - CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); - return p->GetInteger(); + return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetInteger(); } FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const { - if (i >= (FX_DWORD)m_Objects.GetSize()) { + if (i >= (FX_DWORD)m_Objects.GetSize()) return 0; - } - CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); - return p->GetNumber(); + return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetNumber(); } CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const { CPDF_Object* p = GetElementValue(i); @@ -500,11 +491,9 @@ CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const { } void CPDF_Array::RemoveAt(FX_DWORD i) { ASSERT(IsArray()); - if (i >= (FX_DWORD)m_Objects.GetSize()) { + if (i >= (FX_DWORD)m_Objects.GetSize()) return; - } - CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); - if (p) + if (CPDF_Object* p = static_cast<CPDF_Object*>(m_Objects.GetAt(i))) p->Release(); m_Objects.RemoveAt(i); } @@ -513,14 +502,12 @@ void CPDF_Array::SetAt(FX_DWORD i, CPDF_IndirectObjects* pObjs) { ASSERT(IsArray()); ASSERT(i < (FX_DWORD)m_Objects.GetSize()); - if (i >= (FX_DWORD)m_Objects.GetSize()) { + if (i >= (FX_DWORD)m_Objects.GetSize()) return; - } - CPDF_Object* pOld = (CPDF_Object*)m_Objects.GetAt(i); - if (pOld) + if (CPDF_Object* pOld = static_cast<CPDF_Object*>(m_Objects.GetAt(i))) pOld->Release(); if (pObj->GetObjNum()) { - ASSERT(pObjs != NULL); + ASSERT(pObjs); pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); } m_Objects.SetAt(i, pObj); @@ -570,8 +557,8 @@ FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const { return FALSE; } for (int i = 0; i < m_Objects.GetSize(); i++) - if (!((CPDF_Object*)m_Objects[i]) - ->IsIdentical((CPDF_Object*)pOther->m_Objects[i])) { + if (!static_cast<CPDF_Object*>(m_Objects[i]) + ->IsIdentical(static_cast<CPDF_Object*>(pOther->m_Objects[i]))) { return FALSE; } return TRUE; @@ -579,9 +566,8 @@ FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const { CPDF_Dictionary::~CPDF_Dictionary() { FX_POSITION pos = m_Map.GetStartPosition(); while (pos) { - void* value = m_Map.GetNextValue(pos); - if (value) - ((CPDF_Object*)value)->Release(); + if (CPDF_Object* value = static_cast<CPDF_Object*>(m_Map.GetNextValue(pos))) + value->Release(); } } FX_POSITION CPDF_Dictionary::GetStartPos() const { @@ -774,9 +760,8 @@ FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const { m_Map.GetNextAssoc(pos, key, value); if (!value) return FALSE; - if (!((CPDF_Object*)value)->IsIdentical(pOther->GetElement(key))) { + if (!static_cast<CPDF_Object*>(value)->IsIdentical(pOther->GetElement(key))) return FALSE; - } } return TRUE; } @@ -1119,48 +1104,44 @@ CPDF_IndirectObjects::~CPDF_IndirectObjects() { void* key; void* value; m_IndirectObjs.GetNextAssoc(pos, key, value); - ((CPDF_Object*)value)->Destroy(); + static_cast<CPDF_Object*>(value)->Destroy(); } } CPDF_Object* CPDF_IndirectObjects::GetIndirectObject( FX_DWORD objnum, struct PARSE_CONTEXT* pContext) { - if (objnum == 0) { - return NULL; - } + if (objnum == 0) + return nullptr; void* value; - { - if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { - if (((CPDF_Object*)value)->GetObjNum() == -1) { - return NULL; - } - return (CPDF_Object*)value; - } + if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { + CPDF_Object* pValue = static_cast<CPDF_Object*>(value); + if (pValue->GetObjNum() == -1) + return nullptr; + return pValue; } - CPDF_Object* pObj = NULL; - if (m_pParser) { + + CPDF_Object* pObj = nullptr; + if (m_pParser) pObj = m_pParser->ParseIndirectObject(this, objnum, pContext); - } - if (pObj == NULL) { - return NULL; - } + if (!pObj) + return nullptr; + pObj->m_ObjNum = objnum; if (m_LastObjNum < objnum) { m_LastObjNum = objnum; } if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { - if (value) { - ((CPDF_Object*)value)->Destroy(); - } + if (value) + static_cast<CPDF_Object*>(value)->Destroy(); } m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); return pObj; } int CPDF_IndirectObjects::GetIndirectType(FX_DWORD objnum) { void* value; - if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { - return ((CPDF_Object*)value)->GetType(); - } + if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) + return static_cast<CPDF_Object*>(value)->GetType(); + if (m_pParser) { PARSE_CONTEXT context; FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT)); @@ -1181,13 +1162,12 @@ FX_DWORD CPDF_IndirectObjects::AddIndirectObject(CPDF_Object* pObj) { } void CPDF_IndirectObjects::ReleaseIndirectObject(FX_DWORD objnum) { void* value; - if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { + if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) return; - } - if (((CPDF_Object*)value)->GetObjNum() == -1) { + CPDF_Object* pValue = static_cast<CPDF_Object*>(value); + if (pValue->GetObjNum() == -1) return; - } - ((CPDF_Object*)value)->Destroy(); + pValue->Destroy(); m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum); } void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, @@ -1198,10 +1178,10 @@ void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, void* value = NULL; if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { if (value) { - if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum()) { + CPDF_Object* pValue = static_cast<CPDF_Object*>(value); + if (pObj->GetGenNum() <= pValue->GetGenNum()) return; - } - ((CPDF_Object*)value)->Destroy(); + pValue->Destroy(); } } pObj->m_ObjNum = objnum; diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 8c1a123950..c1b78f1d81 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -2046,9 +2046,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_BOOL bIsNumber; CFX_ByteString word = GetNextWord(bIsNumber); if (word.GetLength() == 0) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_INVALID; - } return NULL; } if (bIsNumber) { @@ -2058,34 +2057,29 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, CFX_ByteString nextword2 = GetNextWord(bIsNumber); if (nextword2 == FX_BSTRC("R")) { FX_DWORD objnum = FXSYS_atoi(word); - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_REFERENCE; - } return new CPDF_Reference(pObjList, objnum); } } m_Pos = SavedPos; - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NUMBER; - } return CPDF_Number::Create(word); } if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_BOOLEAN; - } return CPDF_Boolean::Create(word == FX_BSTRC("true")); } if (word == FX_BSTRC("null")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NULL; - } return CPDF_Null::Create(); } if (word == FX_BSTRC("(")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_STRING; - } CFX_ByteString str = ReadString(); if (m_pCryptoHandler && bDecrypt) { m_pCryptoHandler->Decrypt(objnum, gennum, str); @@ -2093,9 +2087,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, return CPDF_String::Create(str, FALSE); } if (word == FX_BSTRC("<")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_STRING; - } CFX_ByteString str = ReadHexString(); if (m_pCryptoHandler && bDecrypt) { m_pCryptoHandler->Decrypt(objnum, gennum, str); @@ -2103,9 +2096,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, return CPDF_String::Create(str, TRUE); } if (word == FX_BSTRC("[")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_ARRAY; - } CPDF_Array* pArray = CPDF_Array::Create(); while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum)) pArray->Add(pObj); @@ -2113,9 +2105,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, return pArray; } if (word[0] == '/') { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NAME; - } return CPDF_Name::Create( PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); } @@ -2219,10 +2210,9 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( FX_BOOL bIsNumber; CFX_ByteString word = GetNextWord(bIsNumber); if (word.GetLength() == 0) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_INVALID; - } - return NULL; + return nullptr; } if (bIsNumber) { FX_FILESIZE SavedPos = m_Pos; @@ -2230,55 +2220,46 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( if (bIsNumber) { CFX_ByteString nextword2 = GetNextWord(bIsNumber); if (nextword2 == FX_BSTRC("R")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_REFERENCE; - } FX_DWORD objnum = FXSYS_atoi(word); return new CPDF_Reference(pObjList, objnum); } } m_Pos = SavedPos; - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NUMBER; - } return CPDF_Number::Create(word); } if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_BOOLEAN; - } return CPDF_Boolean::Create(word == FX_BSTRC("true")); } if (word == FX_BSTRC("null")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NULL; - } return CPDF_Null::Create(); } if (word == FX_BSTRC("(")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_STRING; - } CFX_ByteString str = ReadString(); - if (m_pCryptoHandler) { + if (m_pCryptoHandler) m_pCryptoHandler->Decrypt(objnum, gennum, str); - } return CPDF_String::Create(str, FALSE); } if (word == FX_BSTRC("<")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_STRING; - } CFX_ByteString str = ReadHexString(); - if (m_pCryptoHandler) { + if (m_pCryptoHandler) m_pCryptoHandler->Decrypt(objnum, gennum, str); - } return CPDF_String::Create(str, TRUE); } if (word == FX_BSTRC("[")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_ARRAY; - } nonstd::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( CPDF_Array::Create()); while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum)) @@ -2286,19 +2267,17 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; } if (word[0] == '/') { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NAME; - } return CPDF_Name::Create( PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); } if (word == FX_BSTRC("<<")) { - if (bTypeOnly) { + if (bTypeOnly) return (CPDF_Object*)PDFOBJ_DICTIONARY; - } - if (pContext) { + if (pContext) pContext->m_DictStart = SavedPos; - } + nonstd::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( CPDF_Dictionary::Create()); while (1) { @@ -2354,7 +2333,6 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( } if (bTypeOnly) return (CPDF_Object*)PDFOBJ_INVALID; - return nullptr; } @@ -2991,7 +2969,7 @@ CPDF_DataAvail::~CPDF_DataAvail() { int32_t i = 0; int32_t iSize = m_arrayAcroforms.GetSize(); for (i = 0; i < iSize; ++i) { - ((CPDF_Object*)m_arrayAcroforms.GetAt(i))->Release(); + static_cast<CPDF_Object*>(m_arrayAcroforms.GetAt(i))->Release(); } } void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { @@ -3039,10 +3017,10 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, CFX_PtrArray new_obj_array; int32_t i = 0; for (i = 0; i < obj_array.GetSize(); i++) { - CPDF_Object* pObj = (CPDF_Object*)obj_array[i]; - if (!pObj) { + CPDF_Object* pObj = static_cast<CPDF_Object*>(obj_array[i]); + if (!pObj) continue; - } + int32_t type = pObj->GetType(); switch (type) { case PDFOBJ_ARRAY: { @@ -3110,7 +3088,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, if (count > 0) { int32_t iSize = new_obj_array.GetSize(); for (i = 0; i < iSize; ++i) { - CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i]; + CPDF_Object* pObj = static_cast<CPDF_Object*>(new_obj_array[i]); if (CPDF_Reference* pRef = pObj->AsReference()) { FX_DWORD dwNum = pRef->GetRefObjNum(); if (!m_objnum_array.Find(dwNum)) @@ -3156,7 +3134,7 @@ FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) { if (bRet) { int32_t iSize = m_arrayAcroforms.GetSize(); for (int32_t i = 0; i < iSize; ++i) { - ((CPDF_Object*)m_arrayAcroforms.GetAt(i))->Release(); + static_cast<CPDF_Object*>(m_arrayAcroforms.GetAt(i))->Release(); } m_arrayAcroforms.RemoveAll(); } else { @@ -3469,14 +3447,14 @@ FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { } FX_DWORD iPages = m_PagesArray.GetSize(); for (FX_DWORD i = 0; i < iPages; i++) { - CPDF_Object* pPages = (CPDF_Object*)m_PagesArray.GetAt(i); - if (!pPages) { + CPDF_Object* pPages = static_cast<CPDF_Object*>(m_PagesArray.GetAt(i)); + if (!pPages) continue; - } + if (!GetPageKids(m_pCurrentParser, pPages)) { pPages->Release(); while (++i < iPages) { - pPages = (CPDF_Object*)m_PagesArray.GetAt(i); + pPages = static_cast<CPDF_Object*>(m_PagesArray.GetAt(i)); pPages->Release(); } m_PagesArray.RemoveAll(); diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index 3192445d90..c155b947d9 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -1186,7 +1186,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, } else { CPDF_FileSpec filespec; filespec.SetFileName(pdf_path); - pMainDict->SetAt("F", (CPDF_Object*)filespec); + pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); } } CPDF_Array* pFields = CPDF_Array::Create(); diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 112149370b..467e9429c1 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -2878,14 +2878,14 @@ void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, int iCount = objects.GetSize(); for (int i = 0; i < iCount; i++) { - CPDF_Object* pObject = (CPDF_Object*)objects[i]; - if (pObject == NULL) + CPDF_Object* pObject = static_cast<CPDF_Object*>(objects[i]); + if (!pObject) continue; if (pObject->IsString()) { CFX_WideString csName = pObject->GetUnicodeText(); CPDF_FormField* pField = m_pInterForm->GetField(0, csName); - if (pField != NULL) + if (pField) fields.Add(pField); } else if (pObject->IsDictionary()) { if (m_pInterForm->IsValidFormField(pObject)) |