summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-07-23 14:42:09 -0700
committerTom Sepez <tsepez@chromium.org>2015-07-23 14:42:09 -0700
commit2f2ffece124e4ed4b96d2846263015d4b5ad6c00 (patch)
tree6966e44279e8d9e1516b7c71219cf66f77a89ca2 /core/src/fpdfapi/fpdf_parser
parentd07958fd2d1c4134d865f4ccb056eb925aaa7d2a (diff)
downloadpdfium-2f2ffece124e4ed4b96d2846263015d4b5ad6c00.tar.xz
Merge to XFA - else after returns.
(cherry picked from commit 3c012fef2bb72c8ec1faa73e11ee35539b2559d6) Original Review URL: https://codereview.chromium.org/1243953004 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1239313005 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp9
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp89
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp157
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp3
5 files changed, 113 insertions, 148 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 9736c3dc8e..47c08fb4a3 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -311,9 +311,8 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf, FX_DWORD src_size, const CPDF_Dic
dest_size = last_size;
pImageParms = pParam;
return TRUE;
- } else {
- offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pParam, estimated_size, new_buf, new_size);
}
+ offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pParam, estimated_size, new_buf, new_size);
} else if (decoder == FX_BSTRC("LZWDecode") || decoder == FX_BSTRC("LZW")) {
offset = FPDFAPI_FlateOrLZWDecode(TRUE, last_buf, last_size, pParam, estimated_size, new_buf, new_size);
} else if (decoder == FX_BSTRC("ASCII85Decode") || decoder == FX_BSTRC("A85")) {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
index 0471250fd9..f630ea52da 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
@@ -181,10 +181,9 @@ CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec)
result += ':';
result += ChangeSlash(wsFileName.c_str() + 2);
return result;
- } else {
- CFX_WideString result;
- result += '\\';
- result += ChangeSlash(wsFileName.c_str());
- return result;
}
+ CFX_WideString result;
+ result += '\\';
+ result += ChangeSlash(wsFileName.c_str());
+ return result;
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 190cb2d0f1..8162fff297 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -160,8 +160,8 @@ CPDF_Array* CPDF_Object::GetArray() const
{
if (m_Type == PDFOBJ_ARRAY)
return (CPDF_Array*)this;
- else
- return NULL;
+
+ return NULL;
}
void CPDF_Object::SetString(const CFX_ByteString& str)
{
@@ -201,7 +201,8 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const
if (pOther->m_Type != m_Type) {
if (m_Type == PDFOBJ_REFERENCE && GetDirect()) {
return GetDirect()->IsIdentical(pOther);
- } else if (pOther->m_Type == PDFOBJ_REFERENCE) {
+ }
+ if (pOther->m_Type == PDFOBJ_REFERENCE) {
return IsIdentical(pOther->GetDirect());
}
return FALSE;
@@ -285,27 +286,22 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite
CPDF_StreamAcc acc;
acc.LoadAllData(pThis, TRUE);
FX_DWORD streamSize = acc.GetSize();
- CPDF_Stream* pObj;
- if (pThis->GetDict())
- pObj = new CPDF_Stream(acc.DetachData(), streamSize, (CPDF_Dictionary*)((CPDF_Object*)pThis->GetDict())->CloneInternal(bDirect, visited));
- else
- pObj = new CPDF_Stream(acc.DetachData(), streamSize, NULL);
- return pObj;
+ CPDF_Dictionary* pDict = pThis->GetDict();
+ if (pDict)
+ pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict)->CloneInternal(bDirect, visited);
+ return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
}
case PDFOBJ_REFERENCE: {
CPDF_Reference* pRef = (CPDF_Reference*)this;
FX_DWORD obj_num = pRef->m_RefObjNum;
if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) {
visited->SetAt((void*)(uintptr_t)obj_num, (void*)1);
- CPDF_Object* ret;
- if (pRef->GetDirect())
- ret = pRef->GetDirect()->CloneInternal(TRUE, visited);
- else
- ret = NULL;
- return ret;
- } else {
- return new CPDF_Reference(pRef->m_pObjList, obj_num);
+ if (!pRef->GetDirect())
+ return nullptr;
+
+ return pRef->GetDirect()->CloneInternal(TRUE, visited);
}
+ return new CPDF_Reference(pRef->m_pObjList, obj_num);
}
}
return NULL;
@@ -321,12 +317,14 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const
{
if (m_Type == PDFOBJ_STRING) {
return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap);
- } else if (m_Type == PDFOBJ_STREAM) {
+ }
+ if (m_Type == PDFOBJ_STREAM) {
CPDF_StreamAcc stream;
stream.LoadAllData((CPDF_Stream*)this, FALSE);
CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap);
return result;
- } else if (m_Type == PDFOBJ_NAME) {
+ }
+ if (m_Type == PDFOBJ_NAME) {
return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap);
}
return CFX_WideString();
@@ -427,8 +425,7 @@ CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const
CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
return p->GetString();
}
- else
- return CFX_ByteString();
+ return CFX_ByteString();
}
CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const
{
@@ -436,8 +433,7 @@ CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const
CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
return p->GetConstString();
}
- else
- return CFX_ByteStringC();
+ return CFX_ByteStringC();
}
int CPDF_Array::GetInteger(FX_DWORD i) const
{
@@ -458,11 +454,13 @@ FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const
CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const
{
CPDF_Object* p = GetElementValue(i);
- if (p == NULL) {
+ if (!p) {
return NULL;
- } else if (p->GetType() == PDFOBJ_DICTIONARY) {
+ }
+ if (p->GetType() == PDFOBJ_DICTIONARY) {
return (CPDF_Dictionary*)p;
- } else if (p->GetType() == PDFOBJ_STREAM) {
+ }
+ if (p->GetType() == PDFOBJ_STREAM) {
return ((CPDF_Stream*)p)->GetDict();
}
return NULL;
@@ -604,19 +602,19 @@ CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const
{
CPDF_Object* p = NULL;
m_Map.Lookup(key, (void*&)p);
- if (p)
+ if (p) {
return p->GetString();
- else
- return CFX_ByteString();
+ }
+ return CFX_ByteString();
}
CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key) const
{
CPDF_Object* p = NULL;
m_Map.Lookup(key, (void*&)p);
- if (p)
+ if (p) {
return p->GetConstString();
- else
- return CFX_ByteStringC();
+ }
+ return CFX_ByteStringC();
}
CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_CharMap* pCharMap) const
{
@@ -647,10 +645,10 @@ CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key, cons
{
CPDF_Object* p = NULL;
m_Map.Lookup(key, (void*&)p);
- if (p)
+ if (p) {
return p->GetConstString();
- else
- return CFX_ByteStringC(def);
+ }
+ return CFX_ByteStringC(def);
}
int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const
{
@@ -691,14 +689,16 @@ FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key, FX_BOOL bDefault
CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const
{
CPDF_Object* p = GetElementValue(key);
- if (p == NULL) {
- return NULL;
- } else if (p->GetType() == PDFOBJ_DICTIONARY) {
+ if (!p) {
+ return nullptr;
+ }
+ if (p->GetType() == PDFOBJ_DICTIONARY) {
return (CPDF_Dictionary*)p;
- } else if (p->GetType() == PDFOBJ_STREAM) {
+ }
+ if (p->GetType() == PDFOBJ_STREAM) {
return ((CPDF_Stream*)p)->GetDict();
}
- return NULL;
+ return nullptr;
}
CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const
{
@@ -1270,12 +1270,11 @@ void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pO
}
void* value = NULL;
if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) {
- if (value)
- {
- if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum())
+ if (value) {
+ if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum()) {
return;
- else
- ((CPDF_Object*)value)->Destroy();
+ }
+ ((CPDF_Object*)value)->Destroy();
}
}
pObj->m_ObjNum = objnum;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 5e673b0829..e4d3571eee 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -1997,21 +1997,16 @@ CFX_ByteString CPDF_SyntaxParser::ReadHexString()
void CPDF_SyntaxParser::ToNextLine()
{
uint8_t ch;
- while (1) {
- if (!GetNextChar(ch)) {
- return;
- }
+ while (GetNextChar(ch)) {
if (ch == '\n') {
- return;
+ break;
}
if (ch == '\r') {
GetNextChar(ch);
- if (ch == '\n') {
- return;
- } else {
- m_Pos --;
- return;
+ if (ch != '\n') {
+ --m_Pos;
}
+ break;
}
}
}
@@ -2083,24 +2078,14 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
if (bTypeOnly) {
return (CPDF_Object*)PDFOBJ_REFERENCE;
}
- pRet = CPDF_Reference::Create(pObjList, objnum);
- return pRet;
- } else {
- m_Pos = SavedPos;
- if (bTypeOnly) {
- return (CPDF_Object*)PDFOBJ_NUMBER;
- }
- pRet = CPDF_Number::Create(word);
- return pRet;
+ return new CPDF_Reference(pObjList, objnum);
}
- } else {
- m_Pos = SavedPos;
- if (bTypeOnly) {
- return (CPDF_Object*)PDFOBJ_NUMBER;
- }
- pRet = CPDF_Number::Create(word);
- return pRet;
}
+ m_Pos = SavedPos;
+ if (bTypeOnly) {
+ return (CPDF_Object*)PDFOBJ_NUMBER;
+ }
+ return CPDF_Number::Create(word);
}
if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) {
if (bTypeOnly) {
@@ -2264,25 +2249,18 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
if (bIsNumber) {
CFX_ByteString nextword2 = GetNextWord(bIsNumber);
if (nextword2 == FX_BSTRC("R")) {
- FX_DWORD objnum = FXSYS_atoi(word);
if (bTypeOnly) {
return (CPDF_Object*)PDFOBJ_REFERENCE;
}
- return CPDF_Reference::Create(pObjList, objnum);
- } else {
- m_Pos = SavedPos;
- if (bTypeOnly) {
- return (CPDF_Object*)PDFOBJ_NUMBER;
- }
- return CPDF_Number::Create(word);
- }
- } else {
- m_Pos = SavedPos;
- if (bTypeOnly) {
- return (CPDF_Object*)PDFOBJ_NUMBER;
+ FX_DWORD objnum = FXSYS_atoi(word);
+ return new CPDF_Reference(pObjList, objnum);
}
- return CPDF_Number::Create(word);
}
+ m_Pos = SavedPos;
+ if (bTypeOnly) {
+ return (CPDF_Object*)PDFOBJ_NUMBER;
+ }
+ return CPDF_Number::Create(word);
}
if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) {
if (bTypeOnly) {
@@ -3152,21 +3130,20 @@ FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints)
m_objs_array.RemoveAll();
}
return bRet;
- } else {
- CFX_PtrArray new_objs_array;
- FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
- if (bRet) {
- int32_t iSize = m_arrayAcroforms.GetSize();
- for (int32_t i = 0; i < iSize; ++i) {
- ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release();
- }
- m_arrayAcroforms.RemoveAll();
- } else {
- m_objs_array.RemoveAll();
- m_objs_array.Append(new_objs_array);
+ }
+ CFX_PtrArray new_objs_array;
+ FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
+ if (bRet) {
+ int32_t iSize = m_arrayAcroforms.GetSize();
+ for (int32_t i = 0; i < iSize; ++i) {
+ ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release();
}
- return bRet;
+ m_arrayAcroforms.RemoveAll();
+ } else {
+ m_objs_array.RemoveAll();
+ m_objs_array.Append(new_objs_array);
}
+ return bRet;
}
FX_BOOL CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints)
{
@@ -3220,16 +3197,14 @@ FX_BOOL CPDF_DataAvail::CheckDocStatus(IFX_DownloadHints *pHints)
case PDF_DATAAVAIL_PAGETREE:
if (m_bTotalLoadPageTree) {
return CheckPages(pHints);
- } else {
- return LoadDocPages(pHints);
}
+ return LoadDocPages(pHints);
case PDF_DATAAVAIL_PAGE:
if (m_bTotalLoadPageTree) {
return CheckPage(pHints);
- } else {
- m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD;
- return TRUE;
}
+ m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD;
+ return TRUE;
case PDF_DATAAVAIL_ERROR:
return LoadAllFile(pHints);
case PDF_DATAAVAIL_PAGE_LATERLOAD:
@@ -3773,10 +3748,9 @@ FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints)
SetStartOffset(m_dwXRefOffset);
m_docStatus = PDF_DATAAVAIL_CROSSREF;
return TRUE;
- } else {
- m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
- return TRUE;
}
+ m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
+ return TRUE;
}
pHints->AddSegment(req_pos, dwSize);
return FALSE;
@@ -3811,9 +3785,6 @@ int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI
xref_offset = pObj->GetDict()->GetInteger(FX_BSTRC("Prev"));
pObj->Release();
return 1;
- } else {
- pObj->Release();
- return -1;
}
}
pObj->Release();
@@ -3967,7 +3938,8 @@ FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints)
m_Pos = xref_offset;
}
return TRUE;
- } else if (nRet == -1) {
+ }
+ if (nRet == -1) {
m_docStatus = PDF_DATAAVAIL_ERROR;
}
return FALSE;
@@ -4070,11 +4042,10 @@ FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints)
}
}
return TRUE;
- } else {
- m_dwPrevXRefOffset = 0;
- m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND;
- pTrailer->Release();
}
+ m_dwPrevXRefOffset = 0;
+ m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND;
+ pTrailer->Release();
return TRUE;
}
pHints->AddSegment(m_Pos, iTrailerSize);
@@ -4307,9 +4278,8 @@ FX_BOOL CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints)
if (CheckPageCount(pHints)) {
m_docStatus = PDF_DATAAVAIL_PAGE;
return TRUE;
- } else {
- m_bTotalLoadPageTree = TRUE;
}
+ m_bTotalLoadPageTree = TRUE;
return FALSE;
}
FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints)
@@ -4375,15 +4345,14 @@ FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, IFX_DownloadHints* pHints
m_objs_array.RemoveAll();
}
return bRet;
- } else {
- CFX_PtrArray new_objs_array;
- FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
- m_objs_array.RemoveAll();
- if (!bRet) {
- m_objs_array.Append(new_objs_array);
- }
- return bRet;
}
+ CFX_PtrArray new_objs_array;
+ FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
+ m_objs_array.RemoveAll();
+ if (!bRet) {
+ m_objs_array.Append(new_objs_array);
+ }
+ return bRet;
}
FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHints* pHints)
{
@@ -4393,10 +4362,10 @@ FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHint
}
m_bAnnotsLoad = TRUE;
}
- if (m_bAnnotsLoad)
- if (!CheckLinearizedData(pHints)) {
+ if (m_bAnnotsLoad) {
+ if (!CheckLinearizedData(pHints))
return FALSE;
- }
+ }
m_bPageLoadedOK = FALSE;
return TRUE;
}
@@ -4551,15 +4520,14 @@ FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints)
m_objs_array.RemoveAll();
}
return bRet;
- } else {
- CFX_PtrArray new_objs_array;
- FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
- m_objs_array.RemoveAll();
- if (!bRet) {
- m_objs_array.Append(new_objs_array);
- }
- return bRet;
}
+ CFX_PtrArray new_objs_array;
+ FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
+ m_objs_array.RemoveAll();
+ if (!bRet) {
+ m_objs_array.Append(new_objs_array);
+ }
+ return bRet;
}
void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize)
{
@@ -4616,16 +4584,15 @@ FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum)
}
FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext)
{
- int32_t iLen = m_number_array.GetSize();
int32_t iLow = 0;
- int32_t iHigh = iLen - 1;
- int32_t iMid = 0;
+ int32_t iHigh = m_number_array.GetSize() - 1;
while (iLow <= iHigh) {
- iMid = (iLow + iHigh) / 2;
+ int32_t iMid = (iLow + iHigh) / 2;
if (m_number_array.GetAt(iMid) == value) {
iNext = iMid;
return TRUE;
- } else if (m_number_array.GetAt(iMid) > value) {
+ }
+ if (m_number_array.GetAt(iMid) > value) {
iHigh = iMid - 1;
} else if (m_number_array.GetAt(iMid) < value) {
iLow = iMid + 1;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index 6d425de6f8..4903312645 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -165,7 +165,8 @@ CFX_ByteStringC CPDF_SimpleParser::GetWord()
m_dwCurPos ++;
}
return CFX_ByteStringC(pStart, (FX_STRSIZE)(m_dwCurPos - (pStart - m_pData)));
- } else if (dwSize == 1 && pStart[0] == '(') {
+ }
+ if (dwSize == 1 && pStart[0] == '(') {
int level = 1;
while (m_dwCurPos < m_dwSize) {
if (m_pData[m_dwCurPos] == ')') {