summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.cpp13
-rw-r--r--fpdfsdk/pdfwindow/PWL_FontMap.cpp29
2 files changed, 14 insertions, 28 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() {
diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/pdfwindow/PWL_FontMap.cpp
index 9a2962cd56..a7c42698cd 100644
--- a/fpdfsdk/pdfwindow/PWL_FontMap.cpp
+++ b/fpdfsdk/pdfwindow/PWL_FontMap.cpp
@@ -55,32 +55,26 @@ CPDF_Document* CPWL_FontMap::GetDocument() {
m_pPDFDoc->CreateNewDoc();
}
}
-
return m_pPDFDoc.get();
}
CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
- if (nFontIndex >= 0 && nFontIndex < pdfium::CollectionSize<int32_t>(m_Data)) {
- if (m_Data[nFontIndex])
- return m_Data[nFontIndex]->pFont;
- }
+ if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex])
+ return m_Data[nFontIndex]->pFont;
+
return nullptr;
}
CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
- if (nFontIndex >= 0 && nFontIndex < pdfium::CollectionSize<int32_t>(m_Data)) {
- if (m_Data[nFontIndex])
- return m_Data[nFontIndex]->sFontName;
- }
+ if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex])
+ return m_Data[nFontIndex]->sFontName;
+
return CFX_ByteString();
}
bool CPWL_FontMap::KnowWord(int32_t nFontIndex, uint16_t word) {
- if (nFontIndex >= 0 && nFontIndex < pdfium::CollectionSize<int32_t>(m_Data)) {
- if (m_Data[nFontIndex])
- return CharCodeFromUnicode(nFontIndex, word) >= 0;
- }
- return false;
+ return pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex] &&
+ CharCodeFromUnicode(nFontIndex, word) >= 0;
}
int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
@@ -116,7 +110,7 @@ int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
}
int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
- if (nFontIndex < 0 || nFontIndex >= pdfium::CollectionSize<int32_t>(m_Data))
+ if (!pdfium::IndexInBounds(m_Data, nFontIndex))
return -1;
CPWL_FontMap_Data* pData = m_Data[nFontIndex].get();
@@ -284,10 +278,7 @@ CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
}
const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
- if (nIndex < 0 || nIndex >= pdfium::CollectionSize<int32_t>(m_Data))
- return nullptr;
-
- return m_Data[nIndex].get();
+ return pdfium::IndexInBounds(m_Data, nIndex) ? m_Data[nIndex].get() : nullptr;
}
int32_t CPWL_FontMap::GetNativeCharset() {