summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-11-04 18:04:03 -0800
committerLei Zhang <thestig@chromium.org>2015-11-04 18:04:03 -0800
commitff5adbc0dfa71270a9979f0c3e1d27923c16218a (patch)
treec68169974c3d747d30f925c1ace74d7bc9fb774c /fpdfsdk/src
parent4544797e8998a31e7bc3f5439a5982f7f66dff26 (diff)
downloadpdfium-ff5adbc0dfa71270a9979f0c3e1d27923c16218a.tar.xz
Cleanup: Remove some NULL checks in fpdfsdk.
And simplify code. R=ochang@chromium.org Review URL: https://codereview.chromium.org/1411663013 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/formfiller/FFL_IFormFiller.cpp2
-rw-r--r--fpdfsdk/src/fpdfeditpage.cpp42
-rw-r--r--fpdfsdk/src/fsdk_baseform.cpp18
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp22
4 files changed, 34 insertions, 50 deletions
diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
index 2126c2a903..92a44eb65e 100644
--- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
@@ -565,7 +565,7 @@ CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot,
}
void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot) {
- if (pAnnot != NULL) {
+ if (pAnnot) {
UnRegisterFormFiller(pAnnot);
}
}
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index c0576ae59c..ff175d6c14 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -93,37 +93,21 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
return -1;
}
CPDF_Dictionary* pDict = pPage->m_pFormDict;
+ if (!pDict)
+ return -1;
- int rotate = 0;
- if (pDict != NULL) {
- if (pDict->KeyExist("Rotate"))
- rotate = pDict->GetElement("Rotate")->GetDirect()
- ? pDict->GetElement("Rotate")->GetDirect()->GetInteger() / 90
- : 0;
- else {
- if (pDict->KeyExist("Parent")) {
- CPDF_Dictionary* pPages =
- ToDictionary(pDict->GetElement("Parent")->GetDirect());
- while (pPages) {
- if (pPages->KeyExist("Rotate")) {
- rotate =
- pPages->GetElement("Rotate")->GetDirect()
- ? pPages->GetElement("Rotate")->GetDirect()->GetInteger() /
- 90
- : 0;
- break;
- } else if (pPages->KeyExist("Parent"))
- pPages = ToDictionary(pPages->GetElement("Parent")->GetDirect());
- else
- break;
- }
- }
+ while (pDict) {
+ if (pDict->KeyExist("Rotate")) {
+ CPDF_Object* pRotateObj = pDict->GetElement("Rotate")->GetDirect();
+ return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
}
- } else {
- return -1;
+ if (!pDict->KeyExist("Parent"))
+ break;
+
+ pDict = ToDictionary(pDict->GetElement("Parent")->GetDirect());
}
- return rotate;
+ return 0;
}
DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
@@ -136,7 +120,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
return;
}
CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj;
- if (pPageObj == NULL)
+ if (!pPageObj)
return;
FX_POSITION LastPersition = pPage->GetLastObjectPosition();
@@ -259,7 +243,7 @@ DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
double e,
double f) {
CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object;
- if (pPageObj == NULL)
+ if (!pPageObj)
return;
CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index 9a20e48e84..bc2d137d70 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -1806,7 +1806,7 @@ CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
bFormated = FALSE;
CPDF_AAction aAction = pFormField->GetAdditionalAction();
- if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) {
+ if (aAction && aAction.ActionExist(CPDF_AAction::Format)) {
CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
if (action) {
CFX_WideString script = action.GetJavaScript();
@@ -1876,7 +1876,7 @@ void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
ASSERT(pFormField != NULL);
CPDF_AAction aAction = pFormField->GetAdditionalAction();
- if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke)) {
+ if (aAction && aAction.ActionExist(CPDF_AAction::KeyStroke)) {
CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
if (action) {
ASSERT(m_pDocument != NULL);
@@ -1904,7 +1904,7 @@ void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
ASSERT(pFormField != NULL);
CPDF_AAction aAction = pFormField->GetAdditionalAction();
- if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate)) {
+ if (aAction && aAction.ActionExist(CPDF_AAction::Validate)) {
CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
if (action) {
ASSERT(m_pDocument != NULL);
@@ -2038,19 +2038,19 @@ FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
if (pFDF) {
CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
- if (pMainDict == NULL)
+ if (!pMainDict)
return FALSE;
// Get fields
CPDF_Array* pFields = pMainDict->GetArray("Fields");
- if (pFields == NULL)
+ if (!pFields)
return FALSE;
CFX_ByteTextBuf fdfEncodedData;
for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
CPDF_Dictionary* pField = pFields->GetDict(i);
- if (pField == NULL)
+ if (!pField)
continue;
CFX_WideString name;
name = pField->GetUnicodeText("T");
@@ -2106,14 +2106,14 @@ FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
ASSERT(pEnv != NULL);
- if (NULL == m_pDocument)
+ if (!m_pDocument)
return FALSE;
CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
- if (NULL == m_pInterForm)
+ if (!m_pInterForm)
return FALSE;
CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
- if (NULL == pFDFDoc)
+ if (!pFDFDoc)
return FALSE;
CFX_ByteTextBuf FdfBuffer;
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index e898214cd8..92b47666e2 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -366,20 +366,20 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
while (*p) {
const char* pTemp = strchr(p, ch);
- if (pTemp == NULL) {
+ if (!pTemp) {
StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(p).c_str()));
break;
- } else {
- char* pSub = new char[pTemp - p + 1];
- strncpy(pSub, p, pTemp - p);
- *(pSub + (pTemp - p)) = '\0';
+ }
- StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str()));
- delete[] pSub;
+ char* pSub = new char[pTemp - p + 1];
+ strncpy(pSub, p, pTemp - p);
+ *(pSub + (pTemp - p)) = '\0';
- nIndex++;
- p = ++pTemp;
- }
+ StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str()));
+ delete[] pSub;
+
+ nIndex++;
+ p = ++pTemp;
}
return StrArray;
}
@@ -1804,7 +1804,7 @@ FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc,
}
CFX_WideString swValue;
- if (pEventHandler->m_pValue != NULL)
+ if (pEventHandler->m_pValue)
swValue = pEventHandler->Value();
if (pEventHandler->WillCommit()) {