diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-14 15:53:36 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-15 00:03:38 +0000 |
commit | 193e6ca5e48ee99e620f0e7546f1407ba1a20323 (patch) | |
tree | 11d920c59a89247d28fe590d77ab6d6a9ce37a0c /fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | |
parent | cd5139a291113f177d3494990efbcaf388d1f3bf (diff) | |
download | pdfium-193e6ca5e48ee99e620f0e7546f1407ba1a20323.tar.xz |
Add IndexInBounds() convenience routine.
Avoid writing |Type| in CollectionSize<Type>() so that index
type can change without rewriting conditions.
Change-Id: I40c94ca39148b379908760ba9b861114b88af7bb
Reviewed-on: https://pdfium-review.googlesource.com/3056
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfxfa/cpdfxfa_context.cpp')
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
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<int>(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<int>(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<int>(m_XFAPageList)) { + if (pdfium::IndexInBounds(m_XFAPageList, page_index)) m_XFAPageList[page_index] = nullptr; - } } void CPDFXFA_Context::ClearChangeMark() { |