summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-13 14:36:52 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-13 14:36:52 +0000
commit9a3a077e4820efa035eca4aec7e93fbd1298d6cb (patch)
tree682e7861f7d7148e3b0d24646397d226e9262366
parentaa123edaf307ac238f3aa79d951ea4b991c1f7aa (diff)
downloadpdfium-9a3a077e4820efa035eca4aec7e93fbd1298d6cb.tar.xz
Use size_t in CXML_Element and callers.
Change-Id: I9ebacd18252a837f1f5f13ccaec19b196bacc3ae Reviewed-on: https://pdfium-review.googlesource.com/21072 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fxcrt/xml/cxml_element.cpp20
-rw-r--r--core/fxcrt/xml/cxml_element.h14
-rw-r--r--fpdfsdk/fpdf_ext.cpp9
-rw-r--r--fpdfsdk/pwl/cpwl_edit.cpp8
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale.cpp6
5 files changed, 27 insertions, 30 deletions
diff --git a/core/fxcrt/xml/cxml_element.cpp b/core/fxcrt/xml/cxml_element.cpp
index 9d3e22c8f9..f11fd1fe14 100644
--- a/core/fxcrt/xml/cxml_element.cpp
+++ b/core/fxcrt/xml/cxml_element.cpp
@@ -53,11 +53,11 @@ ByteString CXML_Element::GetNamespaceURI(const ByteString& qName) const {
return pwsSpace ? pwsSpace->UTF8Encode() : ByteString();
}
-void CXML_Element::GetAttrByIndex(int index,
+void CXML_Element::GetAttrByIndex(size_t index,
ByteString* space,
ByteString* name,
WideString* value) const {
- if (index < 0 || index >= m_AttrMap.GetSize())
+ if (index >= static_cast<size_t>(m_AttrMap.GetSize()))
return;
CXML_AttrItem& item = m_AttrMap.GetAt(index);
@@ -89,9 +89,9 @@ int CXML_Element::GetAttrInteger(const ByteStringView& name) const {
return pwsValue ? pwsValue->GetInteger() : 0;
}
-uint32_t CXML_Element::CountElements(const ByteStringView& space,
- const ByteStringView& tag) const {
- int count = 0;
+size_t CXML_Element::CountElements(const ByteStringView& space,
+ const ByteStringView& tag) const {
+ size_t count = 0;
for (const auto& pChild : m_Children) {
const CXML_Element* pKid = pChild->AsElement();
if (pKid && pKid->m_TagName == tag &&
@@ -102,22 +102,20 @@ uint32_t CXML_Element::CountElements(const ByteStringView& space,
return count;
}
-CXML_Object* CXML_Element::GetChild(uint32_t index) const {
+CXML_Object* CXML_Element::GetChild(size_t index) const {
return index < m_Children.size() ? m_Children[index].get() : nullptr;
}
CXML_Element* CXML_Element::GetElement(const ByteStringView& space,
const ByteStringView& tag,
- int nth) const {
- if (nth < 0)
- return nullptr;
-
+ size_t nth) const {
for (const auto& pChild : m_Children) {
CXML_Element* pKid = pChild->AsElement();
if (pKid && pKid->m_TagName == tag &&
(space.IsEmpty() || pKid->m_QSpaceName == space)) {
- if (nth-- == 0)
+ if (nth == 0)
return pKid;
+ --nth;
}
}
return nullptr;
diff --git a/core/fxcrt/xml/cxml_element.h b/core/fxcrt/xml/cxml_element.h
index 5c4d24d661..db9a214c17 100644
--- a/core/fxcrt/xml/cxml_element.h
+++ b/core/fxcrt/xml/cxml_element.h
@@ -30,8 +30,8 @@ class CXML_Element : public CXML_Object {
ByteString GetTagName() const;
ByteString GetNamespaceURI(const ByteString& qName) const;
const CXML_Element* GetParent() const { return m_pParent.Get(); }
- uint32_t CountAttrs() const { return m_AttrMap.GetSize(); }
- void GetAttrByIndex(int index,
+ size_t CountAttrs() const { return m_AttrMap.GetSize(); }
+ void GetAttrByIndex(size_t index,
ByteString* space,
ByteString* name,
WideString* value) const;
@@ -43,13 +43,13 @@ class CXML_Element : public CXML_Object {
m_Children.push_back(std::move(child));
}
- uint32_t CountChildren() const { return m_Children.size(); }
- uint32_t CountElements(const ByteStringView& space,
- const ByteStringView& tag) const;
- CXML_Object* GetChild(uint32_t index) const;
+ size_t CountChildren() const { return m_Children.size(); }
+ size_t CountElements(const ByteStringView& space,
+ const ByteStringView& tag) const;
+ CXML_Object* GetChild(size_t index) const;
CXML_Element* GetElement(const ByteStringView& space,
const ByteStringView& tag,
- int nth) const;
+ size_t nth) const;
void SetAttribute(const ByteString& space,
const ByteString& name,
diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp
index 1e39f2b2c9..87605cfad6 100644
--- a/fpdfsdk/fpdf_ext.cpp
+++ b/fpdfsdk/fpdf_ext.cpp
@@ -76,9 +76,8 @@ void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) {
}
bool CheckSharedForm(const CXML_Element* pElement, ByteString cbName) {
- int count = pElement->CountAttrs();
- int i = 0;
- for (i = 0; i < count; i++) {
+ size_t count = pElement->CountAttrs();
+ for (size_t i = 0; i < count; ++i) {
ByteString space;
ByteString name;
WideString value;
@@ -106,8 +105,8 @@ bool CheckSharedForm(const CXML_Element* pElement, ByteString cbName) {
}
}
- uint32_t nCount = pElement->CountChildren();
- for (i = 0; i < (int)nCount; i++) {
+ size_t nCount = pElement->CountChildren();
+ for (size_t i = 0; i < nCount; ++i) {
CXML_Element* pChild = ToElement(pElement->GetChild(i));
if (pChild && CheckSharedForm(pChild, cbName))
return true;
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index 650db5438b..f2ed03dea4 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -56,15 +56,15 @@ void CPWL_Edit::SetText(const WideString& csText) {
swText.clear();
bool bFirst = true;
- int32_t nCount = pXML->CountChildren();
- for (int32_t i = 0; i < nCount; i++) {
+ size_t nCount = pXML->CountChildren();
+ for (size_t i = 0; i < nCount; ++i) {
CXML_Element* pSubElement = ToElement(pXML->GetChild(i));
if (!pSubElement || !pSubElement->GetTagName().EqualNoCase("p"))
continue;
WideString swSection;
- int nSubChild = pSubElement->CountChildren();
- for (int32_t j = 0; j < nSubChild; j++) {
+ size_t nSubChild = pSubElement->CountChildren();
+ for (size_t j = 0; j < nSubChild; ++j) {
CXML_Content* pSubContent = ToContent(pSubElement->GetChild(j));
if (pSubContent)
swSection += pSubContent->m_Content;
diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp
index f9e4353dca..659c7bbefe 100644
--- a/xfa/fxfa/parser/cxfa_xmllocale.cpp
+++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp
@@ -109,7 +109,7 @@ WideString CXFA_XMLLocale::GetEraName(bool bAD) const {
WideString CXFA_XMLLocale::GetCalendarSymbol(const ByteStringView& symbol,
int index,
bool bAbbr) const {
- if (!m_pLocaleData)
+ if (index < 0 || !m_pLocaleData)
return WideString();
CXML_Element* pChild = m_pLocaleData->GetElement("", "calendarSymbols", 0);
@@ -195,8 +195,8 @@ WideString CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType) const {
WideString CXFA_XMLLocale::GetPattern(CXML_Element* pElement,
const ByteStringView& bsTag,
const WideStringView& wsName) const {
- int32_t iCount = pElement->CountElements("", bsTag);
- for (int32_t i = 0; i < iCount; i++) {
+ size_t iCount = pElement->CountElements("", bsTag);
+ for (size_t i = 0; i < iCount; i++) {
CXML_Element* pChild = pElement->GetElement("", bsTag, i);
if (pChild->GetAttrValue("name") == wsName) {
CXML_Content* pContent = ToContent(pChild->GetChild(0));