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

Unified Diff: core/fpdfapi/parser/cpdf_syntax_parser.cpp

Issue 2526543003: Use more unique_ptrs in CPDF_SyntaxParser and CPDF_Annot (Closed)
Patch Set: Created 4 years, 1 month 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 | « core/fpdfapi/parser/cpdf_syntax_parser.h ('k') | core/fpdfdoc/cpdf_annot.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/parser/cpdf_syntax_parser.cpp
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 17e4954f2abf4ba78c09c97c2bfa6e713bc14c4b..9beae0b7f7ffac229be729def798a09e70bba787 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);
« no previous file with comments | « core/fpdfapi/parser/cpdf_syntax_parser.h ('k') | core/fpdfdoc/cpdf_annot.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698