Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2390)

Unified Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1360103002: Get rid of gotos in CPDF_SyntaxParser and FlateUncompress(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/src/fxcodec/codec/fx_codec_flate.cpp » ('j') | core/src/fxcodec/codec/fx_codec_flate.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 7482f0b8e4fc12427b49cdc9752ad5003771310a..fa1ab9843ba55bd251dd5b8f6fb4329eb8c7530a 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -8,6 +8,7 @@
#include <utility>
#include <vector>
+#include "../../../../third_party/base/nonstd_unique_ptr.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_parser.h"
@@ -484,6 +485,7 @@ FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos,
m_Syntax.RestorePos(SavedPos + count * recordsize);
return TRUE;
}
+
FX_BOOL CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos,
FX_FILESIZE streampos,
FX_BOOL bSkip,
@@ -592,12 +594,11 @@ FX_BOOL CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos,
}
m_Syntax.RestorePos(SavedPos + count * recordsize);
}
- if (streampos)
- if (!LoadCrossRefV5(streampos, streampos, FALSE)) {
- return FALSE;
- }
+ if (streampos && !LoadCrossRefV5(streampos, streampos, FALSE))
Tom Sepez 2015/09/23 21:48:41 nit: maybe return !streampos || LoadCrossRefV5(..)
Lei Zhang 2015/09/25 09:33:48 Done.
+ return FALSE;
return TRUE;
}
+
FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) {
if (!LoadCrossRefV5(xrefpos, xrefpos, TRUE)) {
return FALSE;
@@ -2700,76 +2701,74 @@ FX_BOOL CPDF_SyntaxParser::SearchWord(const CFX_ByteStringC& tag,
}
return FALSE;
}
+
struct _SearchTagRecord {
const uint8_t* m_pTag;
FX_DWORD m_Len;
FX_DWORD m_Offset;
};
+
int32_t CPDF_SyntaxParser::SearchMultiWord(const CFX_ByteStringC& tags,
FX_BOOL bWholeWord,
FX_FILESIZE limit) {
- int32_t ntags = 1, i;
- for (i = 0; i < tags.GetLength(); i++)
+ int32_t ntags = 1;
+ for (int i = 0; i < tags.GetLength(); i++) {
if (tags[i] == 0) {
ntags++;
}
- _SearchTagRecord* pPatterns = FX_Alloc(_SearchTagRecord, ntags);
- FX_DWORD start = 0, itag = 0, max_len = 0;
- for (i = 0; i <= tags.GetLength(); i++) {
+ }
+ std::vector<_SearchTagRecord> patterns(ntags);
+ FX_DWORD start = 0;
+ FX_DWORD itag = 0;
+ FX_DWORD max_len = 0;
+ for (int i = 0; i <= tags.GetLength(); i++) {
if (tags[i] == 0) {
FX_DWORD len = i - start;
if (len > max_len) {
max_len = len;
}
- pPatterns[itag].m_pTag = tags.GetPtr() + start;
- pPatterns[itag].m_Len = len;
- pPatterns[itag].m_Offset = 0;
+ patterns[itag].m_pTag = tags.GetPtr() + start;
+ patterns[itag].m_Len = len;
+ patterns[itag].m_Offset = 0;
start = i + 1;
itag++;
}
}
- FX_FILESIZE pos = m_Pos;
uint8_t byte;
- GetCharAt(pos++, byte);
- int32_t found = -1;
- while (1) {
- for (i = 0; i < ntags; i++) {
- if (pPatterns[i].m_pTag[pPatterns[i].m_Offset] == byte) {
- pPatterns[i].m_Offset++;
- if (pPatterns[i].m_Offset == pPatterns[i].m_Len) {
+ GetCharAt(m_Pos, byte);
+ for (FX_FILESIZE pos = m_Pos + 1;; ++pos) {
+ for (int i = 0; i < ntags; i++) {
+ if (patterns[i].m_pTag[patterns[i].m_Offset] == byte) {
+ patterns[i].m_Offset++;
+ if (patterns[i].m_Offset == patterns[i].m_Len) {
if (!bWholeWord ||
- IsWholeWord(pos - pPatterns[i].m_Len, limit, pPatterns[i].m_pTag,
- pPatterns[i].m_Len)) {
- found = i;
- goto end;
+ IsWholeWord(pos - patterns[i].m_Len, limit, patterns[i].m_pTag,
+ patterns[i].m_Len)) {
+ return i;
} else {
- if (pPatterns[i].m_pTag[0] == byte) {
- pPatterns[i].m_Offset = 1;
+ if (patterns[i].m_pTag[0] == byte) {
+ patterns[i].m_Offset = 1;
} else {
- pPatterns[i].m_Offset = 0;
+ patterns[i].m_Offset = 0;
}
}
}
} else {
- if (pPatterns[i].m_pTag[0] == byte) {
- pPatterns[i].m_Offset = 1;
+ if (patterns[i].m_pTag[0] == byte) {
+ patterns[i].m_Offset = 1;
} else {
- pPatterns[i].m_Offset = 0;
+ patterns[i].m_Offset = 0;
}
}
}
- if (limit && pos >= m_Pos + limit) {
- goto end;
- }
- if (!GetCharAt(pos, byte)) {
- goto end;
+
+ if ((limit && pos >= m_Pos + limit) || !GetCharAt(pos, byte)) {
Tom Sepez 2015/09/23 21:48:41 I would like to have the first half of this || use
Lei Zhang 2015/09/25 09:33:48 Done.
+ return -1;
}
- pos++;
}
-end:
- FX_Free(pPatterns);
- return found;
+ return -1;
Tom Sepez 2015/09/23 21:48:41 notreached? Only way out of your loop by return? w
Lei Zhang 2015/09/25 09:33:48 Acknowledged.
}
+
FX_FILESIZE CPDF_SyntaxParser::FindTag(const CFX_ByteStringC& tag,
FX_FILESIZE limit) {
int32_t taglen = tag.GetLength();
@@ -2814,20 +2813,19 @@ class CPDF_DataAvail final : public IPDF_DataAvail {
CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead);
~CPDF_DataAvail() override;
- virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) override;
+ FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) override;
- virtual void SetDocument(CPDF_Document* pDoc) override;
+ void SetDocument(CPDF_Document* pDoc) override;
- virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) override;
+ FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) override;
- virtual int32_t IsFormAvail(IFX_DownloadHints* pHints) override;
+ int32_t IsFormAvail(IFX_DownloadHints* pHints) override;
- virtual int32_t IsLinearizedPDF() override;
+ int32_t IsLinearizedPDF() override;
- virtual FX_BOOL IsLinearized() override { return m_bLinearized; }
+ FX_BOOL IsLinearized() override { return m_bLinearized; }
- virtual void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos,
- FX_DWORD* pSize) override;
+ void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, FX_DWORD* pSize) override;
protected:
static const int kMaxDataAvailRecursionDepth = 64;
« no previous file with comments | « no previous file | core/src/fxcodec/codec/fx_codec_flate.cpp » ('j') | core/src/fxcodec/codec/fx_codec_flate.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698