Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1882)

Unified Diff: core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp

Issue 2294383003: Use unsigned page indexes in CPDF_HintTables. (Closed)
Patch Set: Use unsigned page indexes in CPDF_HintTables. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
index 316361acedcb53339f6beee074067b8689bbacd0..7d9d0238bb151e283aaa6a0daaabc83861f7068a 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
@@ -35,10 +35,9 @@ CPDF_HintTables::CPDF_HintTables(CPDF_DataAvail* pDataAvail,
CPDF_HintTables::~CPDF_HintTables() {}
uint32_t CPDF_HintTables::GetItemLength(
- int index,
+ uint32_t index,
const std::vector<FX_FILESIZE>& szArray) {
- if (index < 0 || szArray.size() < 2 ||
- static_cast<size_t>(index) > szArray.size() - 2 ||
+ if (szArray.size() < 2 || index > szArray.size() - 2 ||
szArray[index] > szArray[index + 1]) {
return 0;
}
@@ -354,13 +353,10 @@ bool CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream,
return true;
}
-bool CPDF_HintTables::GetPagePos(int index,
+bool CPDF_HintTables::GetPagePos(uint32_t index,
FX_FILESIZE* szPageStartPos,
FX_FILESIZE* szPageLength,
uint32_t* dwObjNum) {
- if (index < 0)
- return false;
-
*szPageStartPos = m_szPageOffsetArray[index];
*szPageLength = GetItemLength(index, m_szPageOffsetArray);
@@ -372,15 +368,16 @@ bool CPDF_HintTables::GetPagePos(int index,
if (nFirstPageNum < 0)
Tom Sepez 2016/09/01 16:16:27 Do we just want to use base's checked cast magin i
Lei Zhang 2016/09/01 17:58:21 Done.
return false;
- if (index == nFirstPageNum) {
+ uint32_t dwFirstPageNum = static_cast<uint32_t>(nFirstPageNum);
+ if (index == dwFirstPageNum) {
*dwObjNum = nFirstPageObjNum;
return true;
}
// The object number of remaining pages starts from 1.
*dwObjNum = 1;
- for (int i = 0; i < index; ++i) {
- if (i == nFirstPageNum)
+ for (uint32_t i = 0; i < index; ++i) {
+ if (i == dwFirstPageNum)
continue;
*dwObjNum += m_dwDeltaNObjsArray[i];
}
@@ -388,12 +385,16 @@ bool CPDF_HintTables::GetPagePos(int index,
}
CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(
- int index,
+ uint32_t index,
CPDF_DataAvail::DownloadHints* pHints) {
- if (!pHints || index < 0)
+ if (!pHints)
+ return CPDF_DataAvail::DataError;
+
+ int nFirstPageNum = GetFirstPageNumber();
+ if (nFirstPageNum < 0)
return CPDF_DataAvail::DataError;
- if (index == GetFirstPageNumber())
+ if (index == static_cast<uint32_t>(nFirstPageNum))
return CPDF_DataAvail::DataAvailable;
uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray);
@@ -406,7 +407,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(
// Download data of shared objects in the page.
uint32_t offset = 0;
- for (int i = 0; i < index; ++i)
+ for (uint32_t i = 0; i < index; ++i)
offset += m_dwNSharedObjsArray[i];
int nFirstPageObjNum = GetFirstPageObjectNumber();

Powered by Google App Engine
This is Rietveld 408576698