summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-07-22 15:04:26 -0700
committerTom Sepez <tsepez@chromium.org>2015-07-22 15:04:26 -0700
commit4eb4d7f6c707cc2c23c806aa540d055c8832b55d (patch)
tree43b7a7fac7b4ce08c287bfc03d09e5e1201e20d0 /core/src/fpdfapi/fpdf_parser
parent7cc97521db1e52d5927f5605de5f9a7102f8af40 (diff)
downloadpdfium-4eb4d7f6c707cc2c23c806aa540d055c8832b55d.tar.xz
Revert "Fix else-after-returns throughout pdfium."
This reverts commit 7cc97521db1e52d5927f5605de5f9a7102f8af40.
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.cpp150
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp3
5 files changed, 143 insertions, 111 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 47c08fb4a3..9736c3dc8e 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -311,8 +311,9 @@ 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 f630ea52da..0471250fd9 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
@@ -181,9 +181,10 @@ 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 c7d1dece25..a3e409df57 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;
-
- return NULL;
+ else
+ return NULL;
}
void CPDF_Object::SetString(const CFX_ByteString& str)
{
@@ -201,8 +201,7 @@ 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);
- }
- if (pOther->m_Type == PDFOBJ_REFERENCE) {
+ } else if (pOther->m_Type == PDFOBJ_REFERENCE) {
return IsIdentical(pOther->GetDirect());
}
return FALSE;
@@ -286,22 +285,27 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite
CPDF_StreamAcc acc;
acc.LoadAllData(pThis, TRUE);
FX_DWORD streamSize = acc.GetSize();
- CPDF_Dictionary* pDict = pThis->GetDict();
- if (pDict)
- pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict)->CloneInternal(bDirect, visited);
- return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
+ 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;
}
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);
- if (!pRef->GetDirect())
- return nullptr;
-
- return pRef->GetDirect()->CloneInternal(TRUE, visited);
+ 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);
}
- return new CPDF_Reference(pRef->m_pObjList, obj_num);
}
}
return NULL;
@@ -317,14 +321,12 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const
{
if (m_Type == PDFOBJ_STRING) {
return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap);
- }
- if (m_Type == PDFOBJ_STREAM) {
+ } else 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;
- }
- if (m_Type == PDFOBJ_NAME) {
+ } else if (m_Type == PDFOBJ_NAME) {
return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap);
}
return CFX_WideString();
@@ -425,7 +427,8 @@ CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const
CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
return p->GetString();
}
- return CFX_ByteString();
+ else
+ return CFX_ByteString();
}
CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const
{
@@ -433,7 +436,8 @@ CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const
CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
return p->GetConstString();
}
- return CFX_ByteStringC();
+ else
+ return CFX_ByteStringC();
}
int CPDF_Array::GetInteger(FX_DWORD i) const
{
@@ -454,13 +458,11 @@ 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) {
+ if (p == NULL) {
return NULL;
- }
- if (p->GetType() == PDFOBJ_DICTIONARY) {
+ } else if (p->GetType() == PDFOBJ_DICTIONARY) {
return (CPDF_Dictionary*)p;
- }
- if (p->GetType() == PDFOBJ_STREAM) {
+ } else if (p->GetType() == PDFOBJ_STREAM) {
return ((CPDF_Stream*)p)->GetDict();
}
return NULL;
@@ -602,19 +604,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();
- }
- return CFX_ByteString();
+ else
+ 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();
- }
- return CFX_ByteStringC();
+ else
+ return CFX_ByteStringC();
}
CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_CharMap* pCharMap) const
{
@@ -645,10 +647,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();
- }
- return CFX_ByteStringC(def);
+ else
+ return CFX_ByteStringC(def);
}
int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const
{
@@ -689,16 +691,14 @@ 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) {
- return nullptr;
- }
- if (p->GetType() == PDFOBJ_DICTIONARY) {
+ if (p == NULL) {
+ return NULL;
+ } else if (p->GetType() == PDFOBJ_DICTIONARY) {
return (CPDF_Dictionary*)p;
- }
- if (p->GetType() == PDFOBJ_STREAM) {
+ } else if (p->GetType() == PDFOBJ_STREAM) {
return ((CPDF_Stream*)p)->GetDict();
}
- return nullptr;
+ return NULL;
}
CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const
{
@@ -1269,11 +1269,12 @@ 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;
- }
- ((CPDF_Object*)value)->Destroy();
+ else
+ ((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 854be75ad4..f7174f7a72 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -1993,16 +1993,21 @@ CFX_ByteString CPDF_SyntaxParser::ReadHexString()
void CPDF_SyntaxParser::ToNextLine()
{
uint8_t ch;
- while (GetNextChar(ch)) {
+ while (1) {
+ if (!GetNextChar(ch)) {
+ return;
+ }
if (ch == '\n') {
- break;
+ return;
}
if (ch == '\r') {
GetNextChar(ch);
- if (ch != '\n') {
- --m_Pos;
+ if (ch == '\n') {
+ return;
+ } else {
+ m_Pos --;
+ return;
}
- break;
}
}
}
@@ -2074,13 +2079,20 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
return (CPDF_Object*)PDFOBJ_REFERENCE;
}
return new CPDF_Reference(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;
+ }
+ 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) {
@@ -2240,18 +2252,25 @@ 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;
}
- FX_DWORD objnum = FXSYS_atoi(word);
return new CPDF_Reference(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;
+ }
+ 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) {
@@ -3121,20 +3140,21 @@ FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints)
m_objs_array.RemoveAll();
}
return bRet;
- }
- 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();
+ }
+ m_arrayAcroforms.RemoveAll();
+ } else {
+ m_objs_array.RemoveAll();
+ m_objs_array.Append(new_objs_array);
+ }
+ return bRet;
}
- return bRet;
}
FX_BOOL CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints)
{
@@ -3188,14 +3208,16 @@ 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:
@@ -3739,9 +3761,10 @@ 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;
@@ -3776,6 +3799,9 @@ 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();
@@ -3929,8 +3955,7 @@ FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints)
m_Pos = xref_offset;
}
return TRUE;
- }
- if (nRet == -1) {
+ } else if (nRet == -1) {
m_docStatus = PDF_DATAAVAIL_ERROR;
}
return FALSE;
@@ -4033,10 +4058,11 @@ 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);
@@ -4269,8 +4295,9 @@ 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)
@@ -4336,14 +4363,15 @@ 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)
{
@@ -4353,10 +4381,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;
}
@@ -4511,14 +4539,15 @@ 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)
{
@@ -4575,15 +4604,16 @@ 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 = m_number_array.GetSize() - 1;
+ int32_t iHigh = iLen - 1;
+ int32_t iMid = 0;
while (iLow <= iHigh) {
- int32_t iMid = (iLow + iHigh) / 2;
+ iMid = (iLow + iHigh) / 2;
if (m_number_array.GetAt(iMid) == value) {
iNext = iMid;
return TRUE;
- }
- if (m_number_array.GetAt(iMid) > value) {
+ } else 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 4903312645..6d425de6f8 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -165,8 +165,7 @@ CFX_ByteStringC CPDF_SimpleParser::GetWord()
m_dwCurPos ++;
}
return CFX_ByteStringC(pStart, (FX_STRSIZE)(m_dwCurPos - (pStart - m_pData)));
- }
- if (dwSize == 1 && pStart[0] == '(') {
+ } else if (dwSize == 1 && pStart[0] == '(') {
int level = 1;
while (m_dwCurPos < m_dwSize) {
if (m_pData[m_dwCurPos] == ')') {