summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp5
-rw-r--r--core/fpdfapi/font/ttgsubtable.cpp6
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectlist.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp6
-rw-r--r--core/fpdftext/cpdf_textpage.cpp10
-rw-r--r--core/fxcodec/lgif/fx_gif.cpp6
-rw-r--r--core/fxcrt/fx_arabic.cpp8
7 files changed, 17 insertions, 28 deletions
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 7988ec7124..f0b5ac16b7 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -458,10 +458,9 @@ uint32_t CPDF_Font::FallbackFontFromCharcode(uint32_t charcode) {
}
int CPDF_Font::FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode) {
- if (fallbackFont < 0 ||
- fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) {
+ if (!pdfium::IndexInBounds(m_FontFallbacks, fallbackFont))
return -1;
- }
+
int glyph =
FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode);
if (glyph == 0 || glyph == 0xffff)
diff --git a/core/fpdfapi/font/ttgsubtable.cpp b/core/fpdfapi/font/ttgsubtable.cpp
index 946ccd7abe..4fae5d41d2 100644
--- a/core/fpdfapi/font/ttgsubtable.cpp
+++ b/core/fpdfapi/font/ttgsubtable.cpp
@@ -127,9 +127,8 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub(uint32_t glyphnum,
uint32_t* vglyphnum,
TFeature* Feature) {
for (int index : Feature->LookupListIndices) {
- if (index < 0 || index >= pdfium::CollectionSize<int>(LookupList.Lookups))
+ if (!pdfium::IndexInBounds(LookupList.Lookups, index))
continue;
-
if (LookupList.Lookups[index].LookupType == 1 &&
GetVerticalGlyphSub2(glyphnum, vglyphnum, &LookupList.Lookups[index])) {
return true;
@@ -154,8 +153,7 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum,
case 2: {
auto* tbl2 = static_cast<TSingleSubstFormat2*>(subTable.get());
int index = GetCoverageIndex(tbl2->Coverage.get(), glyphnum);
- if (index >= 0 &&
- index < pdfium::CollectionSize<int>(tbl2->Substitutes)) {
+ if (pdfium::IndexInBounds(tbl2->Substitutes, index)) {
*vglyphnum = tbl2->Substitutes[index];
return true;
}
diff --git a/core/fpdfapi/page/cpdf_pageobjectlist.cpp b/core/fpdfapi/page/cpdf_pageobjectlist.cpp
index 02b590e413..5c30fe9877 100644
--- a/core/fpdfapi/page/cpdf_pageobjectlist.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectlist.cpp
@@ -10,7 +10,5 @@
#include "third_party/base/stl_util.h"
CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) {
- if (index < 0 || index >= pdfium::CollectionSize<int>(*this))
- return nullptr;
- return (*this)[index].get();
+ return pdfium::IndexInBounds(*this, index) ? (*this)[index].get() : nullptr;
}
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<int>(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<int>(m_PageList))
+ if (!pdfium::IndexInBounds(m_PageList, found_index))
return -1;
m_PageList[found_index] = objnum;
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 7a89b24171..1eab19f4f1 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -378,10 +378,7 @@ CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const {
}
void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const {
- if (!m_bIsParsed)
- return;
-
- if (index < 0 || index >= pdfium::CollectionSize<int>(m_CharList))
+ if (!m_bIsParsed || !pdfium::IndexInBounds(m_CharList, index))
return;
const PAGECHAR_INFO& charinfo = m_CharList[index];
@@ -496,10 +493,7 @@ void CPDF_TextPage::GetRect(int rectIndex,
float& top,
float& right,
float& bottom) const {
- if (!m_bIsParsed)
- return;
-
- if (rectIndex < 0 || rectIndex >= pdfium::CollectionSize<int>(m_SelRects))
+ if (!m_bIsParsed || !pdfium::IndexInBounds(m_SelRects, rectIndex))
return;
left = m_SelRects[rectIndex].left;
diff --git a/core/fxcodec/lgif/fx_gif.cpp b/core/fxcodec/lgif/fx_gif.cpp
index c4661b0acd..c109b6193d 100644
--- a/core/fxcodec/lgif/fx_gif.cpp
+++ b/core/fxcodec/lgif/fx_gif.cpp
@@ -841,11 +841,11 @@ int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) {
gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
return 1;
}
+
int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) {
- if (!gif_ptr || frame_num < 0 ||
- frame_num >= pdfium::CollectionSize<int>(*gif_ptr->img_ptr_arr_ptr)) {
+ if (!gif_ptr || !pdfium::IndexInBounds(*gif_ptr->img_ptr_arr_ptr, frame_num))
return 0;
- }
+
uint8_t* data_size_ptr = nullptr;
uint8_t* data_ptr = nullptr;
uint32_t skip_size_org = gif_ptr->skip_size;
diff --git a/core/fxcrt/fx_arabic.cpp b/core/fxcrt/fx_arabic.cpp
index 103271cd02..76f2e38663 100644
--- a/core/fxcrt/fx_arabic.cpp
+++ b/core/fxcrt/fx_arabic.cpp
@@ -415,9 +415,9 @@ class CFX_BidiLineTemplate {
void FX_BidiReverseString(std::vector<CFX_Char>& chars,
int32_t iStart,
int32_t iCount) {
- ASSERT(iStart >= 0 && iStart < pdfium::CollectionSize<int32_t>(chars));
- ASSERT(iCount >= 0 &&
- iStart + iCount <= pdfium::CollectionSize<int32_t>(chars));
+ ASSERT(pdfium::IndexInBounds(chars, iStart));
+ ASSERT(pdfium::IndexInBounds(chars, iCount));
+ ASSERT(iStart + iCount <= pdfium::CollectionSize<int32_t>(chars));
std::reverse(chars.begin() + iStart, chars.begin() + iStart + iCount);
}
@@ -426,7 +426,7 @@ class CFX_BidiLineTemplate {
int32_t iStart,
int32_t iCount,
int32_t iValue) {
- ASSERT(iStart >= 0 && iStart <= pdfium::CollectionSize<int32_t>(chars));
+ ASSERT(pdfium::IndexInBounds(chars, iStart));
ASSERT(iStart - iCount > -1);
int32_t iLast = iStart - iCount;
if (bClass) {