summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_contentparser.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-11-08 15:49:51 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-08 15:49:51 +0000
commitc064d54cd169390039eedae422bbb132f771d20a (patch)
treea9f94cd071c0bf1f1e0015ae9f055047dedc6810 /core/fpdfapi/page/cpdf_contentparser.cpp
parent58629a0e49e4ebfb0a0171a4203d2fab4af63165 (diff)
downloadpdfium-c064d54cd169390039eedae422bbb132f771d20a.tar.xz
Use MaybeOwned in CPDF_ContentParser
Change-Id: I7e5daeafd70ef29bcc9bdebbae004fa4b946b83d Reviewed-on: https://pdfium-review.googlesource.com/18019 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_contentparser.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 0571405908..30701422d2 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -103,15 +103,11 @@ CPDF_ContentParser::CPDF_ContentParser(CPDF_Form* pForm,
m_pSingleStream =
pdfium::MakeRetain<CPDF_StreamAcc>(pForm->m_pFormStream.Get());
m_pSingleStream->LoadAllData(false);
- m_pData = const_cast<uint8_t*>(m_pSingleStream->GetData());
+ m_pData.Reset(m_pSingleStream->GetData());
m_Size = m_pSingleStream->GetSize();
}
-CPDF_ContentParser::~CPDF_ContentParser() {
- // TODO(thestig): Switch |m_pData| to MaybeOwned?
- if (!m_pSingleStream)
- FX_Free(m_pData);
-}
+CPDF_ContentParser::~CPDF_ContentParser() {}
bool CPDF_ContentParser::Continue(IFX_PauseIndicator* pPause) {
if (m_bIsDone)
@@ -131,16 +127,17 @@ bool CPDF_ContentParser::Continue(IFX_PauseIndicator* pPause) {
return false;
}
m_Size = safeSize.ValueOrDie();
- m_pData = FX_Alloc(uint8_t, m_Size);
+ m_pData.Reset(std::unique_ptr<uint8_t, FxFreeDeleter>(
+ FX_Alloc(uint8_t, m_Size)));
uint32_t pos = 0;
for (const auto& stream : m_StreamArray) {
- memcpy(m_pData + pos, stream->GetData(), stream->GetSize());
+ memcpy(m_pData.Get() + pos, stream->GetData(), stream->GetSize());
pos += stream->GetSize();
- m_pData[pos++] = ' ';
+ m_pData.Get()[pos++] = ' ';
}
m_StreamArray.clear();
} else {
- m_pData = const_cast<uint8_t*>(m_pSingleStream->GetData());
+ m_pData.Reset(m_pSingleStream->GetData());
m_Size = m_pSingleStream->GetSize();
}
m_InternalStage = STAGE_PARSE;
@@ -170,7 +167,7 @@ bool CPDF_ContentParser::Continue(IFX_PauseIndicator* pPause) {
m_InternalStage = STAGE_CHECKCLIP;
} else {
m_CurrentOffset +=
- m_pParser->Parse(m_pData + m_CurrentOffset,
+ m_pParser->Parse(m_pData.Get() + m_CurrentOffset,
m_Size - m_CurrentOffset, PARSE_STEP_LIMIT);
}
}