summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_parser.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-04 14:37:18 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 21:48:48 +0000
commitafd0d1f488ea55da545b3310fd8f22e45522a695 (patch)
tree89136eba4669421b6f828edb9f3d69ee558110d0 /core/fpdfapi/parser/cpdf_parser.cpp
parent4f8b044b95dc282959dfe41453e2a9c1ec7e9354 (diff)
downloadpdfium-afd0d1f488ea55da545b3310fd8f22e45522a695.tar.xz
RefCount CPDF_StreamAcc all the time.
Pass stream argument to constructor; it feels like a stream accessor should always be made from a stream rather than passing one in after the fact. Change-Id: Iaa46cb37677b81f0170f5d39bab76ad38ea4af44 Reviewed-on: https://pdfium-review.googlesource.com/3620 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_parser.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index cac678762d..20e9418904 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -40,11 +40,11 @@ uint32_t GetVarInt(const uint8_t* p, int32_t n) {
return result;
}
-int32_t GetStreamNCount(CPDF_StreamAcc* pObjStream) {
+int32_t GetStreamNCount(const CFX_RetainPtr<CPDF_StreamAcc>& pObjStream) {
return pObjStream->GetDict()->GetIntegerFor("N");
}
-int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) {
+int32_t GetStreamFirst(const CFX_RetainPtr<CPDF_StreamAcc>& pObjStream) {
return pObjStream->GetDict()->GetIntegerFor("First");
}
@@ -997,11 +997,11 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) {
return false;
uint32_t totalWidth = dwAccWidth.ValueOrDie();
- CPDF_StreamAcc acc;
- acc.LoadAllData(pStream);
+ auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
+ pAcc->LoadAllData();
- const uint8_t* pData = acc.GetData();
- uint32_t dwTotalSize = acc.GetSize();
+ const uint8_t* pData = pAcc->GetData();
+ uint32_t dwTotalSize = pAcc->GetSize();
uint32_t segindex = 0;
for (uint32_t i = 0; i < arrIndex.size(); i++) {
int32_t startnum = arrIndex[i].first;
@@ -1114,7 +1114,8 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject(
if (GetObjectType(objnum) != 2)
return nullptr;
- CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos);
+ CFX_RetainPtr<CPDF_StreamAcc> pObjStream =
+ GetObjectStream(m_ObjectInfo[objnum].pos);
if (!pObjStream)
return nullptr;
@@ -1141,10 +1142,10 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject(
return syntax.GetObject(pObjList, 0, 0, true);
}
-CPDF_StreamAcc* CPDF_Parser::GetObjectStream(uint32_t objnum) {
+CFX_RetainPtr<CPDF_StreamAcc> CPDF_Parser::GetObjectStream(uint32_t objnum) {
auto it = m_ObjectStreamMap.find(objnum);
if (it != m_ObjectStreamMap.end())
- return it->second.get();
+ return it->second;
if (!m_pDocument)
return nullptr;
@@ -1154,9 +1155,9 @@ CPDF_StreamAcc* CPDF_Parser::GetObjectStream(uint32_t objnum) {
if (!pStream)
return nullptr;
- CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc;
- pStreamAcc->LoadAllData(pStream);
- m_ObjectStreamMap[objnum].reset(pStreamAcc);
+ auto pStreamAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
+ pStreamAcc->LoadAllData();
+ m_ObjectStreamMap[objnum] = pStreamAcc;
return pStreamAcc;
}
@@ -1190,7 +1191,8 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum,
return;
if (GetObjectType(objnum) == 2) {
- CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos);
+ CFX_RetainPtr<CPDF_StreamAcc> pObjStream =
+ GetObjectStream(m_ObjectInfo[objnum].pos);
if (!pObjStream)
return;