From 193e6ca5e48ee99e620f0e7546f1407ba1a20323 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 14 Mar 2017 15:53:36 -0700 Subject: Add IndexInBounds() convenience routine. Avoid writing |Type| in CollectionSize() so that index type can change without rewriting conditions. Change-Id: I40c94ca39148b379908760ba9b861114b88af7bb Reviewed-on: https://pdfium-review.googlesource.com/3056 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfapi/parser/cpdf_document.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_document.cpp') diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index ed88a4f82a..8ff9e66506 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -477,10 +477,10 @@ bool CPDF_Document::IsPageLoaded(int iPage) const { } CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { - if (iPage < 0 || iPage >= pdfium::CollectionSize(m_PageList)) + if (!pdfium::IndexInBounds(m_PageList, iPage)) return nullptr; - if (m_bLinearized && (iPage == m_iFirstPageNo)) { + if (m_bLinearized && iPage == m_iFirstPageNo) { if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(m_dwFirstPageObjNum))) { return pDict; @@ -586,7 +586,7 @@ int CPDF_Document::GetPageIndex(uint32_t objnum) { int found_index = FindPageIndex(pPages, &skip_count, objnum, &start_index); // Corrupt page tree may yield out-of-range results. - if (found_index < 0 || found_index >= pdfium::CollectionSize(m_PageList)) + if (!pdfium::IndexInBounds(m_PageList, found_index)) return -1; m_PageList[found_index] = objnum; -- cgit v1.2.3