Simplify checks in newly added annotation APIs.
FormHandleToInteractiveForm() will check the FPDF_FORMHANDLE argument,
so there is no need to also explicitly check it.
Change-Id: I530f9f46c6ba5744999c8bcd033ca48adc284bb5
Reviewed-on: https://pdfium-review.googlesource.com/c/51151
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index e2d66e4..8ab2d84 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -916,7 +916,11 @@
FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetOptionCount(FPDF_FORMHANDLE hHandle,
FPDF_ANNOTATION annot) {
- if (!hHandle || !annot)
+ CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle);
+ if (!pForm)
+ return -1;
+
+ if (!annot)
return -1;
CPDF_Dictionary* pAnnotDict =
@@ -924,10 +928,6 @@
if (!pAnnotDict)
return -1;
- CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle);
- if (!pForm)
- return -1;
-
CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm();
CPDF_FormField* pFormField = pPDFForm->GetFieldByDict(pAnnotDict);
return pFormField ? pFormField->CountOptions() : -1;
@@ -939,7 +939,11 @@
int index,
void* buffer,
unsigned long buflen) {
- if (!hHandle || !annot || index < 0)
+ CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle);
+ if (!pForm)
+ return 0;
+
+ if (!annot || index < 0)
return 0;
CPDF_Dictionary* pAnnotDict =
@@ -947,10 +951,6 @@
if (!pAnnotDict)
return 0;
- CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle);
- if (!pForm)
- return 0;
-
CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm();
CPDF_FormField* pFormField = pPDFForm->GetFieldByDict(pAnnotDict);
if (!pFormField || index >= pFormField->CountOptions())