summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-14 19:24:06 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-14 19:24:06 +0000
commit8c068b396dedc7d29ba7c107f03b2663520c11f1 (patch)
tree1aec18433367ef5eede3d07203191178789c986c
parent46b437333e53295869afde696ed31043c1f6c717 (diff)
downloadpdfium-8c068b396dedc7d29ba7c107f03b2663520c11f1.tar.xz
Remove default level from FPDF_GetFieldAttr().
Make call into internal helper function. Write helper function so as to be obviously tail-recursive, and remove redundant null check. Change-Id: If29f9be66b07239b35de9ac9241d5ef72365889b Reviewed-on: https://pdfium-review.googlesource.com/40130 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp37
-rw-r--r--core/fpdfdoc/cpdf_formfield.h7
2 files changed, 22 insertions, 22 deletions
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index c88513d50f..678a66acaf 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -43,6 +43,21 @@ bool IsUnison(CPDF_FormField* pField) {
return (pField->GetFieldFlags() & 0x2000000) != 0;
}
+const CPDF_Object* FPDF_GetFieldAttrRecursive(const CPDF_Dictionary* pFieldDict,
+ const char* name,
+ int nLevel) {
+ static constexpr int kGetFieldMaxRecursion = 32;
+ if (!pFieldDict || nLevel > kGetFieldMaxRecursion)
+ return nullptr;
+
+ const CPDF_Object* pAttr = pFieldDict->GetDirectObjectFor(name);
+ if (pAttr)
+ return pAttr;
+
+ return FPDF_GetFieldAttrRecursive(pFieldDict->GetDictFor("Parent"), name,
+ nLevel + 1);
+}
+
} // namespace
Optional<FormFieldType> IntToFormFieldType(int value) {
@@ -54,25 +69,13 @@ Optional<FormFieldType> IntToFormFieldType(int value) {
}
const CPDF_Object* FPDF_GetFieldAttr(const CPDF_Dictionary* pFieldDict,
- const char* name,
- int nLevel) {
- static constexpr int kGetFieldMaxRecursion = 32;
- if (!pFieldDict || nLevel > kGetFieldMaxRecursion)
- return nullptr;
-
- const CPDF_Object* pAttr = pFieldDict->GetDirectObjectFor(name);
- if (pAttr)
- return pAttr;
-
- const CPDF_Dictionary* pParent = pFieldDict->GetDictFor("Parent");
- return pParent ? FPDF_GetFieldAttr(pParent, name, nLevel + 1) : nullptr;
+ const char* name) {
+ return FPDF_GetFieldAttrRecursive(pFieldDict, name, 0);
}
-CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict,
- const char* name,
- int nLevel) {
- return const_cast<CPDF_Object*>(FPDF_GetFieldAttr(
- static_cast<const CPDF_Dictionary*>(pFieldDict), name, nLevel));
+CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, const char* name) {
+ return const_cast<CPDF_Object*>(FPDF_GetFieldAttrRecursive(
+ static_cast<const CPDF_Dictionary*>(pFieldDict), name, 0));
}
WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) {
diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h
index b6a4ed82a9..6f0006506f 100644
--- a/core/fpdfdoc/cpdf_formfield.h
+++ b/core/fpdfdoc/cpdf_formfield.h
@@ -80,11 +80,8 @@ class CPDF_InterForm;
class CPDF_String;
const CPDF_Object* FPDF_GetFieldAttr(const CPDF_Dictionary* pFieldDict,
- const char* name,
- int nLevel = 0);
-CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict,
- const char* name,
- int nLevel = 0);
+ const char* name);
+CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, const char* name);
WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict);