summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-22 13:02:43 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-22 13:02:43 -0800
commitc675a2f4afdd7e54bc4b4638bd1ffcb2de0b7124 (patch)
tree32d24b9f0f0644d59ed2e6578e420eb1542aee70
parent6136ec6347a5858a85912a805ea41126863558cd (diff)
downloadpdfium-chromium/2929.tar.xz
Use more unique_ptrs in CPDF_SyntaxParser and CPDF_Annotchromium/2929
Review-Url: https://codereview.chromium.org/2526543003
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp30
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.h7
-rw-r--r--core/fpdfdoc/cpdf_annot.cpp12
3 files changed, 21 insertions, 28 deletions
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 17e4954f2a..9beae0b7f7 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -477,9 +477,8 @@ std::unique_ptr<CPDF_Object> CPDF_SyntaxParser::GetObject(
m_Pos = SavedPos;
return std::move(pDict);
}
- return ReadStream(pDict.release(), objnum, gennum);
+ return ReadStream(std::move(pDict), objnum, gennum);
}
-
if (word == ">>")
m_Pos = SavedObjPos;
@@ -587,10 +586,8 @@ std::unique_ptr<CPDF_Object> CPDF_SyntaxParser::GetObjectForStrict(
m_Pos = SavedPos;
return std::move(pDict);
}
-
- return ReadStream(pDict.release(), objnum, gennum);
+ return ReadStream(std::move(pDict), objnum, gennum);
}
-
if (word == ">>")
m_Pos = SavedObjPos;
@@ -614,7 +611,7 @@ unsigned int CPDF_SyntaxParser::ReadEOLMarkers(FX_FILESIZE pos) {
}
std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
- CPDF_Dictionary* pDict,
+ std::unique_ptr<CPDF_Dictionary> pDict,
uint32_t objnum,
uint32_t gennum) {
CPDF_Object* pLenObj = pDict->GetObjectFor("Length");
@@ -693,10 +690,8 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
}
// Can't find "endstream" or "endobj".
- if (endStreamOffset < 0 && endObjOffset < 0) {
- delete pDict;
+ if (endStreamOffset < 0 && endObjOffset < 0)
return nullptr;
- }
if (endStreamOffset < 0 && endObjOffset >= 0) {
// Correct the position of end stream.
@@ -707,8 +702,8 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
} else if (endStreamOffset > endObjOffset) {
endStreamOffset = endObjOffset;
}
-
len = endStreamOffset;
+
int numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 2);
if (numMarkers == 2) {
len -= 2;
@@ -718,20 +713,15 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
len -= 1;
}
}
-
- if (len < 0) {
- delete pDict;
+ if (len < 0)
return nullptr;
- }
+
pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(len));
}
m_Pos = streamStartPos;
}
-
- if (len < 0) {
- delete pDict;
+ if (len < 0)
return nullptr;
- }
uint8_t* pData = nullptr;
if (len > 0) {
@@ -744,7 +734,6 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
void* context = pCryptoHandler->DecryptStart(objnum, gennum);
pCryptoHandler->DecryptStream(context, pData, len, dest_buf);
pCryptoHandler->DecryptFinish(context, dest_buf);
-
FX_Free(pData);
pData = dest_buf.GetBuffer();
len = dest_buf.GetSize();
@@ -752,8 +741,7 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
}
}
- auto pStream =
- pdfium::MakeUnique<CPDF_Stream>(pData, len, pdfium::WrapUnique(pDict));
+ auto pStream = pdfium::MakeUnique<CPDF_Stream>(pData, len, std::move(pDict));
streamStartPos = m_Pos;
FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1);
GetNextWordInternal(nullptr);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h
index 094872ab70..1e8f736c17 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.h
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -75,9 +75,10 @@ class CPDF_SyntaxParser {
CFX_ByteString ReadString();
CFX_ByteString ReadHexString();
unsigned int ReadEOLMarkers(FX_FILESIZE pos);
- std::unique_ptr<CPDF_Stream> ReadStream(CPDF_Dictionary* pDict,
- uint32_t objnum,
- uint32_t gennum);
+ std::unique_ptr<CPDF_Stream> ReadStream(
+ std::unique_ptr<CPDF_Dictionary> pDict,
+ uint32_t objnum,
+ uint32_t gennum);
inline bool CheckPosition(FX_FILESIZE pos) {
return m_BufOffset >= pos ||
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index a7d2101364..70c6b8d3c4 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfdoc/cpdf_annot.h"
+#include <utility>
+
#include "core/fpdfapi/page/cpdf_form.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_array.h"
@@ -205,11 +207,13 @@ CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) {
if (it != m_APMap.end())
return it->second.get();
- CPDF_Form* pNewForm =
- new CPDF_Form(m_pDocument, pPage->m_pResources, pStream);
+ auto pNewForm =
+ pdfium::MakeUnique<CPDF_Form>(m_pDocument, pPage->m_pResources, pStream);
pNewForm->ParseContent(nullptr, nullptr, nullptr);
- m_APMap[pStream] = pdfium::WrapUnique(pNewForm);
- return pNewForm;
+
+ CPDF_Form* pResult = pNewForm.get();
+ m_APMap[pStream] = std::move(pNewForm);
+ return pResult;
}
// Static.