summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Li <weili@chromium.org>2016-03-29 16:42:53 -0700
committerWei Li <weili@chromium.org>2016-03-29 16:42:53 -0700
commit05d53f0355e9889c43bfa436e985d5643f249d99 (patch)
treeeca037b407114efe357e8280a96e44eee182cdfc
parent602aebc11a615971800d38f8d427a4e4f95c1134 (diff)
downloadpdfium-05d53f0355e9889c43bfa436e985d5643f249d99.tar.xz
Code change to avoid signed/unsigned mismatch warnings.
This makes pdfium code on Linux and Mac sign-compare warning free. The warning flag will be re-enabled after checking on windows clang build. BUG=pdfium:29 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1841643002 .
-rw-r--r--core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp7
-rw-r--r--core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp2
-rw-r--r--core/fpdfapi/fpdf_font/cpdf_cidfont.cpp7
-rw-r--r--core/fpdfapi/fpdf_font/font_int.h12
-rw-r--r--core/fpdfapi/fpdf_font/fpdf_font.cpp16
-rw-r--r--core/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp18
-rw-r--r--core/fpdfapi/fpdf_font/fpdf_font_unittest.cpp12
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.cpp10
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.h14
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp2
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_func.cpp144
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp9
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp8
-rw-r--r--core/fpdfapi/fpdf_page/pageint.h14
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_array.cpp4
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp13
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp7
-rw-r--r--core/fpdfapi/fpdf_parser/include/cpdf_array.h2
-rw-r--r--core/fpdfapi/fpdf_parser/include/cpdf_object.h1
-rw-r--r--core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp21
-rw-r--r--core/fpdfdoc/doc_formfield.cpp94
-rw-r--r--core/fpdftext/fpdf_text_int_unittest.cpp4
-rw-r--r--core/fxcodec/codec/fx_codec_jpx_unittest.cpp24
-rw-r--r--core/fxcrt/fx_basic_gcc_unittest.cpp10
-rw-r--r--core/fxcrt/include/fx_string.h4
-rw-r--r--core/fxge/ge/fx_ge_text.cpp36
-rw-r--r--core/include/fpdfdoc/fpdf_doc.h2
-rw-r--r--fpdfsdk/fpdfdoc_embeddertest.cpp10
-rw-r--r--fpdfsdk/fpdfsave_embeddertest.cpp4
-rw-r--r--fpdfsdk/fpdftext_embeddertest.cpp37
-rw-r--r--fpdfsdk/fpdfview.cpp3
-rw-r--r--fpdfsdk/fpdfview_embeddertest.cpp18
-rw-r--r--fpdfsdk/javascript/Field.cpp2
-rw-r--r--fpdfsdk/javascript/PublicMethods.cpp2
34 files changed, 265 insertions, 308 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),
diff --git a/core/fpdfdoc/doc_formfield.cpp b/core/fpdfdoc/doc_formfield.cpp
index cc34a9d297..4ebf2d3020 100644
--- a/core/fpdfdoc/doc_formfield.cpp
+++ b/core/fpdfdoc/doc_formfield.cpp
@@ -458,11 +458,9 @@ int CPDF_FormField::GetSelectedIndex(int index) {
return iOptIndex;
}
}
- int nOpts = CountOptions();
- for (int i = 0; i < nOpts; i++) {
- if (sel_value == GetOptionValue(i)) {
+ for (int i = 0; i < CountOptions(); i++) {
+ if (sel_value == GetOptionValue(i))
return i;
- }
}
return -1;
}
@@ -500,6 +498,7 @@ FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) {
m_pForm->m_bUpdated = TRUE;
return TRUE;
}
+
FX_BOOL CPDF_FormField::IsItemSelected(int index) {
ASSERT(GetType() == ComboBox || GetType() == ListBox);
if (index < 0 || index >= CountOptions()) {
@@ -544,6 +543,7 @@ FX_BOOL CPDF_FormField::IsItemSelected(int index) {
}
return FALSE;
}
+
FX_BOOL CPDF_FormField::SetItemSelection(int index,
FX_BOOL bSelected,
FX_BOOL bNotify) {
@@ -575,20 +575,16 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
}
} else if (pValue->IsArray()) {
CPDF_Array* pArray = new CPDF_Array;
- int iCount = CountOptions();
- for (int i = 0; i < iCount; i++) {
- if (i != index) {
- if (IsItemSelected(i)) {
- opt_value = GetOptionValue(i);
- pArray->AddString(PDF_EncodeText(opt_value));
- }
+ for (int i = 0; i < CountOptions(); i++) {
+ if (i != index && IsItemSelected(i)) {
+ opt_value = GetOptionValue(i);
+ pArray->AddString(PDF_EncodeText(opt_value));
}
}
- if (pArray->GetCount() < 1) {
+ if (pArray->GetCount() < 1)
pArray->Release();
- } else {
+ else
m_pDict->SetAt("V", pArray);
- }
}
} else if (m_Type == ComboBox) {
m_pDict->RemoveAt("V");
@@ -602,15 +598,8 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
m_pDict->SetAtString("V", PDF_EncodeText(opt_value));
} else {
CPDF_Array* pArray = new CPDF_Array;
- int iCount = CountOptions();
- for (int i = 0; i < iCount; i++) {
- FX_BOOL bSelected;
- if (i != index) {
- bSelected = IsItemSelected(i);
- } else {
- bSelected = TRUE;
- }
- if (bSelected) {
+ for (int i = 0; i < CountOptions(); i++) {
+ if (i == index || IsItemSelected(i)) {
opt_value = GetOptionValue(i);
pArray->AddString(PDF_EncodeText(opt_value));
}
@@ -638,54 +627,46 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
m_pForm->m_bUpdated = TRUE;
return TRUE;
}
+
FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) {
ASSERT(GetType() == ComboBox || GetType() == ListBox);
- if (index < 0 || index >= CountOptions()) {
+ if (index < 0 || index >= CountOptions())
return FALSE;
- }
int iDVIndex = GetDefaultSelectedItem();
- if (iDVIndex < 0) {
- return FALSE;
- }
- return (iDVIndex == index);
+ return iDVIndex >= 0 && iDVIndex == index;
}
+
int CPDF_FormField::GetDefaultSelectedItem() {
ASSERT(GetType() == ComboBox || GetType() == ListBox);
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV");
- if (!pValue) {
+ if (!pValue)
return -1;
- }
CFX_WideString csDV = pValue->GetUnicodeText();
- if (csDV.IsEmpty()) {
+ if (csDV.IsEmpty())
return -1;
- }
- int iCount = CountOptions();
- for (int i = 0; i < iCount; i++) {
- if (csDV == GetOptionValue(i)) {
+ for (int i = 0; i < CountOptions(); i++) {
+ if (csDV == GetOptionValue(i))
return i;
- }
}
return -1;
}
+
void CPDF_FormField::UpdateAP(CPDF_FormControl* pControl) {
- if (m_Type == PushButton) {
- return;
- }
- if (m_Type == RadioButton || m_Type == CheckBox) {
+ if (m_Type == PushButton || m_Type == RadioButton || m_Type == CheckBox)
return;
- }
- if (!m_pForm->m_bGenerateAP) {
+ if (!m_pForm->m_bGenerateAP)
return;
- }
for (int i = 0; i < CountControls(); i++) {
CPDF_FormControl* pControl = GetControl(i);
FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict);
}
}
+
int CPDF_FormField::CountOptions() {
CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
return pArray ? pArray->GetCount() : 0;
}
+
CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) {
CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
if (!pArray)
@@ -706,30 +687,23 @@ CFX_WideString CPDF_FormField::GetOptionLabel(int index) {
CFX_WideString CPDF_FormField::GetOptionValue(int index) {
return GetOptionText(index, 0);
}
+
int CPDF_FormField::FindOption(CFX_WideString csOptLabel) {
- int iCount = CountOptions();
- for (int i = 0; i < iCount; i++) {
- CFX_WideString csValue = GetOptionValue(i);
- if (csValue == csOptLabel) {
+ for (int i = 0; i < CountOptions(); i++) {
+ if (GetOptionValue(i) == csOptLabel)
return i;
- }
}
return -1;
}
-int CPDF_FormField::FindOptionValue(const CFX_WideString& csOptValue,
- int iStartIndex) {
- if (iStartIndex < 0) {
- iStartIndex = 0;
- }
- int iCount = CountOptions();
- for (; iStartIndex < iCount; iStartIndex++) {
- CFX_WideString csValue = GetOptionValue(iStartIndex);
- if (csValue == csOptValue) {
- return iStartIndex;
- }
+
+int CPDF_FormField::FindOptionValue(const CFX_WideString& csOptValue) {
+ for (int i = 0; i < CountOptions(); i++) {
+ if (GetOptionValue(i) == csOptValue)
+ return i;
}
return -1;
}
+
#ifdef PDF_ENABLE_XFA
int CPDF_FormField::InsertOption(CFX_WideString csOptLabel,
int index,
diff --git a/core/fpdftext/fpdf_text_int_unittest.cpp b/core/fpdftext/fpdf_text_int_unittest.cpp
index 1510ebc06c..e62e885d4b 100644
--- a/core/fpdftext/fpdf_text_int_unittest.cpp
+++ b/core/fpdftext/fpdf_text_int_unittest.cpp
@@ -26,7 +26,7 @@ TEST(fpdf_text_int, CheckMailLink) {
L"abc@.xyz.org", // Domain name should not start with '.'.
L"fan@g..com" // Domain name should not have consecutive '.'
};
- for (int i = 0; i < FX_ArraySize(invalid_strs); ++i) {
+ for (size_t i = 0; i < FX_ArraySize(invalid_strs); ++i) {
CFX_WideString text_str(invalid_strs[i]);
EXPECT_FALSE(extractor.CheckMailLink(text_str));
}
@@ -46,7 +46,7 @@ TEST(fpdf_text_int, CheckMailLink) {
{L"fan@g.com..", L"fan@g.com"}, // Trim the ending periods.
{L"CAP.cap@Gmail.Com", L"CAP.cap@Gmail.Com"}, // Keep the original case.
};
- for (int i = 0; i < FX_ArraySize(valid_strs); ++i) {
+ for (size_t i = 0; i < FX_ArraySize(valid_strs); ++i) {
CFX_WideString text_str(valid_strs[i][0]);
CFX_WideString expected_str(L"mailto:");
expected_str += valid_strs[i][1];
diff --git a/core/fxcodec/codec/fx_codec_jpx_unittest.cpp b/core/fxcodec/codec/fx_codec_jpx_unittest.cpp
index 765d8a2e59..13b5425927 100644
--- a/core/fxcodec/codec/fx_codec_jpx_unittest.cpp
+++ b/core/fxcodec/codec/fx_codec_jpx_unittest.cpp
@@ -296,7 +296,7 @@ TEST(fxcodec, DecodeDataSkip) {
// Skiping within buffer is allowed.
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(1, opj_skip_from_memory(1, &dd));
+ EXPECT_EQ(1u, opj_skip_from_memory(1, &dd));
EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
EXPECT_EQ(0x01, buffer[0]);
EXPECT_EQ(0xbd, buffer[1]);
@@ -310,7 +310,7 @@ TEST(fxcodec, DecodeDataSkip) {
// Skiping to EOS-1 is possible.
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(4, opj_skip_from_memory(4, &dd));
+ EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
EXPECT_EQ(0x87, buffer[0]);
EXPECT_EQ(0xbd, buffer[1]);
@@ -325,7 +325,7 @@ TEST(fxcodec, DecodeDataSkip) {
// Skiping directly to EOS is allowed.
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(8, opj_skip_from_memory(8, &dd));
+ EXPECT_EQ(8u, opj_skip_from_memory(8, &dd));
// Next read fails.
EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
@@ -336,7 +336,7 @@ TEST(fxcodec, DecodeDataSkip) {
// Skipping beyond end of stream is allowed and returns full distance.
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(9, opj_skip_from_memory(9, &dd));
+ EXPECT_EQ(9u, opj_skip_from_memory(9, &dd));
// Next read fails.
EXPECT_EQ(kReadError, opj_read_from_memory(buffer, 1, &dd));
@@ -348,7 +348,7 @@ TEST(fxcodec, DecodeDataSkip) {
// Skipping way beyond EOS is allowd, doesn't wrap, and returns
// full distance.
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(4, opj_skip_from_memory(4, &dd));
+ EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
EXPECT_EQ(std::numeric_limits<OPJ_OFF_T>::max(),
opj_skip_from_memory(std::numeric_limits<OPJ_OFF_T>::max(), &dd));
@@ -361,7 +361,7 @@ TEST(fxcodec, DecodeDataSkip) {
// Negative skip within buffer not is allowed, position unchanged.
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(4, opj_skip_from_memory(4, &dd));
+ EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
EXPECT_EQ(kSkipError, opj_skip_from_memory(-2, &dd));
// Next read succeeds as if nothing has happenned.
@@ -383,12 +383,12 @@ TEST(fxcodec, DecodeDataSkip) {
// Negative skip way before buffer is not allowed, doesn't wrap
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(4, opj_skip_from_memory(4, &dd));
+ EXPECT_EQ(4u, opj_skip_from_memory(4, &dd));
EXPECT_EQ(kSkipError,
opj_skip_from_memory(std::numeric_limits<OPJ_OFF_T>::min(), &dd));
// Next read succeeds. If it fails, it may mean we wrapped.
- EXPECT_EQ(1, opj_read_from_memory(buffer, 1, &dd));
+ EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
EXPECT_EQ(0x84, buffer[0]);
EXPECT_EQ(0xbd, buffer[1]);
}
@@ -397,7 +397,7 @@ TEST(fxcodec, DecodeDataSkip) {
// Negative skip after EOS isn't alowed, still EOS.
memset(buffer, 0xbd, sizeof(buffer));
- EXPECT_EQ(8, opj_skip_from_memory(8, &dd));
+ EXPECT_EQ(8u, opj_skip_from_memory(8, &dd));
EXPECT_EQ(kSkipError, opj_skip_from_memory(-4, &dd));
// Next read fails.
@@ -420,7 +420,7 @@ TEST(fxcodec, DecodeDataSeek) {
// Seeking before start returns error leaving position unchanged.
memset(buffer, 0xbd, sizeof(buffer));
EXPECT_FALSE(opj_seek_from_memory(-1, &dd));
- EXPECT_EQ(1, opj_read_from_memory(buffer, 1, &dd));
+ EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
EXPECT_EQ(0x02, buffer[0]);
EXPECT_EQ(0xbd, buffer[1]);
@@ -428,7 +428,7 @@ TEST(fxcodec, DecodeDataSeek) {
memset(buffer, 0xbd, sizeof(buffer));
EXPECT_FALSE(
opj_seek_from_memory(std::numeric_limits<OPJ_OFF_T>::min(), &dd));
- EXPECT_EQ(1, opj_read_from_memory(buffer, 1, &dd));
+ EXPECT_EQ(1u, opj_read_from_memory(buffer, 1, &dd));
EXPECT_EQ(0x03, buffer[0]);
EXPECT_EQ(0xbd, buffer[1]);
@@ -498,7 +498,7 @@ TEST(fxcodec, YUV420ToRGB) {
bool expected;
} cases[] = {{0, false}, {1, false}, {30, false}, {31, true},
{32, true}, {33, false}, {34, false}, {UINT_MAX, false}};
- for (int i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) {
+ for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) {
y.w = cases[i].w;
y.h = y.w;
img.x1 = y.w;
diff --git a/core/fxcrt/fx_basic_gcc_unittest.cpp b/core/fxcrt/fx_basic_gcc_unittest.cpp
index 8d8d2f5deb..c6913cfd82 100644
--- a/core/fxcrt/fx_basic_gcc_unittest.cpp
+++ b/core/fxcrt/fx_basic_gcc_unittest.cpp
@@ -93,16 +93,16 @@ TEST(fxcrt, FXSYS_wtoi64) {
}
TEST(fxcrt, FXSYS_atoui) {
- EXPECT_EQ(0, FXSYS_atoui(""));
- EXPECT_EQ(0, FXSYS_atoui("0"));
+ EXPECT_EQ(0u, FXSYS_atoui(""));
+ EXPECT_EQ(0u, FXSYS_atoui("0"));
EXPECT_EQ(4294967295, FXSYS_atoui("-1"));
- EXPECT_EQ(2345, FXSYS_atoui("2345"));
+ EXPECT_EQ(2345u, FXSYS_atoui("2345"));
// Handle the sign.
EXPECT_EQ(4294964951, FXSYS_atoui("-2345"));
- EXPECT_EQ(2345, FXSYS_atoui("+2345"));
+ EXPECT_EQ(2345u, FXSYS_atoui("+2345"));
// The max value.
EXPECT_EQ(4294967295, FXSYS_atoui("4294967295"));
- EXPECT_EQ(9, FXSYS_atoui("9x9"));
+ EXPECT_EQ(9u, FXSYS_atoui("9x9"));
// Out of range values.
EXPECT_EQ(4294967295, FXSYS_atoui("2147483623423412348"));
diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h
index e5f9466b21..0aa34171c2 100644
--- a/core/fxcrt/include/fx_string.h
+++ b/core/fxcrt/include/fx_string.h
@@ -134,7 +134,9 @@ inline bool operator==(const char* lhs, const CFX_ByteStringC& rhs) {
inline bool operator!=(const char* lhs, const CFX_ByteStringC& rhs) {
return rhs != lhs;
}
-#define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4))
+#define FXBSTR_ID(c1, c2, c3, c4) \
+ (((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | \
+ ((uint32_t)c4))
// A mutable string with shared buffers using copy-on-write semantics that
// avoids the cost of std::string's iterator stability guarantees.
diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp
index 10c769aa6b..1d18ecd377 100644
--- a/core/fxge/ge/fx_ge_text.cpp
+++ b/core/fxge/ge/fx_ge_text.cpp
@@ -1536,12 +1536,14 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont,
skew = pSubstFont->m_ItalicAngle;
}
if (skew) {
- skew = skew <= -ANGLESKEW_ARRAY_SIZE ? -58 : -g_AngleSkew[-skew];
- if (pFont->IsVertical()) {
+ // skew is nonpositive so -skew is used as the index.
+ skew = -skew <= static_cast<int>(ANGLESKEW_ARRAY_SIZE)
+ ? -58
+ : -g_AngleSkew[-skew];
+ if (pFont->IsVertical())
ft_matrix.yx += ft_matrix.yy * skew / 100;
- } else {
+ else
ft_matrix.xy += -ft_matrix.xx * skew / 100;
- }
}
if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {
pFont->AdjustMMParams(glyph_index, dest_width,
@@ -1574,10 +1576,9 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont,
}
if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
weight > 400) {
- int index = (weight - 400) / 10;
- if (index >= WEIGHTPOW_ARRAY_SIZE) {
+ uint32_t index = (weight - 400) / 10;
+ if (index >= WEIGHTPOW_ARRAY_SIZE)
return NULL;
- }
int level = 0;
if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) {
level =
@@ -1801,12 +1802,14 @@ CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, int dest_width) {
if (m_pSubstFont) {
if (m_pSubstFont->m_ItalicAngle) {
int skew = m_pSubstFont->m_ItalicAngle;
- skew = skew <= -ANGLESKEW_ARRAY_SIZE ? -58 : -g_AngleSkew[-skew];
- if (m_bVertical) {
+ // skew is nonpositive so -skew is used as the index.
+ skew = -skew <= static_cast<int>(ANGLESKEW_ARRAY_SIZE)
+ ? -58
+ : -g_AngleSkew[-skew];
+ if (m_bVertical)
ft_matrix.yx += ft_matrix.yy * skew / 100;
- } else {
+ else
ft_matrix.xy += -ft_matrix.xx * skew / 100;
- }
}
if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {
AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight);
@@ -1817,21 +1820,18 @@ CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, int dest_width) {
if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face)) {
load_flags |= FT_LOAD_NO_HINTING;
}
- int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);
- if (error) {
+ if (FXFT_Load_Glyph(m_Face, glyph_index, load_flags))
return NULL;
- }
if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
m_pSubstFont->m_Weight > 400) {
- int index = (m_pSubstFont->m_Weight - 400) / 10;
+ uint32_t index = (m_pSubstFont->m_Weight - 400) / 10;
if (index >= WEIGHTPOW_ARRAY_SIZE)
index = WEIGHTPOW_ARRAY_SIZE - 1;
int level = 0;
- if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) {
+ if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET)
level = g_WeightPow_SHIFTJIS[index] * 2 * 65536 / 36655;
- } else {
+ else
level = g_WeightPow[index] * 2;
- }
FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
}
FXFT_Outline_Funcs funcs;
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h
index 87d1662c81..5939966995 100644
--- a/core/include/fpdfdoc/fpdf_doc.h
+++ b/core/include/fpdfdoc/fpdf_doc.h
@@ -722,7 +722,7 @@ class CPDF_FormField {
int FindOption(CFX_WideString csOptLabel);
- int FindOptionValue(const CFX_WideString& csOptValue, int iStartIndex = 0);
+ int FindOptionValue(const CFX_WideString& csOptValue);
FX_BOOL CheckControl(int iControlIndex,
bool bChecked,
diff --git a/fpdfsdk/fpdfdoc_embeddertest.cpp b/fpdfsdk/fpdfdoc_embeddertest.cpp
index bf91038ca6..855235858b 100644
--- a/fpdfsdk/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/fpdfdoc_embeddertest.cpp
@@ -72,7 +72,7 @@ TEST_F(FPDFDocEmbeddertest, NoBookmarks) {
// The non-existent top-level bookmark has no title.
unsigned short buf[128];
- EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
+ EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
// The non-existent top-level bookmark has no children.
EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr));
@@ -84,11 +84,11 @@ TEST_F(FPDFDocEmbeddertest, Bookmarks) {
// The existent top-level bookmark has no title.
unsigned short buf[128];
- EXPECT_EQ(0, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
+ EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf)));
FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr);
EXPECT_NE(nullptr, child);
- EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
+ EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
CFX_WideString::FromUTF16LE(buf, 16));
@@ -96,7 +96,7 @@ TEST_F(FPDFDocEmbeddertest, Bookmarks) {
FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child);
EXPECT_NE(nullptr, sibling);
- EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf)));
+ EXPECT_EQ(28u, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf)));
EXPECT_EQ(CFX_WideString(L"A Good Ending"),
CFX_WideString::FromUTF16LE(buf, 13));
@@ -115,7 +115,7 @@ TEST_F(FPDFDocEmbeddertest, FindBookmarks) {
// Check that the string matches.
unsigned short buf[128];
- EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
+ EXPECT_EQ(34u, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
CFX_WideString::FromUTF16LE(buf, 16));
diff --git a/fpdfsdk/fpdfsave_embeddertest.cpp b/fpdfsdk/fpdfsave_embeddertest.cpp
index 2b138a61e4..5dbff36327 100644
--- a/fpdfsdk/fpdfsave_embeddertest.cpp
+++ b/fpdfsdk/fpdfsave_embeddertest.cpp
@@ -19,14 +19,14 @@ TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
- EXPECT_EQ(843, GetString().length());
+ EXPECT_EQ(843u, GetString().length());
}
TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 14));
EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.4\r\n"));
- EXPECT_EQ(843, GetString().length());
+ EXPECT_EQ(843u, GetString().length());
}
TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) {
diff --git a/fpdfsdk/fpdftext_embeddertest.cpp b/fpdfsdk/fpdftext_embeddertest.cpp
index ed20882a1b..a5215c20cc 100644
--- a/fpdfsdk/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/fpdftext_embeddertest.cpp
@@ -48,7 +48,8 @@ TEST_F(FPDFTextEmbeddertest, Text) {
EXPECT_TRUE(check_unsigned_shorts(expected, fixed_buffer, sizeof(expected)));
// Count does not include the terminating NUL in the string literal.
- EXPECT_EQ(sizeof(expected) - 1, FPDFText_CountChars(textpage));
+ EXPECT_EQ(sizeof(expected) - 1,
+ static_cast<size_t>(FPDFText_CountChars(textpage)));
for (size_t i = 0; i < sizeof(expected) - 1; ++i) {
EXPECT_EQ(static_cast<unsigned int>(expected[i]),
FPDFText_GetUnicode(textpage, i))
@@ -285,6 +286,7 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) {
EXPECT_EQ(26, FPDFLink_GetURL(pagelink, 1, nullptr, 0));
static const char expected_url[] = "http://example.com?q=foo";
+ static const size_t expected_len = sizeof(expected_url);
unsigned short fixed_buffer[128];
// Retrieve a link with too small a buffer. Buffer will not be
@@ -297,30 +299,27 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) {
// Check buffer that doesn't have space for a terminating NUL.
memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
- EXPECT_EQ(
- sizeof(expected_url) - 1,
- FPDFLink_GetURL(pagelink, 0, fixed_buffer, sizeof(expected_url) - 1));
- EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer,
- sizeof(expected_url) - 1));
- EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url) - 1]);
+ EXPECT_EQ(static_cast<int>(expected_len - 1),
+ FPDFLink_GetURL(pagelink, 0, fixed_buffer, expected_len - 1));
+ EXPECT_TRUE(
+ check_unsigned_shorts(expected_url, fixed_buffer, expected_len - 1));
+ EXPECT_EQ(0xbdbd, fixed_buffer[expected_len - 1]);
// Retreive link with exactly-sized buffer.
memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
- EXPECT_EQ(sizeof(expected_url),
- FPDFLink_GetURL(pagelink, 0, fixed_buffer, sizeof(expected_url)));
- EXPECT_TRUE(
- check_unsigned_shorts(expected_url, fixed_buffer, sizeof(expected_url)));
- EXPECT_EQ(0u, fixed_buffer[sizeof(expected_url) - 1]);
- EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url)]);
+ EXPECT_EQ(static_cast<int>(expected_len),
+ FPDFLink_GetURL(pagelink, 0, fixed_buffer, expected_len));
+ EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer, expected_len));
+ EXPECT_EQ(0u, fixed_buffer[expected_len - 1]);
+ EXPECT_EQ(0xbdbd, fixed_buffer[expected_len]);
// Retreive link with ample-sized-buffer.
memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
- EXPECT_EQ(sizeof(expected_url),
+ EXPECT_EQ(static_cast<int>(expected_len),
FPDFLink_GetURL(pagelink, 0, fixed_buffer, 128));
- EXPECT_TRUE(
- check_unsigned_shorts(expected_url, fixed_buffer, sizeof(expected_url)));
- EXPECT_EQ(0u, fixed_buffer[sizeof(expected_url) - 1]);
- EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url)]);
+ EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer, expected_len));
+ EXPECT_EQ(0u, fixed_buffer[expected_len - 1]);
+ EXPECT_EQ(0xbdbd, fixed_buffer[expected_len]);
// Each link rendered in a single rect in this test page.
EXPECT_EQ(1, FPDFLink_CountRects(pagelink, 0));
@@ -382,7 +381,7 @@ TEST_F(FPDFTextEmbeddertest, GetFontSize) {
16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
int count = FPDFText_CountChars(textpage);
- ASSERT_EQ(FX_ArraySize(kExpectedFontsSizes), count);
+ ASSERT_EQ(FX_ArraySize(kExpectedFontsSizes), static_cast<size_t>(count));
for (int i = 0; i < count; ++i)
EXPECT_EQ(kExpectedFontsSizes[i], FPDFText_GetFontSize(textpage, i)) << i;
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 9995fc0426..9183b4073b 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -194,7 +194,8 @@ FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer,
FX_SAFE_FILESIZE newPos =
pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
newPos += offset;
- if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) {
+ if (!newPos.IsValid() ||
+ newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
return FALSE;
}
return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer,
diff --git a/fpdfsdk/fpdfview_embeddertest.cpp b/fpdfsdk/fpdfview_embeddertest.cpp
index 29eb91ab4d..10fe3aa822 100644
--- a/fpdfsdk/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/fpdfview_embeddertest.cpp
@@ -88,14 +88,16 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, &buffer_size);
EXPECT_EQ(nullptr, dest);
- EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified.
+ EXPECT_EQ(sizeof(fixed_buffer),
+ static_cast<size_t>(buffer_size)); // unmodified.
// Try to retrieve the forth item with ample buffer. Item is taken
// from Dests NameTree but has a vale of the wrong type in named_dests.pdf.
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, &buffer_size);
EXPECT_EQ(nullptr, dest);
- EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified.
+ EXPECT_EQ(sizeof(fixed_buffer),
+ static_cast<size_t>(buffer_size)); // unmodified.
// Try to retrieve fifth item with ample buffer. Item taken from the
// old-style Dests dictionary object in named_dests.pdf.
@@ -120,25 +122,29 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, &buffer_size);
EXPECT_EQ(nullptr, dest);
- EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified.
+ EXPECT_EQ(sizeof(fixed_buffer),
+ static_cast<size_t>(buffer_size)); // unmodified.
// Try to underflow/overflow the integer index.
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), std::numeric_limits<int>::max(),
fixed_buffer, &buffer_size);
EXPECT_EQ(nullptr, dest);
- EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified.
+ EXPECT_EQ(sizeof(fixed_buffer),
+ static_cast<size_t>(buffer_size)); // unmodified.
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), std::numeric_limits<int>::min(),
fixed_buffer, &buffer_size);
EXPECT_EQ(nullptr, dest);
- EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified.
+ EXPECT_EQ(sizeof(fixed_buffer),
+ static_cast<size_t>(buffer_size)); // unmodified.
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), -1, fixed_buffer, &buffer_size);
EXPECT_EQ(nullptr, dest);
- EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified.
+ EXPECT_EQ(sizeof(fixed_buffer),
+ static_cast<size_t>(buffer_size)); // unmodified.
}
TEST_F(FPDFViewEmbeddertest, NamedDestsByName) {
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index 54b4f6432c..5b8750d88e 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -1014,7 +1014,7 @@ void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
for (size_t i = 0; i < array.size(); ++i) {
if (i != 0 && !(dwFieldFlags & (1 << 21)))
break;
- if (array[i] < pFormField->CountOptions() &&
+ if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
!pFormField->IsItemSelected(array[i])) {
pFormField->SetItemSelection(array[i], TRUE);
}
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index a4c13564c8..62659e4163 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -1502,7 +1502,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(
if (wChange.empty())
return TRUE;
- int iIndexMask = pEvent->SelStart();
+ size_t iIndexMask = pEvent->SelStart();
size_t combined_len = wstrValue.length() + wChange.length() -
(pEvent->SelEnd() - pEvent->SelStart());