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 --- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'fpdfsdk/fpdfxfa') diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 88c88a1748..aaa0e9849b 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -172,10 +172,8 @@ CPDFXFA_Page* CPDFXFA_Context::GetXFAPage(int page_index) { pPage->Release(); return nullptr; } - if (page_index >= 0 && - page_index < pdfium::CollectionSize(m_XFAPageList)) { + if (pdfium::IndexInBounds(m_XFAPageList, page_index)) m_XFAPageList[page_index] = pPage; - } return pPage; } @@ -203,20 +201,17 @@ void CPDFXFA_Context::DeletePage(int page_index) { if (m_pPDFDoc) m_pPDFDoc->DeletePage(page_index); - if (page_index < 0 || - page_index >= pdfium::CollectionSize(m_XFAPageList)) { + if (!pdfium::IndexInBounds(m_XFAPageList, page_index)) return; - } + if (CPDFXFA_Page* pPage = m_XFAPageList[page_index]) pPage->Release(); } void CPDFXFA_Context::RemovePage(CPDFXFA_Page* page) { int page_index = page->GetPageIndex(); - if (page_index >= 0 && - page_index < pdfium::CollectionSize(m_XFAPageList)) { + if (pdfium::IndexInBounds(m_XFAPageList, page_index)) m_XFAPageList[page_index] = nullptr; - } } void CPDFXFA_Context::ClearChangeMark() { -- cgit v1.2.3