Make a couple small improvements to CPDF_FormField. - Reduce the scope of a variable in ResetField(). - Replace a pointer in ResetField() with a bool. - Remove a redundant call in GetValue(). Change-Id: I69e82c3e4c3d47fda48f3bb5ad0bfca4a08ca6d6 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/59940 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index 80fa65d..ff99ee6 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -180,14 +180,17 @@ if (pDV) csDValue = pDV->GetUnicodeText(); - const CPDF_Object* pV = - FPDF_GetFieldAttr(m_pDict.Get(), pdfium::form_fields::kV); WideString csValue; - if (pV) - csValue = pV->GetUnicodeText(); + { + // Limit the scope of |pV| because it may get invalidated below. + const CPDF_Object* pV = + FPDF_GetFieldAttr(m_pDict.Get(), pdfium::form_fields::kV); + if (pV) + csValue = pV->GetUnicodeText(); + } - const CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict.Get(), "RV"); - if (!pRV && (csDValue == csValue)) + bool bHasRV = !!FPDF_GetFieldAttr(m_pDict.Get(), "RV"); + if (!bHasRV && (csDValue == csValue)) return false; if (notify == NotificationOption::kNotify && @@ -200,7 +203,7 @@ return false; m_pDict->SetFor(pdfium::form_fields::kV, std::move(pClone)); - if (pRV) { + if (bHasRV) { m_pDict->SetFor("RV", pDV->Clone()); } } else { @@ -296,12 +299,8 @@ FPDF_GetFieldAttr(m_pDict.Get(), bDefault ? pdfium::form_fields::kDV : pdfium::form_fields::kV); if (!pValue) { - if (!bDefault) { - if (m_Type == kRichText) - pValue = FPDF_GetFieldAttr(m_pDict.Get(), pdfium::form_fields::kV); - if (!pValue && m_Type != kText) - pValue = FPDF_GetFieldAttr(m_pDict.Get(), pdfium::form_fields::kDV); - } + if (!bDefault && m_Type != kText) + pValue = FPDF_GetFieldAttr(m_pDict.Get(), pdfium::form_fields::kDV); if (!pValue) return WideString(); }