summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-14 15:53:36 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-15 00:03:38 +0000
commit193e6ca5e48ee99e620f0e7546f1407ba1a20323 (patch)
tree11d920c59a89247d28fe590d77ab6d6a9ce37a0c /xfa
parentcd5139a291113f177d3494990efbcaf388d1f3bf (diff)
downloadpdfium-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 'xfa')
-rw-r--r--xfa/fde/tto/fde_textout.cpp5
-rw-r--r--xfa/fde/xml/fde_xml_imp.cpp8
-rw-r--r--xfa/fgas/layout/cfx_breakline.cpp4
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.cpp3
-rw-r--r--xfa/fgas/layout/fgas_textbreak.cpp7
5 files changed, 11 insertions, 16 deletions
diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp
index c9f5ec84ef..f816176841 100644
--- a/xfa/fde/tto/fde_textout.cpp
+++ b/xfa/fde/tto/fde_textout.cpp
@@ -775,10 +775,7 @@ int32_t CFDE_TTOLine::GetSize() const {
}
FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) {
- if (index < 0 || index >= pdfium::CollectionSize<int32_t>(m_pieces))
- return nullptr;
-
- return &m_pieces[index];
+ return pdfium::IndexInBounds(m_pieces, index) ? &m_pieces[index] : nullptr;
}
void CFDE_TTOLine::RemoveLast(int32_t icount) {
diff --git a/xfa/fde/xml/fde_xml_imp.cpp b/xfa/fde/xml/fde_xml_imp.cpp
index 0959661b26..334410049c 100644
--- a/xfa/fde/xml/fde_xml_imp.cpp
+++ b/xfa/fde/xml/fde_xml_imp.cpp
@@ -652,7 +652,7 @@ int32_t CFDE_XMLInstruction::CountData() const {
}
bool CFDE_XMLInstruction::GetData(int32_t index, CFX_WideString& wsData) const {
- if (index < 0 || index >= pdfium::CollectionSize<int32_t>(m_TargetData))
+ if (!pdfium::IndexInBounds(m_TargetData, index))
return false;
wsData = m_TargetData[index];
@@ -664,10 +664,8 @@ void CFDE_XMLInstruction::AppendData(const CFX_WideString& wsData) {
}
void CFDE_XMLInstruction::RemoveData(int32_t index) {
- if (index < 0 || index >= pdfium::CollectionSize<int32_t>(m_TargetData))
- return;
-
- m_TargetData.erase(m_TargetData.begin() + index);
+ if (pdfium::IndexInBounds(m_TargetData, index))
+ m_TargetData.erase(m_TargetData.begin() + index);
}
CFDE_XMLInstruction::~CFDE_XMLInstruction() {}
diff --git a/xfa/fgas/layout/cfx_breakline.cpp b/xfa/fgas/layout/cfx_breakline.cpp
index 65860e4013..562f984ffe 100644
--- a/xfa/fgas/layout/cfx_breakline.cpp
+++ b/xfa/fgas/layout/cfx_breakline.cpp
@@ -17,12 +17,12 @@ int32_t CFX_BreakLine::CountChars() const {
}
CFX_Char* CFX_BreakLine::GetChar(int32_t index) {
- ASSERT(index >= 0 && index < pdfium::CollectionSize<int32_t>(m_LineChars));
+ ASSERT(pdfium::IndexInBounds(m_LineChars, index));
return &m_LineChars[index];
}
const CFX_Char* CFX_BreakLine::GetChar(int32_t index) const {
- ASSERT(index >= 0 && index < pdfium::CollectionSize<int32_t>(m_LineChars));
+ ASSERT(pdfium::IndexInBounds(m_LineChars, index));
return &m_LineChars[index];
}
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp
index 37822140c3..68c04a7f64 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.cpp
+++ b/xfa/fgas/layout/fgas_rtfbreak.cpp
@@ -805,8 +805,9 @@ const CFX_BreakPiece* CFX_RTFBreak::GetBreakPieceUnstable(int32_t index) const {
const std::vector<CFX_BreakPiece>& pRTFPieces =
m_RTFLine[m_iReadyLineIndex].m_LinePieces;
- if (index < 0 || index >= pdfium::CollectionSize<int32_t>(pRTFPieces))
+ if (!pdfium::IndexInBounds(pRTFPieces, index))
return nullptr;
+
return &pRTFPieces[index];
}
diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp
index 8bba780382..c42de45411 100644
--- a/xfa/fgas/layout/fgas_textbreak.cpp
+++ b/xfa/fgas/layout/fgas_textbreak.cpp
@@ -796,11 +796,10 @@ int32_t CFX_TxtBreak::CountBreakPieces() const {
const CFX_BreakPiece* CFX_TxtBreak::GetBreakPiece(int32_t index) const {
if (!HasTxtLine())
return nullptr;
- if (index < 0 ||
- index >= pdfium::CollectionSize<int32_t>(
- m_TxtLine[m_iReadyLineIndex].m_LinePieces)) {
+
+ if (!pdfium::IndexInBounds(m_TxtLine[m_iReadyLineIndex].m_LinePieces, index))
return nullptr;
- }
+
return &m_TxtLine[m_iReadyLineIndex].m_LinePieces[index];
}