diff options
author | Wei Li <weili@chromium.org> | 2016-04-11 10:02:09 -0700 |
---|---|---|
committer | Wei Li <weili@chromium.org> | 2016-04-11 10:02:09 -0700 |
commit | e1aebd43b0c75133f94f8b141b33d12e2e715524 (patch) | |
tree | 863aded8c706db162eb3f69d6482100f9d61b842 /core/fpdfapi | |
parent | 2d4a4fc372159ac7562abea48498b6ab72c2f321 (diff) | |
download | pdfium-e1aebd43b0c75133f94f8b141b33d12e2e715524.tar.xz |
Use std::vector as internal storage for CPDF_Array
Replace the usage of CFX_ArrayTemplate inside CPDF_Array, which
has non-standard APIs such as GetSize() returns int.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1867183002 .
Diffstat (limited to 'core/fpdfapi')
18 files changed, 119 insertions, 129 deletions
diff --git a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp index a484edd6b9..28cbdfc02e 100644 --- a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp @@ -129,11 +129,10 @@ void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { CFX_ByteTextBuf buf; if (CPDF_Array* pArray = pContent->AsArray()) { - int iCount = pArray->GetCount(); + size_t iCount = pArray->GetCount(); CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); - int size = 0; - int i = 0; - for (i = 0; i < iCount; ++i) { + size_t size = 0; + for (size_t i = 0; i < iCount; ++i) { pContent = pArray->GetObjectAt(i); CPDF_Stream* pStream = ToStream(pContent); if (!pStream) @@ -146,7 +145,7 @@ void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { } int pos = 0; uint8_t* pBuf = FX_Alloc(uint8_t, size); - for (i = 0; i < iCount; ++i) { + for (size_t i = 0; i < iCount; ++i) { FXSYS_memcpy(pBuf + pos, pContentArray[i]->GetData(), pContentArray[i]->GetSize()); pos += pContentArray[i]->GetSize() + 1; diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index a337cf59ff..c2e556c3a7 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -96,7 +96,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, } offset += 1; const CPDF_Array* p = pObj->AsArray(); - for (uint32_t i = 0; i < p->GetCount(); i++) { + for (size_t i = 0; i < p->GetCount(); i++) { CPDF_Object* pElement = p->GetObjectAt(i); if (pElement->GetObjNum()) { if (pFile->AppendString(" ") < 0) { @@ -1199,7 +1199,7 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, } m_Offset += 1; const CPDF_Array* p = pObj->AsArray(); - for (uint32_t i = 0; i < p->GetCount(); i++) { + for (size_t i = 0; i < p->GetCount(); i++) { CPDF_Object* pElement = p->GetObjectAt(i); if (pElement->GetObjNum()) { if (m_File.AppendString(" ") < 0) { diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp index 04ab9ea863..379e75938e 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp @@ -1033,8 +1033,7 @@ static int InsertDeletePDFPage(CPDF_Document* pDoc, if (!pKidList) { return -1; } - int nKids = pKidList->GetCount(); - for (int i = 0; i < nKids; i++) { + for (size_t i = 0; i < pKidList->GetCount(); i++) { CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (pKid->GetStringBy("Type") == "Page") { if (nPagesToGo == 0) { diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp index 3329f5c577..034f6f6ece 100644 --- a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp @@ -817,8 +817,7 @@ void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, int iCurElement = 0; int first_code = 0; int last_code = 0; - uint32_t count = pArray->GetCount(); - for (uint32_t i = 0; i < count; i++) { + for (size_t i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pObj = pArray->GetDirectObjectAt(i); if (!pObj) continue; @@ -827,8 +826,7 @@ void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, if (width_status != 1) return; - uint32_t count = pArray->GetCount(); - for (uint32_t j = 0; j < count; j += nElements) { + for (size_t j = 0; j < pArray->GetCount(); j += nElements) { result.Add(first_code); result.Add(first_code); for (int k = 0; k < nElements; k++) { diff --git a/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp b/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp index 0b4199aac0..b367184e2e 100644 --- a/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp @@ -111,7 +111,6 @@ FX_BOOL CPDF_SimpleFont::LoadCommon() { LoadFontDescriptor(pFontDesc); } CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths"); - int width_start = 0, width_end = -1; m_bUseFontWidth = TRUE; if (pWidthArray) { m_bUseFontWidth = FALSE; @@ -121,19 +120,15 @@ FX_BOOL CPDF_SimpleFont::LoadCommon() { m_CharWidth[i] = MissingWidth; } } - width_start = m_pFontDict->GetIntegerBy("FirstChar", 0); - width_end = m_pFontDict->GetIntegerBy("LastChar", 0); - if (width_start >= 0 && width_start <= 255) { - if (width_end <= 0 || - width_end >= width_start + (int)pWidthArray->GetCount()) { + size_t width_start = m_pFontDict->GetIntegerBy("FirstChar", 0); + size_t width_end = m_pFontDict->GetIntegerBy("LastChar", 0); + if (width_start <= 255) { + if (width_end == 0 || width_end >= width_start + pWidthArray->GetCount()) width_end = width_start + pWidthArray->GetCount() - 1; - } - if (width_end > 255) { + if (width_end > 255) width_end = 255; - } - for (int i = width_start; i <= width_end; i++) { + for (size_t i = width_start; i <= width_end; i++) m_CharWidth[i] = pWidthArray->GetIntegerAt(i - width_start); - } } } if (m_pFontFile) { diff --git a/core/fpdfapi/fpdf_font/cpdf_type3font.cpp b/core/fpdfapi/fpdf_font/cpdf_type3font.cpp index 9f37d4adee..92f5102cdb 100644 --- a/core/fpdfapi/fpdf_font/cpdf_type3font.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_type3font.cpp @@ -57,14 +57,12 @@ FX_BOOL CPDF_Type3Font::Load() { int StartChar = m_pFontDict->GetIntegerBy("FirstChar"); CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths"); if (pWidthArray && (StartChar >= 0 && StartChar < 256)) { - uint32_t count = pWidthArray->GetCount(); - if (count > 256) { + size_t count = pWidthArray->GetCount(); + if (count > 256) count = 256; - } - if (StartChar + count > 256) { + if (StartChar + count > 256) count = 256 - StartChar; - } - for (uint32_t i = 0; i < count; i++) { + for (size_t i = 0; i < count; i++) { m_CharWidthL[StartChar + i] = FXSYS_round(pWidthArray->GetNumberAt(i) * xscale * 1000); } diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp index f2d637f888..4fe5283251 100644 --- a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp @@ -46,10 +46,9 @@ void CPDF_AllStates::SetLineDash(CPDF_Array* pArray, FX_FLOAT scale) { CFX_GraphStateData* pData = m_GraphState.GetModify(); pData->m_DashPhase = phase * scale; - pData->SetDashCount(pArray->GetCount()); - for (uint32_t i = 0; i < pArray->GetCount(); i++) { + pData->SetDashCount(static_cast<int>(pArray->GetCount())); + for (size_t i = 0; i < pArray->GetCount(); i++) pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale; - } } void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp index f637a4463c..457de9667a 100644 --- a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp @@ -48,7 +48,7 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, } CPDF_ShadingPattern::~CPDF_ShadingPattern() { - for (int i = 0; i < m_nFuncs; ++i) + for (size_t i = 0; i < m_nFuncs; ++i) delete m_pFunctions[i]; CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr; @@ -66,16 +66,16 @@ FX_BOOL CPDF_ShadingPattern::Load() { return FALSE; if (m_nFuncs) { - for (int i = 0; i < m_nFuncs; i++) + for (size_t i = 0; i < m_nFuncs; i++) delete m_pFunctions[i]; m_nFuncs = 0; } CPDF_Object* pFunc = pShadingDict->GetDirectObjectBy("Function"); if (pFunc) { if (CPDF_Array* pArray = pFunc->AsArray()) { - m_nFuncs = std::min<int>(pArray->GetCount(), 4); + m_nFuncs = std::min<size_t>(pArray->GetCount(), 4); - for (int i = 0; i < m_nFuncs; i++) + for (size_t i = 0; i < m_nFuncs; i++) m_pFunctions[i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i)); } else { m_pFunctions[0] = CPDF_Function::Load(pFunc); diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h index 55a249a1bc..c9bbd07d2e 100644 --- a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h +++ b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h @@ -56,7 +56,7 @@ class CPDF_ShadingPattern : public CPDF_Pattern { CPDF_CountedColorSpace* m_pCountedCS; CPDF_Function* m_pFunctions[4]; - int m_nFuncs; + size_t m_nFuncs; }; #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_SHADINGPATTERN_H_ diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 21edc9e0cd..ba2901df24 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1418,14 +1418,14 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { if (!pArray) { return; } - int n = pArray->GetCount(); - int nsegs = 0; - for (int i = 0; i < n; i++) { + size_t n = pArray->GetCount(); + size_t nsegs = 0; + for (size_t i = 0; i < n; i++) { if (pArray->GetDirectObjectAt(i)->IsString()) nsegs++; } if (nsegs == 0) { - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { m_pCurStates->m_TextX -= (pArray->GetNumberAt(i) * m_pCurStates->m_TextState.GetFontSize()) / 1000; @@ -1434,9 +1434,9 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { } CFX_ByteString* pStrs = new CFX_ByteString[nsegs]; FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs); - int iSegment = 0; + size_t iSegment = 0; FX_FLOAT fInitKerning = 0; - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { CPDF_Object* pObj = pArray->GetDirectObjectAt(i); if (pObj->IsString()) { CFX_ByteString str = pObj->GetString(); @@ -1801,7 +1801,7 @@ void PDF_ReplaceAbbr(CPDF_Object* pObj) { } case CPDF_Object::ARRAY: { CPDF_Array* pArray = pObj->AsArray(); - for (uint32_t i = 0; i < pArray->GetCount(); i++) { + for (size_t i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetObjectAt(i); if (pElement->IsName()) { CFX_ByteString name = pElement->GetString(); diff --git a/core/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/fpdfapi/fpdf_parser/cpdf_array.cpp index 964ba64236..e2279c8e1d 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_array.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_array.cpp @@ -15,11 +15,9 @@ CPDF_Array::CPDF_Array() {} CPDF_Array::~CPDF_Array() { - int size = m_Objects.GetSize(); - CPDF_Object** pList = m_Objects.GetData(); - for (int i = 0; i < size; i++) { - if (pList[i]) - pList[i]->Release(); + for (auto& it : m_Objects) { + if (it) + it->Release(); } } @@ -48,15 +46,15 @@ const CPDF_Array* CPDF_Array::AsArray() const { CPDF_Object* CPDF_Array::Clone(FX_BOOL bDirect) const { CPDF_Array* pCopy = new CPDF_Array(); for (size_t i = 0; i < GetCount(); i++) { - CPDF_Object* value = m_Objects.GetAt(i); - pCopy->m_Objects.Add(value->Clone(bDirect)); + CPDF_Object* value = m_Objects.at(i); + pCopy->m_Objects.push_back(value->Clone(bDirect)); } return pCopy; } CFX_FloatRect CPDF_Array::GetRect() { CFX_FloatRect rect; - if (!IsArray() || m_Objects.GetSize() != 4) + if (!IsArray() || m_Objects.size() != 4) return rect; rect.left = GetNumberAt(0); @@ -68,7 +66,7 @@ CFX_FloatRect CPDF_Array::GetRect() { CFX_Matrix CPDF_Array::GetMatrix() { CFX_Matrix matrix; - if (!IsArray() || m_Objects.GetSize() != 6) + if (!IsArray() || m_Objects.size() != 6) return matrix; matrix.Set(GetNumberAt(0), GetNumberAt(1), GetNumberAt(2), GetNumberAt(3), @@ -76,43 +74,43 @@ CFX_Matrix CPDF_Array::GetMatrix() { return matrix; } -CPDF_Object* CPDF_Array::GetObjectAt(uint32_t i) const { - if (i >= (uint32_t)m_Objects.GetSize()) +CPDF_Object* CPDF_Array::GetObjectAt(size_t i) const { + if (i >= m_Objects.size()) return nullptr; - return m_Objects.GetAt(i); + return m_Objects.at(i); } -CPDF_Object* CPDF_Array::GetDirectObjectAt(uint32_t i) const { - if (i >= (uint32_t)m_Objects.GetSize()) +CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) const { + if (i >= m_Objects.size()) return nullptr; - return m_Objects.GetAt(i)->GetDirect(); + return m_Objects.at(i)->GetDirect(); } -CFX_ByteString CPDF_Array::GetStringAt(uint32_t i) const { - if (i >= (uint32_t)m_Objects.GetSize()) +CFX_ByteString CPDF_Array::GetStringAt(size_t i) const { + if (i >= m_Objects.size()) return CFX_ByteString(); - return m_Objects.GetAt(i)->GetString(); + return m_Objects.at(i)->GetString(); } -CFX_ByteStringC CPDF_Array::GetConstStringAt(uint32_t i) const { - if (i >= (uint32_t)m_Objects.GetSize()) +CFX_ByteStringC CPDF_Array::GetConstStringAt(size_t i) const { + if (i >= m_Objects.size()) return CFX_ByteStringC(); - return m_Objects.GetAt(i)->GetConstString(); + return m_Objects.at(i)->GetConstString(); } -int CPDF_Array::GetIntegerAt(uint32_t i) const { - if (i >= (uint32_t)m_Objects.GetSize()) +int CPDF_Array::GetIntegerAt(size_t i) const { + if (i >= m_Objects.size()) return 0; - return m_Objects.GetAt(i)->GetInteger(); + return m_Objects.at(i)->GetInteger(); } -FX_FLOAT CPDF_Array::GetNumberAt(uint32_t i) const { - if (i >= (uint32_t)m_Objects.GetSize()) +FX_FLOAT CPDF_Array::GetNumberAt(size_t i) const { + if (i >= m_Objects.size()) return 0; - return m_Objects.GetAt(i)->GetNumber(); + return m_Objects.at(i)->GetNumber(); } -CPDF_Dictionary* CPDF_Array::GetDictAt(uint32_t i) const { +CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const { CPDF_Object* p = GetDirectObjectAt(i); if (!p) return NULL; @@ -123,52 +121,59 @@ CPDF_Dictionary* CPDF_Array::GetDictAt(uint32_t i) const { return NULL; } -CPDF_Stream* CPDF_Array::GetStreamAt(uint32_t i) const { +CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) const { return ToStream(GetDirectObjectAt(i)); } -CPDF_Array* CPDF_Array::GetArrayAt(uint32_t i) const { +CPDF_Array* CPDF_Array::GetArrayAt(size_t i) const { return ToArray(GetDirectObjectAt(i)); } -void CPDF_Array::RemoveAt(uint32_t i, uint32_t nCount) { - if (i >= (uint32_t)m_Objects.GetSize()) +void CPDF_Array::RemoveAt(size_t i, size_t nCount) { + if (i >= m_Objects.size()) return; - if (nCount <= 0 || nCount > m_Objects.GetSize() - i) + if (nCount <= 0 || nCount > m_Objects.size() - i) return; - for (uint32_t j = 0; j < nCount; ++j) { - if (CPDF_Object* p = m_Objects.GetAt(i + j)) + for (size_t j = 0; j < nCount; ++j) { + if (CPDF_Object* p = m_Objects.at(i + j)) p->Release(); } - m_Objects.RemoveAt(i, nCount); + m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount); } -void CPDF_Array::SetAt(uint32_t i, +void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) { ASSERT(IsArray()); - ASSERT(i < (uint32_t)m_Objects.GetSize()); - if (i >= (uint32_t)m_Objects.GetSize()) + ASSERT(i < m_Objects.size()); + if (i >= m_Objects.size()) return; - if (CPDF_Object* pOld = m_Objects.GetAt(i)) + if (CPDF_Object* pOld = m_Objects.at(i)) pOld->Release(); if (pObj->GetObjNum()) { ASSERT(pObjs); pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); } - m_Objects.SetAt(i, pObj); + m_Objects[i] = pObj; } -void CPDF_Array::InsertAt(uint32_t index, +void CPDF_Array::InsertAt(size_t index, CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) { if (pObj->GetObjNum()) { ASSERT(pObjs); pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); } - m_Objects.InsertAt(index, pObj); + if (index >= m_Objects.size()) { + // Allocate space first. + m_Objects.resize(index + 1, nullptr); + m_Objects[index] = pObj; + } else { + // Directly insert. + m_Objects.insert(m_Objects.begin() + index, pObj); + } } void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) { @@ -176,7 +181,7 @@ void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) { ASSERT(pObjs); pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); } - m_Objects.Add(pObj); + m_Objects.push_back(pObj); } void CPDF_Array::AddName(const CFX_ByteString& str) { diff --git a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp index 68f8b88557..e08e913f74 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp @@ -142,8 +142,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail( uint32_t count = 0; CFX_ArrayTemplate<CPDF_Object*> new_obj_array; - int32_t i = 0; - for (i = 0; i < obj_array.GetSize(); i++) { + for (int i = 0; i < obj_array.GetSize(); i++) { CPDF_Object* pObj = obj_array[i]; if (!pObj) continue; @@ -152,7 +151,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail( switch (type) { case CPDF_Object::ARRAY: { CPDF_Array* pArray = pObj->GetArray(); - for (uint32_t k = 0; k < pArray->GetCount(); ++k) + for (size_t k = 0; k < pArray->GetCount(); ++k) new_obj_array.Add(pArray->GetObjectAt(k)); } break; case CPDF_Object::STREAM: @@ -193,8 +192,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail( } if (count > 0) { - int32_t iSize = new_obj_array.GetSize(); - for (i = 0; i < iSize; ++i) { + for (int i = 0; i < new_obj_array.GetSize(); ++i) { CPDF_Object* pObj = new_obj_array[i]; if (CPDF_Reference* pRef = pObj->AsReference()) { uint32_t dwNum = pRef->GetRefObjNum(); @@ -513,8 +511,7 @@ FX_BOOL CPDF_DataAvail::CheckPage(IPDF_DataAvail::DownloadHints* pHints) { if (pObj->IsArray()) { CPDF_Array* pArray = pObj->GetArray(); if (pArray) { - int32_t iSize = pArray->GetCount(); - for (int32_t j = 0; j < iSize; ++j) { + for (size_t j = 0; j < pArray->GetCount(); ++j) { if (CPDF_Reference* pRef = ToReference(pArray->GetObjectAt(j))) UnavailObjList.Add(pRef->GetRefObjNum()); } @@ -583,7 +580,7 @@ FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { break; case CPDF_Object::ARRAY: { CPDF_Array* pKidsArray = pKids->AsArray(); - for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) { + for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i))) m_PageObjList.Add(pRef->GetRefObjNum()); } @@ -1285,7 +1282,7 @@ FX_BOOL CPDF_DataAvail::CheckArrayPageNode( } pPageNode->m_type = PDF_PAGENODE_PAGES; - for (uint32_t i = 0; i < pArray->GetCount(); ++i) { + for (size_t i = 0; i < pArray->GetCount(); ++i) { CPDF_Reference* pKid = ToReference(pArray->GetObjectAt(i)); if (!pKid) continue; @@ -1348,7 +1345,7 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode( } break; case CPDF_Object::ARRAY: { CPDF_Array* pKidsArray = pKids->AsArray(); - for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) { + for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { CPDF_Reference* pKid = ToReference(pKidsArray->GetObjectAt(i)); if (!pKid) continue; diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp index d48edd056b..808a468016 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -32,7 +32,7 @@ int CountPages(CPDF_Dictionary* pPages, return 0; } count = 0; - for (uint32_t i = 0; i < pKidList->GetCount(); i++) { + for (size_t i = 0; i < pKidList->GetCount(); i++) { CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (!pKid || pdfium::ContainsKey(*visited_pages, pKid)) { continue; @@ -155,8 +155,7 @@ CPDF_Dictionary* CPDF_Document::_FindPDFPage(CPDF_Dictionary* pPages, if (level >= FX_MAX_PAGE_LEVEL) { return NULL; } - int nKids = pKidList->GetCount(); - for (int i = 0; i < nKids; i++) { + for (size_t i = 0; i < pKidList->GetCount(); i++) { CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (!pKid) { nPagesToGo--; @@ -228,23 +227,23 @@ int CPDF_Document::_FindPageIndex(CPDF_Dictionary* pNode, if (level >= FX_MAX_PAGE_LEVEL) { return -1; } - uint32_t count = pNode->GetIntegerBy("Count"); + size_t count = pNode->GetIntegerBy("Count"); if (count <= skip_count) { skip_count -= count; index += count; return -1; } if (count && count == pKidList->GetCount()) { - for (uint32_t i = 0; i < count; i++) { + for (size_t i = 0; i < count; i++) { if (CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i))) { if (pKid->GetRefObjNum() == objnum) { m_PageList.SetAt(index + i, objnum); - return index + i; + return static_cast<int>(index + i); } } } } - for (uint32_t i = 0; i < pKidList->GetCount(); i++) { + for (size_t i = 0; i < pKidList->GetCount(); i++) { CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (!pKid) { continue; diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp index 4ba43678b8..97b03f046c 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -988,8 +988,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { std::vector<std::pair<int32_t, int32_t>> arrIndex; CPDF_Array* pArray = pStream->GetDict()->GetArrayBy("Index"); if (pArray) { - uint32_t nPairSize = pArray->GetCount() / 2; - for (uint32_t i = 0; i < nPairSize; i++) { + for (size_t i = 0; i < pArray->GetCount() / 2; i++) { CPDF_Object* pStartNumObj = pArray->GetObjectAt(i * 2); CPDF_Object* pCountObj = pArray->GetObjectAt(i * 2 + 1); @@ -1013,7 +1012,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { CFX_ArrayTemplate<uint32_t> WidthArray; FX_SAFE_UINT32 dwAccWidth = 0; - for (uint32_t i = 0; i < pArray->GetCount(); i++) { + for (size_t i = 0; i < pArray->GetCount(); i++) { WidthArray.Add(pArray->GetIntegerAt(i)); dwAccWidth += WidthArray[i]; } diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 0a7729fe4b..11d9e524ee 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -349,7 +349,7 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf, if (!pParamsArray) pParams = nullptr; - for (uint32_t i = 0; i < pDecoders->GetCount(); i++) { + for (size_t i = 0; i < pDecoders->GetCount(); i++) { DecoderList.push_back(pDecoders->GetConstStringAt(i)); ParamList.Add(pParams ? pParamsArray->GetDictAt(i) : nullptr); } diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp index 31e7388bd7..bfd0de44b6 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp @@ -179,7 +179,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { case CPDF_Object::ARRAY: { const CPDF_Array* p = pObj->AsArray(); buf << "["; - for (uint32_t i = 0; i < p->GetCount(); i++) { + for (size_t i = 0; i < p->GetCount(); i++) { CPDF_Object* pElement = p->GetObjectAt(i); if (pElement->GetObjNum()) { buf << " " << pElement->GetObjNum() << " 0 R"; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_array.h b/core/fpdfapi/fpdf_parser/include/cpdf_array.h index b964f4955b..506a6bc338 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_array.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_array.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_ #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_ +#include <vector> + #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" #include "core/fxcrt/include/fx_basic.h" @@ -24,27 +26,27 @@ class CPDF_Array : public CPDF_Object { CPDF_Array* AsArray() override; const CPDF_Array* AsArray() const override; - uint32_t GetCount() const { return m_Objects.GetSize(); } - CPDF_Object* GetObjectAt(uint32_t index) const; - CPDF_Object* GetDirectObjectAt(uint32_t index) const; - CFX_ByteString GetStringAt(uint32_t index) const; - CFX_ByteStringC GetConstStringAt(uint32_t index) const; - int GetIntegerAt(uint32_t index) const; - FX_FLOAT GetNumberAt(uint32_t index) const; - CPDF_Dictionary* GetDictAt(uint32_t index) const; - CPDF_Stream* GetStreamAt(uint32_t index) const; - CPDF_Array* GetArrayAt(uint32_t index) const; - FX_FLOAT GetFloatAt(uint32_t index) const { return GetNumberAt(index); } + size_t GetCount() const { return m_Objects.size(); } + CPDF_Object* GetObjectAt(size_t index) const; + CPDF_Object* GetDirectObjectAt(size_t index) const; + CFX_ByteString GetStringAt(size_t index) const; + CFX_ByteStringC GetConstStringAt(size_t index) const; + int GetIntegerAt(size_t index) const; + FX_FLOAT GetNumberAt(size_t index) const; + CPDF_Dictionary* GetDictAt(size_t index) const; + CPDF_Stream* GetStreamAt(size_t index) const; + CPDF_Array* GetArrayAt(size_t index) const; + FX_FLOAT GetFloatAt(size_t index) const { return GetNumberAt(index); } CFX_Matrix GetMatrix(); CFX_FloatRect GetRect(); - void SetAt(uint32_t index, + void SetAt(size_t index, CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs = nullptr); - void InsertAt(uint32_t index, + void InsertAt(size_t index, CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs = nullptr); - void RemoveAt(uint32_t index, uint32_t nCount = 1); + void RemoveAt(size_t index, size_t nCount = 1); void Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs = nullptr); void AddNumber(FX_FLOAT f); @@ -59,7 +61,7 @@ class CPDF_Array : public CPDF_Object { protected: ~CPDF_Array() override; - CFX_ArrayTemplate<CPDF_Object*> m_Objects; + std::vector<CPDF_Object*> m_Objects; }; #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_ diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index efb55d928f..6aee8e75b6 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -417,7 +417,7 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { m_Flags |= FXRENDER_IMAGE_LOSSY; } } else if (CPDF_Array* pArray = pFilters->AsArray()) { - for (uint32_t i = 0; i < pArray->GetCount(); i++) { + for (size_t i = 0; i < pArray->GetCount(); i++) { CFX_ByteStringC bsDecodeType = pArray->GetConstStringAt(i); if (bsDecodeType == "DCTDecode" || bsDecodeType == "JPXDecode") { m_Flags |= FXRENDER_IMAGE_LOSSY; @@ -937,8 +937,8 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, return NULL; } FXSYS_memset(pFloats, 0, num_floats.ValueOrDie()); - int count = pBC->GetCount() > 8 ? 8 : pBC->GetCount(); - for (int i = 0; i < count; i++) { + size_t count = pBC->GetCount() > 8 ? 8 : pBC->GetCount(); + for (size_t i = 0; i < count; i++) { pFloats[i] = pBC->GetNumberAt(i); } pCS->GetRGB(pFloats, R, G, B); |