diff options
Diffstat (limited to 'core/fpdfapi')
20 files changed, 149 insertions, 174 deletions
diff --git a/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp b/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp index 3cd6106e1c..9248efb718 100644 --- a/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp +++ b/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp @@ -18,11 +18,10 @@ void FPDFAPI_FindEmbeddedCMap(const char* name, CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); const FXCMAP_CMap* pCMaps = pFontGlobals->m_EmbeddedCharsets[charset].m_pMapList; - int nCMaps = pFontGlobals->m_EmbeddedCharsets[charset].m_Count; - for (int i = 0; i < nCMaps; i++) { - if (FXSYS_strcmp(name, pCMaps[i].m_Name)) { + for (uint32_t i = 0; i < pFontGlobals->m_EmbeddedCharsets[charset].m_Count; + i++) { + if (FXSYS_strcmp(name, pCMaps[i].m_Name)) continue; - } pMap = &pCMaps[i]; break; } diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index 0f087d980a..21934d35c4 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -1410,7 +1410,7 @@ void CPDF_Creator::InitNewObjNumOffsets() { for (const auto& pair : m_pDocument->m_IndirectObjs) { const uint32_t objnum = pair.first; const CPDF_Object* pObj = pair.second; - if (pObj->GetObjNum() == -1) + if (pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) continue; if (bIncremental) { if (!pObj->IsModified()) diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp index de119b75d1..3329f5c577 100644 --- a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp @@ -155,13 +155,12 @@ uint32_t EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap, if (!pCodes) return 0; - int nCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count; - for (int i = 0; i < nCodes; ++i) { + for (uint32_t i = 0; i < pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count; + ++i) { if (pCodes[i] == unicode) { uint32_t CharCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i); - if (CharCode != 0) { + if (CharCode != 0) return CharCode; - } } } return 0; diff --git a/core/fpdfapi/fpdf_font/font_int.h b/core/fpdfapi/fpdf_font/font_int.h index 3ee4068d7d..fc69b0cbd9 100644 --- a/core/fpdfapi/fpdf_font/font_int.h +++ b/core/fpdfapi/fpdf_font/font_int.h @@ -48,8 +48,8 @@ class CFX_StockFontArray { ~CFX_StockFontArray(); // Takes ownership of |pFont|. - void SetFont(int index, CPDF_Font* pFont); - CPDF_Font* GetFont(int index) const; + void SetFont(uint32_t index, CPDF_Font* pFont); + CPDF_Font* GetFont(uint32_t index) const; private: std::unique_ptr<CPDF_Font> m_StockFonts[14]; @@ -61,19 +61,19 @@ class CPDF_FontGlobals { ~CPDF_FontGlobals(); void Clear(CPDF_Document* pDoc); - CPDF_Font* Find(CPDF_Document* pDoc, int index); + CPDF_Font* Find(CPDF_Document* pDoc, uint32_t index); // Takes ownership of |pFont|. - void Set(CPDF_Document* key, int index, CPDF_Font* pFont); + void Set(CPDF_Document* key, uint32_t index, CPDF_Font* pFont); CPDF_CMapManager m_CMapManager; struct { const struct FXCMAP_CMap* m_pMapList; - int m_Count; + uint32_t m_Count; } m_EmbeddedCharsets[CIDSET_NUM_SETS]; struct { const uint16_t* m_pMap; - int m_Count; + uint32_t m_Count; } m_EmbeddedToUnicodes[CIDSET_NUM_SETS]; private: diff --git a/core/fpdfapi/fpdf_font/fpdf_font.cpp b/core/fpdfapi/fpdf_font/fpdf_font.cpp index b0659b4a52..ce2390ec08 100644 --- a/core/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/fpdfapi/fpdf_font/fpdf_font.cpp @@ -45,14 +45,14 @@ CFX_StockFontArray::~CFX_StockFontArray() { } } -CPDF_Font* CFX_StockFontArray::GetFont(int index) const { - if (index < 0 || index >= FX_ArraySize(m_StockFonts)) +CPDF_Font* CFX_StockFontArray::GetFont(uint32_t index) const { + if (index >= FX_ArraySize(m_StockFonts)) return nullptr; return m_StockFonts[index].get(); } -void CFX_StockFontArray::SetFont(int index, CPDF_Font* font) { - if (index < 0 || index >= FX_ArraySize(m_StockFonts)) +void CFX_StockFontArray::SetFont(uint32_t index, CPDF_Font* font) { + if (index >= FX_ArraySize(m_StockFonts)) return; m_StockFonts[index].reset(font); } @@ -64,14 +64,16 @@ CPDF_FontGlobals::CPDF_FontGlobals() { CPDF_FontGlobals::~CPDF_FontGlobals() {} -CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, int index) { +CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, uint32_t index) { auto it = m_StockMap.find(pDoc); if (it == m_StockMap.end()) return nullptr; return it->second ? it->second->GetFont(index) : nullptr; } -void CPDF_FontGlobals::Set(CPDF_Document* pDoc, int index, CPDF_Font* pFont) { +void CPDF_FontGlobals::Set(CPDF_Document* pDoc, + uint32_t index, + CPDF_Font* pFont) { if (!pdfium::ContainsKey(m_StockMap, pDoc)) m_StockMap[pDoc].reset(new CFX_StockFontArray); m_StockMap[pDoc]->SetFont(index, pFont); @@ -121,7 +123,7 @@ CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) { uint32_t CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { for (const auto& pair : m_Map) { - if (pair.second == unicode) + if (pair.second == static_cast<uint32_t>(unicode)) return pair.first; } return 0; diff --git a/core/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp b/core/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp index c12b9c5eee..ccf49ee46a 100644 --- a/core/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp +++ b/core/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp @@ -18,16 +18,16 @@ bool uint_ranges_equal(uint8_t* a, uint8_t* b, size_t count) { } // namespace TEST(fpdf_font_cid, CMap_GetCode) { - EXPECT_EQ(0, CPDF_CMapParser::CMap_GetCode("")); - EXPECT_EQ(0, CPDF_CMapParser::CMap_GetCode("<")); - EXPECT_EQ(194, CPDF_CMapParser::CMap_GetCode("<c2")); - EXPECT_EQ(162, CPDF_CMapParser::CMap_GetCode("<A2")); - EXPECT_EQ(2802, CPDF_CMapParser::CMap_GetCode("<Af2")); - EXPECT_EQ(162, CPDF_CMapParser::CMap_GetCode("<A2z")); + EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("")); + EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<")); + EXPECT_EQ(194u, CPDF_CMapParser::CMap_GetCode("<c2")); + EXPECT_EQ(162u, CPDF_CMapParser::CMap_GetCode("<A2")); + EXPECT_EQ(2802u, CPDF_CMapParser::CMap_GetCode("<Af2")); + EXPECT_EQ(162u, CPDF_CMapParser::CMap_GetCode("<A2z")); - EXPECT_EQ(12, CPDF_CMapParser::CMap_GetCode("12")); - EXPECT_EQ(12, CPDF_CMapParser::CMap_GetCode("12d")); - EXPECT_EQ(128, CPDF_CMapParser::CMap_GetCode("128")); + EXPECT_EQ(12u, CPDF_CMapParser::CMap_GetCode("12")); + EXPECT_EQ(12u, CPDF_CMapParser::CMap_GetCode("12d")); + EXPECT_EQ(128u, CPDF_CMapParser::CMap_GetCode("128")); } TEST(fpdf_font_cid, CMap_GetCodeRange) { diff --git a/core/fpdfapi/fpdf_font/fpdf_font_unittest.cpp b/core/fpdfapi/fpdf_font/fpdf_font_unittest.cpp index dd2119e0cf..0c5ad8a66a 100644 --- a/core/fpdfapi/fpdf_font/fpdf_font_unittest.cpp +++ b/core/fpdfapi/fpdf_font/fpdf_font_unittest.cpp @@ -6,12 +6,12 @@ #include "testing/gtest/include/gtest/gtest.h" TEST(fpdf_font, StringToCode) { - EXPECT_EQ(0, CPDF_ToUnicodeMap::StringToCode("")); - EXPECT_EQ(194, CPDF_ToUnicodeMap::StringToCode("<c2")); - EXPECT_EQ(162, CPDF_ToUnicodeMap::StringToCode("<A2")); - EXPECT_EQ(2802, CPDF_ToUnicodeMap::StringToCode("<Af2")); - EXPECT_EQ(12, CPDF_ToUnicodeMap::StringToCode("12")); - EXPECT_EQ(128, CPDF_ToUnicodeMap::StringToCode("128")); + EXPECT_EQ(0u, CPDF_ToUnicodeMap::StringToCode("")); + EXPECT_EQ(194u, CPDF_ToUnicodeMap::StringToCode("<c2")); + EXPECT_EQ(162u, CPDF_ToUnicodeMap::StringToCode("<A2")); + EXPECT_EQ(2802u, CPDF_ToUnicodeMap::StringToCode("<Af2")); + EXPECT_EQ(12u, CPDF_ToUnicodeMap::StringToCode("12")); + EXPECT_EQ(128u, CPDF_ToUnicodeMap::StringToCode("128")); } TEST(fpdf_font, StringToWideString) { diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp index 7f80c82a03..5c73b28e67 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp @@ -12,14 +12,14 @@ void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, - int nValues) { + uint32_t nValues) { CPDF_ColorStateData* pData = GetModify(); SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues); } void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, - int nValues) { + uint32_t nValues) { CPDF_ColorStateData* pData = GetModify(); SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues); } @@ -28,7 +28,7 @@ void CPDF_ColorState::SetColor(CPDF_Color& color, uint32_t& rgb, CPDF_ColorSpace* pCS, FX_FLOAT* pValue, - int nValues) { + uint32_t nValues) { if (pCS) { color.SetColorSpace(pCS); } else if (color.IsNull()) { @@ -44,7 +44,7 @@ void CPDF_ColorState::SetColor(CPDF_Color& color, void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, FX_FLOAT* pValue, - int nValues) { + uint32_t nValues) { CPDF_ColorStateData* pData = GetModify(); pData->m_FillColor.SetValue(pPattern, pValue, nValues); int R, G, B; @@ -59,7 +59,7 @@ void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, FX_FLOAT* pValue, - int nValues) { + uint32_t nValues) { CPDF_ColorStateData* pData = GetModify(); pData->m_StrokeColor.SetValue(pPattern, pValue, nValues); int R, G, B; diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.h b/core/fpdfapi/fpdf_page/cpdf_colorstate.h index 2b27d07702..da4c49d3c9 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstate.h +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.h @@ -25,17 +25,21 @@ class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> { return m_pObject ? &m_pObject->m_StrokeColor : nullptr; } - void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); - void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); - void SetFillPattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); - void SetStrokePattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); + void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues); + void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues); + void SetFillPattern(CPDF_Pattern* pattern, + FX_FLOAT* pValue, + uint32_t nValues); + void SetStrokePattern(CPDF_Pattern* pattern, + FX_FLOAT* pValue, + uint32_t nValues); private: void SetColor(CPDF_Color& color, uint32_t& rgb, CPDF_ColorSpace* pCS, FX_FLOAT* pValue, - int nValues); + uint32_t nValues); }; #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp index 4ca9acbea7..f637a4463c 100644 --- a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp @@ -43,7 +43,7 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, if (parentMatrix) m_Pattern2Form.Concat(*parentMatrix); } - for (int i = 0; i < FX_ArraySize(m_pFunctions); ++i) + for (size_t i = 0; i < FX_ArraySize(m_pFunctions); ++i) m_pFunctions[i] = nullptr; } diff --git a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp index 7d396ed032..ebd6811da8 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp @@ -116,7 +116,7 @@ class CPDF_PSProc { std::vector<std::unique_ptr<CPDF_PSOP>> m_Operators; }; -const size_t PSENGINE_STACKSIZE = 100; +const uint32_t PSENGINE_STACKSIZE = 100; class CPDF_PSEngine { public: @@ -130,11 +130,11 @@ class CPDF_PSEngine { void Push(FX_FLOAT value); void Push(int value) { Push((FX_FLOAT)value); } FX_FLOAT Pop(); - int GetStackSize() const { return m_StackCount; } + uint32_t GetStackSize() const { return m_StackCount; } private: FX_FLOAT m_Stack[PSENGINE_STACKSIZE]; - int m_StackCount; + uint32_t m_StackCount; CPDF_PSProc m_MainProc; }; @@ -430,49 +430,42 @@ FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) { Push(d1); break; case PSOP_COPY: { - int n = (int)Pop(); - if (n < 0 || n > PSENGINE_STACKSIZE || - m_StackCount + n > PSENGINE_STACKSIZE || n > m_StackCount) { + int n = static_cast<int>(Pop()); + if (n < 0 || m_StackCount + n > PSENGINE_STACKSIZE || + n > static_cast<int>(m_StackCount)) break; - } - for (int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) m_Stack[m_StackCount + i] = m_Stack[m_StackCount + i - n]; - } m_StackCount += n; break; } case PSOP_INDEX: { - int n = (int)Pop(); - if (n < 0 || n >= m_StackCount) { + int n = static_cast<int>(Pop()); + if (n < 0 || n >= static_cast<int>(m_StackCount)) break; - } Push(m_Stack[m_StackCount - n - 1]); break; } case PSOP_ROLL: { - int j = (int)Pop(); - int n = (int)Pop(); - if (m_StackCount == 0) { + int j = static_cast<int>(Pop()); + int n = static_cast<int>(Pop()); + if (m_StackCount == 0) break; - } - if (n < 0 || n > m_StackCount) { + if (n < 0 || n > static_cast<int>(m_StackCount)) break; - } if (j < 0) { for (int i = 0; i < -j; i++) { FX_FLOAT first = m_Stack[m_StackCount - n]; - for (int ii = 0; ii < n - 1; ii++) { + for (int ii = 0; ii < n - 1; ii++) m_Stack[m_StackCount - n + ii] = m_Stack[m_StackCount - n + ii + 1]; - } m_Stack[m_StackCount - 1] = first; } } else { for (int i = 0; i < j; i++) { FX_FLOAT last = m_Stack[m_StackCount - 1]; int ii; - for (ii = 0; ii < n - 1; ii++) { + for (ii = 0; ii < n - 1; ii++) m_Stack[m_StackCount - ii - 1] = m_Stack[m_StackCount - ii - 2]; - } m_Stack[m_StackCount - ii - 1] = last; } } @@ -549,22 +542,20 @@ FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { m_pSampleStream->LoadAllData(pStream, FALSE); m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs); FX_SAFE_DWORD nTotalSampleBits = 1; - for (int i = 0; i < m_nInputs; i++) { + for (uint32_t i = 0; i < m_nInputs; i++) { m_pEncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; - if (!pSize && i == 0) { + if (!pSize && i == 0) m_pEncodeInfo[i].sizes = pDict->GetIntegerBy("Size"); - } nTotalSampleBits *= m_pEncodeInfo[i].sizes; if (pEncode) { m_pEncodeInfo[i].encode_min = pEncode->GetFloatAt(i * 2); m_pEncodeInfo[i].encode_max = pEncode->GetFloatAt(i * 2 + 1); } else { m_pEncodeInfo[i].encode_min = 0; - if (m_pEncodeInfo[i].sizes == 1) { + if (m_pEncodeInfo[i].sizes == 1) m_pEncodeInfo[i].encode_max = 1; - } else { + else m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1; - } } } nTotalSampleBits *= m_nBitsPerSample; @@ -577,7 +568,7 @@ FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { return FALSE; } m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs); - for (int i = 0; i < m_nOutputs; i++) { + for (uint32_t i = 0; i < m_nOutputs; i++) { if (pDecode) { m_pDecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i); m_pDecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1); @@ -595,21 +586,19 @@ FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2); int* index = int_buf; int* blocksize = index + m_nInputs; - for (int i = 0; i < m_nInputs; i++) { - if (i == 0) { + for (uint32_t i = 0; i < m_nInputs; i++) { + if (i == 0) blocksize[i] = 1; - } else { + else blocksize[i] = blocksize[i - 1] * m_pEncodeInfo[i - 1].sizes; - } encoded_input[i] = PDF_Interpolate( inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1], m_pEncodeInfo[i].encode_min, m_pEncodeInfo[i].encode_max); index[i] = (int)encoded_input[i]; - if (index[i] < 0) { + if (index[i] < 0) index[i] = 0; - } else if (index[i] > m_pEncodeInfo[i].sizes - 1) { + else if (index[i] > m_pEncodeInfo[i].sizes - 1) index[i] = m_pEncodeInfo[i].sizes - 1; - } pos += index[i] * blocksize[i]; } FX_SAFE_INT32 bits_to_output = m_nOutputs; @@ -631,25 +620,23 @@ FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { if (!pSampleData) { return FALSE; } - for (int j = 0; j < m_nOutputs; j++) { + for (uint32_t j = 0; j < m_nOutputs; j++) { uint32_t sample = _GetBits32(pSampleData, bitpos.ValueOrDie() + j * m_nBitsPerSample, m_nBitsPerSample); FX_FLOAT encoded = (FX_FLOAT)sample; - for (int i = 0; i < m_nInputs; i++) { + for (uint32_t i = 0; i < m_nInputs; i++) { if (index[i] == m_pEncodeInfo[i].sizes - 1) { - if (index[i] == 0) { + if (index[i] == 0) encoded = encoded_input[i] * (FX_FLOAT)sample; - } } else { FX_SAFE_INT32 bitpos2 = blocksize[i]; bitpos2 += pos; bitpos2 *= m_nOutputs; bitpos2 += j; bitpos2 *= m_nBitsPerSample; - if (!bitpos2.IsValid()) { + if (!bitpos2.IsValid()) return FALSE; - } uint32_t sample1 = _GetBits32(pSampleData, bitpos2.ValueOrDie(), m_nBitsPerSample); encoded += (encoded_input[i] - index[i]) * @@ -682,17 +669,13 @@ FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; PS.Reset(); - int i; - for (i = 0; i < m_nInputs; i++) { + for (uint32_t i = 0; i < m_nInputs; i++) PS.Push(inputs[i]); - } PS.Execute(); - if (PS.GetStackSize() < m_nOutputs) { + if (PS.GetStackSize() < m_nOutputs) return FALSE; - } - for (i = 0; i < m_nOutputs; i++) { + for (uint32_t i = 0; i < m_nOutputs; i++) results[m_nOutputs - i - 1] = PS.Pop(); - } return TRUE; } @@ -723,7 +706,7 @@ FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { CPDF_Array* pArray1 = pDict->GetArrayBy("C1"); m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); - for (int i = 0; i < m_nOutputs; i++) { + for (uint32_t i = 0; i < m_nOutputs; i++) { m_pBeginValues[i] = pArray0 ? pArray0->GetFloatAt(i) : 0.0f; m_pEndValues[i] = pArray1 ? pArray1->GetFloatAt(i) : 1.0f; } @@ -736,8 +719,8 @@ FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { return TRUE; } FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { - for (int i = 0; i < m_nInputs; i++) - for (int j = 0; j < m_nOrigOutputs; j++) { + for (uint32_t i = 0; i < m_nInputs; i++) + for (uint32_t j = 0; j < m_nOrigOutputs; j++) { results[i * m_nOrigOutputs + j] = m_pBeginValues[j] + (FX_FLOAT)FXSYS_pow(inputs[i], m_Exponent) * @@ -771,24 +754,20 @@ FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { return FALSE; } uint32_t nSubs = pArray->GetCount(); - if (nSubs == 0) { + if (nSubs == 0) return FALSE; - } m_nOutputs = 0; for (uint32_t i = 0; i < nSubs; i++) { CPDF_Object* pSub = pArray->GetDirectObjectAt(i); - if (pSub == pObj) { + if (pSub == pObj) return FALSE; - } std::unique_ptr<CPDF_Function> pFunc(CPDF_Function::Load(pSub)); - if (!pFunc) { + if (!pFunc) return FALSE; - } // Check that the input dimensionality is 1, and that all output // dimensionalities are the same. - if (pFunc->CountInputs() != kRequiredNumInputs) { + if (pFunc->CountInputs() != kRequiredNumInputs) return FALSE; - } if (pFunc->CountOutputs() != m_nOutputs) { if (m_nOutputs) return FALSE; @@ -801,30 +780,27 @@ FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { m_pBounds = FX_Alloc(FX_FLOAT, nSubs + 1); m_pBounds[0] = m_pDomains[0]; pArray = pDict->GetArrayBy("Bounds"); - if (!pArray) { + if (!pArray) return FALSE; - } - for (uint32_t i = 0; i < nSubs - 1; i++) { + for (uint32_t i = 0; i < nSubs - 1; i++) m_pBounds[i + 1] = pArray->GetFloatAt(i); - } m_pBounds[nSubs] = m_pDomains[1]; m_pEncode = FX_Alloc2D(FX_FLOAT, nSubs, 2); pArray = pDict->GetArrayBy("Encode"); - if (!pArray) { + if (!pArray) return FALSE; - } - for (uint32_t i = 0; i < nSubs * 2; i++) { + + for (uint32_t i = 0; i < nSubs * 2; i++) m_pEncode[i] = pArray->GetFloatAt(i); - } return TRUE; } FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const { FX_FLOAT input = inputs[0]; size_t i; - for (i = 0; i < m_pSubFunctions.size() - 1; i++) - if (input < m_pBounds[i + 1]) { + for (i = 0; i < m_pSubFunctions.size() - 1; i++) { + if (input < m_pBounds[i + 1]) break; - } + } if (!m_pSubFunctions[i]) { return FALSE; } @@ -888,7 +864,7 @@ FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { return FALSE; m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); - for (int i = 0; i < m_nInputs * 2; i++) { + for (uint32_t i = 0; i < m_nInputs * 2; i++) { m_pDomains[i] = pDomains->GetFloatAt(i); } CPDF_Array* pRanges = pDict->GetArrayBy("Range"); @@ -896,15 +872,13 @@ FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { if (pRanges) { m_nOutputs = pRanges->GetCount() / 2; m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); - for (int i = 0; i < m_nOutputs * 2; i++) { + for (uint32_t i = 0; i < m_nOutputs * 2; i++) m_pRanges[i] = pRanges->GetFloatAt(i); - } } uint32_t old_outputs = m_nOutputs; - if (!v_Init(pObj)) { + if (!v_Init(pObj)) return FALSE; - } - if (m_pRanges && m_nOutputs > (int)old_outputs) { + if (m_pRanges && m_nOutputs > old_outputs) { m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2); if (m_pRanges) { FXSYS_memset(m_pRanges + (old_outputs * 2), 0, @@ -914,28 +888,26 @@ FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { return TRUE; } FX_BOOL CPDF_Function::Call(FX_FLOAT* inputs, - int ninputs, + uint32_t ninputs, FX_FLOAT* results, int& nresults) const { if (m_nInputs != ninputs) { return FALSE; } nresults = m_nOutputs; - for (int i = 0; i < m_nInputs; i++) { - if (inputs[i] < m_pDomains[i * 2]) { + for (uint32_t i = 0; i < m_nInputs; i++) { + if (inputs[i] < m_pDomains[i * 2]) inputs[i] = m_pDomains[i * 2]; - } else if (inputs[i] > m_pDomains[i * 2 + 1]) { + else if (inputs[i] > m_pDomains[i * 2 + 1]) inputs[i] = m_pDomains[i * 2] + 1; - } } v_Call(inputs, results); if (m_pRanges) { - for (int i = 0; i < m_nOutputs; i++) { - if (results[i] < m_pRanges[i * 2]) { + for (uint32_t i = 0; i < m_nOutputs; i++) { + if (results[i] < m_pRanges[i * 2]) results[i] = m_pRanges[i * 2]; - } else if (results[i] > m_pRanges[i * 2 + 1]) { + else if (results[i] > m_pRanges[i * 2 + 1]) results[i] = m_pRanges[i * 2 + 1]; - } } } return TRUE; diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 32517d6b54..bf691f41d2 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1126,15 +1126,14 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Fill() { if (!pLastParam) { return; } - int nargs = m_ParamCount; - int nvalues = nargs; - if (pLastParam->IsName()) { + uint32_t nargs = m_ParamCount; + uint32_t nvalues = nargs; + if (pLastParam->IsName()) nvalues--; - } FX_FLOAT* values = NULL; if (nvalues) { values = FX_Alloc(FX_FLOAT, nvalues); - for (int i = 0; i < nvalues; i++) { + for (uint32_t i = 0; i < nvalues; i++) { values[i] = GetNumber(nargs - i - 1); } } diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp index f4c33d2811..ff15b21d73 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp @@ -19,7 +19,7 @@ TEST(fpdf_page_parser_old, ReadHexString) { uint8_t data[] = "1A2b>abcd"; CPDF_StreamParser parser(data, 5); EXPECT_EQ("\x1a\x2b", parser.ReadHexString()); - EXPECT_EQ(5, parser.GetPos()); + EXPECT_EQ(5u, parser.GetPos()); } { @@ -27,7 +27,7 @@ TEST(fpdf_page_parser_old, ReadHexString) { uint8_t data[] = "1A2b"; CPDF_StreamParser parser(data, 5); EXPECT_EQ("\x1a\x2b", parser.ReadHexString()); - EXPECT_EQ(5, parser.GetPos()); + EXPECT_EQ(5u, parser.GetPos()); } { @@ -35,13 +35,13 @@ TEST(fpdf_page_parser_old, ReadHexString) { uint8_t data[] = "1A2>asdf"; CPDF_StreamParser parser(data, 5); EXPECT_EQ("\x1a\x20", parser.ReadHexString()); - EXPECT_EQ(4, parser.GetPos()); + EXPECT_EQ(4u, parser.GetPos()); } { uint8_t data[] = ">"; CPDF_StreamParser parser(data, 5); EXPECT_EQ("", parser.ReadHexString()); - EXPECT_EQ(1, parser.GetPos()); + EXPECT_EQ(1u, parser.GetPos()); } } diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h index d76eea49d2..4fa62c03cb 100644 --- a/core/fpdfapi/fpdf_page/pageint.h +++ b/core/fpdfapi/fpdf_page/pageint.h @@ -387,11 +387,11 @@ class CPDF_Function { static CPDF_Function* Load(CPDF_Object* pFuncObj); virtual ~CPDF_Function(); FX_BOOL Call(FX_FLOAT* inputs, - int ninputs, + uint32_t ninputs, FX_FLOAT* results, int& nresults) const; - int CountInputs() const { return m_nInputs; } - int CountOutputs() const { return m_nOutputs; } + uint32_t CountInputs() const { return m_nInputs; } + uint32_t CountOutputs() const { return m_nOutputs; } FX_FLOAT GetDomain(int i) const { return m_pDomains[i]; } Type GetType() const { return m_Type; } @@ -401,8 +401,8 @@ class CPDF_Function { virtual FX_BOOL v_Init(CPDF_Object* pObj) = 0; virtual FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const = 0; - int m_nInputs; - int m_nOutputs; + uint32_t m_nInputs; + uint32_t m_nOutputs; FX_FLOAT* m_pDomains; FX_FLOAT* m_pRanges; Type m_Type; @@ -417,7 +417,7 @@ class CPDF_ExpIntFunc : public CPDF_Function { FX_BOOL v_Init(CPDF_Object* pObj) override; FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; - int m_nOrigOutputs; + uint32_t m_nOrigOutputs; FX_FLOAT m_Exponent; FX_FLOAT* m_pBeginValues; FX_FLOAT* m_pEndValues; @@ -436,7 +436,7 @@ class CPDF_StitchFunc : public CPDF_Function { FX_FLOAT* m_pBounds; FX_FLOAT* m_pEncode; - static const int kRequiredNumInputs = 1; + static const uint32_t kRequiredNumInputs = 1; }; class CPDF_IccProfile { diff --git a/core/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/fpdfapi/fpdf_parser/cpdf_array.cpp index 7ea2734745..964ba64236 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_array.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_array.cpp @@ -131,14 +131,14 @@ CPDF_Array* CPDF_Array::GetArrayAt(uint32_t i) const { return ToArray(GetDirectObjectAt(i)); } -void CPDF_Array::RemoveAt(uint32_t i, int nCount) { +void CPDF_Array::RemoveAt(uint32_t i, uint32_t nCount) { if (i >= (uint32_t)m_Objects.GetSize()) return; if (nCount <= 0 || nCount > m_Objects.GetSize() - i) return; - for (int j = 0; j < nCount; ++j) { + for (uint32_t j = 0; j < nCount; ++j) { if (CPDF_Object* p = m_Objects.GetAt(i + j)) p->Release(); } diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp index d81725d06f..18687e5fb7 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp @@ -59,7 +59,7 @@ FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { // Item 2: The location of the first page's page object. uint32_t dwFirstObjLoc = hStream->GetBits(32); - if (dwFirstObjLoc > nStreamOffset) { + if (dwFirstObjLoc > static_cast<uint32_t>(nStreamOffset)) { FX_SAFE_DWORD safeLoc = pdfium::base::checked_cast<uint32_t>(nStreamLen); safeLoc += dwFirstObjLoc; if (!safeLoc.IsValid()) @@ -236,7 +236,7 @@ FX_BOOL CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, // Item 2: The location of the first object in the shared objects section. uint32_t dwFirstSharedObjLoc = hStream->GetBits(32); - if (dwFirstSharedObjLoc > nStreamOffset) + if (dwFirstSharedObjLoc > static_cast<uint32_t>(nStreamOffset)) dwFirstSharedObjLoc += nStreamLen; // Item 3: The number of shared object entries for the first page. @@ -387,12 +387,13 @@ IPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( uint32_t dwObjNum = 0; for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { dwIndex = m_dwIdentifierArray[offset + j]; - if (dwIndex >= m_dwSharedObjNumArray.GetSize()) + if (dwIndex >= static_cast<uint32_t>(m_dwSharedObjNumArray.GetSize())) return IPDF_DataAvail::DataNotAvailable; dwObjNum = m_dwSharedObjNumArray[dwIndex]; - if (dwObjNum >= nFirstPageObjNum && - dwObjNum < nFirstPageObjNum + m_nFirstPageSharedObjs) { + if (dwObjNum >= static_cast<uint32_t>(nFirstPageObjNum) && + dwObjNum < + static_cast<uint32_t>(nFirstPageObjNum) + m_nFirstPageSharedObjs) { continue; } @@ -428,7 +429,7 @@ FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { // Hint table has at least 60 bytes. const uint32_t MIN_STREAM_LEN = 60; if (size < MIN_STREAM_LEN || shared_hint_table_offset <= 0 || - size < shared_hint_table_offset) { + size < static_cast<uint32_t>(shared_hint_table_offset)) { return FALSE; } diff --git a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp index 14410dabb5..ef3395d3ae 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp @@ -26,7 +26,8 @@ CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { auto it = m_IndirectObjs.find(objnum); if (it != m_IndirectObjs.end()) - return it->second->GetObjNum() != -1 ? it->second : nullptr; + return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second + : nullptr; if (!m_pParser) return nullptr; @@ -56,8 +57,10 @@ uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { auto it = m_IndirectObjs.find(objnum); - if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1) + if (it == m_IndirectObjs.end() || + it->second->GetObjNum() == CPDF_Object::kInvalidObjNum) { return; + } it->second->Destroy(); m_IndirectObjs.erase(it); } diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_array.h b/core/fpdfapi/fpdf_parser/include/cpdf_array.h index ea367785ed..b964f4955b 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_array.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_array.h @@ -44,7 +44,7 @@ class CPDF_Array : public CPDF_Object { void InsertAt(uint32_t index, CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs = nullptr); - void RemoveAt(uint32_t index, int nCount = 1); + void RemoveAt(uint32_t index, uint32_t nCount = 1); void Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs = nullptr); void AddNumber(FX_FLOAT f); diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_object.h b/core/fpdfapi/fpdf_parser/include/cpdf_object.h index 1ba38a946e..802cbbc638 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_object.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_object.h @@ -22,6 +22,7 @@ class CPDF_String; class CPDF_Object { public: + static const uint32_t kInvalidObjNum = static_cast<uint32_t>(-1); enum Type { BOOLEAN = 1, NUMBER, diff --git a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 9c1fa36b28..d3081da26f 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -58,15 +58,13 @@ static void DrawAxialShading(CFX_DIBitmap* pBitmap, FX_FLOAT axis_len_square = (x_span * x_span) + (y_span * y_span); CFX_Matrix matrix; matrix.SetReverse(*pObject2Bitmap); - int total_results = 0; + uint32_t total_results = 0; for (int j = 0; j < nFuncs; j++) { - if (pFuncs[j]) { + if (pFuncs[j]) total_results += pFuncs[j]->CountOutputs(); - } } - if (pCS->CountComponents() > total_results) { + if (pCS->CountComponents() > total_results) total_results = pCS->CountComponents(); - } CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); FX_FLOAT* pResults = result_array; FXSYS_memset(pResults, 0, total_results * sizeof(FX_FLOAT)); @@ -144,7 +142,7 @@ static void DrawRadialShading(CFX_DIBitmap* pBitmap, bStartExtend = pArray->GetIntegerAt(0); bEndExtend = pArray->GetIntegerAt(1); } - int total_results = 0; + uint32_t total_results = 0; for (int j = 0; j < nFuncs; j++) { if (pFuncs[j]) { total_results += pFuncs[j]->CountOutputs(); @@ -273,15 +271,13 @@ static void DrawFuncShading(CFX_DIBitmap* pBitmap, int width = pBitmap->GetWidth(); int height = pBitmap->GetHeight(); int pitch = pBitmap->GetPitch(); - int total_results = 0; + uint32_t total_results = 0; for (int j = 0; j < nFuncs; j++) { - if (pFuncs[j]) { + if (pFuncs[j]) total_results += pFuncs[j]->CountOutputs(); - } } - if (pCS->CountComponents() > total_results) { + if (pCS->CountComponents() > total_results) total_results = pCS->CountComponents(); - } CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); FX_FLOAT* pResults = result_array; FXSYS_memset(pResults, 0, total_results * sizeof(FX_FLOAT)); @@ -845,9 +841,8 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, if (pBackColor && pBackColor->GetCount() >= pColorSpace->CountComponents()) { CFX_FixedBufGrow<FX_FLOAT, 16> comps(pColorSpace->CountComponents()); - for (int i = 0; i < pColorSpace->CountComponents(); i++) { + for (uint32_t i = 0; i < pColorSpace->CountComponents(); i++) comps[i] = pBackColor->GetNumberAt(i); - } FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; pColorSpace->GetRGB(comps, R, G, B); background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), |