summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_parser.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-06 18:07:18 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-06 18:07:18 +0000
commit1ca11be3b7a36b16663da4816c575cf0ac06ee7f (patch)
treeec2864da9f2834d9bebd77dfb02ea06dadf4445b /core/fpdfapi/parser/cpdf_parser.cpp
parent7f08348c98325eb303322142148440610b49fe86 (diff)
downloadpdfium-1ca11be3b7a36b16663da4816c575cf0ac06ee7f.tar.xz
Do more CPDF_Parser::LoadCrossRefV5() cleanup.
- Use range for-loop to avoid needing "i" and "j". - Avoid repeatedly calculating "startnum + j". - Reduce levels of nested ifs. - Remove variable that is only used once. Change-Id: I9d08cef1082812fcfaa2699f65720165c52ebcff Reviewed-on: https://pdfium-review.googlesource.com/39437 Reviewed-by: Art Snake <art-snake@yandex-team.ru> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_parser.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp57
1 files changed, 28 insertions, 29 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 9cff27f5e2..46973781b8 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -660,11 +660,7 @@ bool CPDF_Parser::RebuildCrossRef() {
bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) {
std::unique_ptr<CPDF_Object> pObject(ParseIndirectObjectAt(*pos, 0));
- if (!pObject)
- return false;
-
- uint32_t objnum = pObject->GetObjNum();
- if (!objnum)
+ if (!pObject || !pObject->GetObjNum())
return false;
CPDF_Stream* pStream = pObject->AsStream();
@@ -728,12 +724,12 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) {
const uint8_t* pData = pAcc->GetData();
uint32_t dwTotalSize = pAcc->GetSize();
uint32_t segindex = 0;
- for (uint32_t i = 0; i < arrIndex.size(); i++) {
- int32_t startnum = arrIndex[i].first;
+ for (const auto& index : arrIndex) {
+ const int32_t startnum = index.first;
if (startnum < 0)
continue;
- uint32_t count = pdfium::base::checked_cast<uint32_t>(arrIndex[i].second);
+ uint32_t count = pdfium::base::checked_cast<uint32_t>(index.second);
FX_SAFE_UINT32 dwCaculatedSize = segindex;
dwCaculatedSize += count;
dwCaculatedSize *= totalWidth;
@@ -749,43 +745,46 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) {
if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size)
continue;
- for (uint32_t j = 0; j < count; j++) {
+ for (uint32_t i = 0; i < count; i++) {
ObjectType type = ObjectType::kNotCompressed;
- const uint8_t* entrystart = segstart + j * totalWidth;
+ const uint8_t* entrystart = segstart + i * totalWidth;
if (WidthArray[0]) {
const uint32_t cross_ref_stream_obj_type =
GetVarInt(entrystart, WidthArray[0]);
type = GetObjectTypeFromCrossRefStreamType(cross_ref_stream_obj_type);
}
- if (GetObjectType(startnum + j) == ObjectType::kNull) {
+ const uint32_t objnum = startnum + i;
+ if (GetObjectType(objnum) == ObjectType::kNull) {
uint32_t offset = GetVarInt(entrystart + WidthArray[0], WidthArray[1]);
if (pdfium::base::IsValueInRangeForNumericType<FX_FILESIZE>(offset))
- m_CrossRefTable->AddNormal(startnum + j, 0, offset);
+ m_CrossRefTable->AddNormal(objnum, 0, offset);
continue;
}
- if (GetObjectType(startnum + j) != ObjectType::kFree)
+ if (GetObjectType(objnum) != ObjectType::kFree)
continue;
if (type == ObjectType::kFree) {
- m_CrossRefTable->SetFree(startnum + j);
- } else {
- const uint32_t entry_value =
- GetVarInt(entrystart + WidthArray[0], WidthArray[1]);
- if (type == ObjectType::kNotCompressed) {
- const uint32_t offset = entry_value;
- if (pdfium::base::IsValueInRangeForNumericType<FX_FILESIZE>(offset))
- m_CrossRefTable->AddNormal(startnum + j, 0, offset);
- } else {
- ASSERT(type == ObjectType::kCompressed);
- const uint32_t archive_obj_num = entry_value;
- if (!IsValidObjectNumber(archive_obj_num))
- return false;
-
- m_CrossRefTable->AddCompressed(startnum + j, archive_obj_num);
- }
+ m_CrossRefTable->SetFree(objnum);
+ continue;
}
+
+ const uint32_t entry_value =
+ GetVarInt(entrystart + WidthArray[0], WidthArray[1]);
+ if (type == ObjectType::kNotCompressed) {
+ const uint32_t offset = entry_value;
+ if (pdfium::base::IsValueInRangeForNumericType<FX_FILESIZE>(offset))
+ m_CrossRefTable->AddNormal(objnum, 0, offset);
+ continue;
+ }
+
+ ASSERT(type == ObjectType::kCompressed);
+ const uint32_t archive_obj_num = entry_value;
+ if (!IsValidObjectNumber(archive_obj_num))
+ return false;
+
+ m_CrossRefTable->AddCompressed(objnum, archive_obj_num);
}
segindex += count;
}