summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-04-04 15:27:21 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 23:05:19 +0000
commit20a909e655147e21f966b95af6b683d85736c8c2 (patch)
tree1bf66f3587e271b31f3d9e4ec34f650dad6ffdea
parent236ce3ba2f274307db9ed49c595e242cd811716c (diff)
downloadpdfium-20a909e655147e21f966b95af6b683d85736c8c2.tar.xz
Remove a couple checks for MakeUnique failures.
Combine some common CCodec_Jbig2Module code. Change-Id: I9a046314bc0e9dddc9a8c1a06b37764e9f3cc4b6 Reviewed-on: https://pdfium-review.googlesource.com/3713 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp12
-rw-r--r--core/fxcodec/codec/ccodec_jbig2module.h3
-rw-r--r--core/fxcodec/codec/fx_codec_jbig.cpp34
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.h2
4 files changed, 20 insertions, 31 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 20e9418904..ecdeeacb19 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -240,17 +240,13 @@ CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() {
if (m_pEncryptDict) {
CFX_ByteString filter = m_pEncryptDict->GetStringFor("Filter");
- std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler;
- Error err = HANDLER_ERROR;
- if (filter == "Standard") {
- pSecurityHandler = pdfium::MakeUnique<CPDF_SecurityHandler>();
- err = PASSWORD_ERROR;
- }
- if (!pSecurityHandler)
+ if (filter != "Standard")
return HANDLER_ERROR;
+ std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler =
+ pdfium::MakeUnique<CPDF_SecurityHandler>();
if (!pSecurityHandler->OnInit(this, m_pEncryptDict))
- return err;
+ return PASSWORD_ERROR;
m_pSecurityHandler = std::move(pSecurityHandler);
std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler(
diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/ccodec_jbig2module.h
index e4e0af35da..43abe042f0 100644
--- a/core/fxcodec/codec/ccodec_jbig2module.h
+++ b/core/fxcodec/codec/ccodec_jbig2module.h
@@ -50,6 +50,9 @@ class CCodec_Jbig2Module {
IFX_Pause* pPause);
FXCODEC_STATUS ContinueDecode(CCodec_Jbig2Context* pJbig2Context,
IFX_Pause* pPause);
+
+ private:
+ FXCODEC_STATUS Decode(CCodec_Jbig2Context* pJbig2Context, int result);
};
#endif // CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_
diff --git a/core/fxcodec/codec/fx_codec_jbig.cpp b/core/fxcodec/codec/fx_codec_jbig.cpp
index 951fec4813..7df87e981f 100644
--- a/core/fxcodec/codec/fx_codec_jbig.cpp
+++ b/core/fxcodec/codec/fx_codec_jbig.cpp
@@ -66,40 +66,30 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(
pJbig2Context->m_pContext = pdfium::MakeUnique<CJBig2_Context>(
global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(),
pPause, false);
- if (!pJbig2Context->m_pContext)
- return FXCODEC_STATUS_ERROR;
-
int ret = pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height,
dest_pitch, pPause);
- if (pJbig2Context->m_pContext->GetProcessingStatus() ==
- FXCODEC_STATUS_DECODE_FINISH) {
- pJbig2Context->m_pContext.reset();
- if (ret != JBIG2_SUCCESS)
- return FXCODEC_STATUS_ERROR;
-
- int dword_size = height * dest_pitch / 4;
- uint32_t* dword_buf = (uint32_t*)dest_buf;
- for (int i = 0; i < dword_size; i++)
- dword_buf[i] = ~dword_buf[i];
- return FXCODEC_STATUS_DECODE_FINISH;
- }
- return pJbig2Context->m_pContext->GetProcessingStatus();
+ return Decode(pJbig2Context, ret);
}
FXCODEC_STATUS CCodec_Jbig2Module::ContinueDecode(
CCodec_Jbig2Context* pJbig2Context,
IFX_Pause* pPause) {
int ret = pJbig2Context->m_pContext->Continue(pPause);
- if (pJbig2Context->m_pContext->GetProcessingStatus() !=
- FXCODEC_STATUS_DECODE_FINISH) {
- return pJbig2Context->m_pContext->GetProcessingStatus();
- }
+ return Decode(pJbig2Context, ret);
+}
+
+FXCODEC_STATUS CCodec_Jbig2Module::Decode(CCodec_Jbig2Context* pJbig2Context,
+ int result) {
+ FXCODEC_STATUS status = pJbig2Context->m_pContext->GetProcessingStatus();
+ if (status != FXCODEC_STATUS_DECODE_FINISH)
+ return status;
+
pJbig2Context->m_pContext.reset();
- if (ret != JBIG2_SUCCESS)
+ if (result != JBIG2_SUCCESS)
return FXCODEC_STATUS_ERROR;
int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4;
- uint32_t* dword_buf = (uint32_t*)pJbig2Context->m_dest_buf;
+ uint32_t* dword_buf = reinterpret_cast<uint32_t*>(pJbig2Context->m_dest_buf);
for (int i = 0; i < dword_size; i++)
dword_buf[i] = ~dword_buf[i];
return FXCODEC_STATUS_DECODE_FINISH;
diff --git a/core/fxcodec/jbig2/JBig2_Context.h b/core/fxcodec/jbig2/JBig2_Context.h
index 31865d4d46..a9fb1e2451 100644
--- a/core/fxcodec/jbig2/JBig2_Context.h
+++ b/core/fxcodec/jbig2/JBig2_Context.h
@@ -54,7 +54,7 @@ class CJBig2_Context {
IFX_Pause* pPause);
int32_t Continue(IFX_Pause* pPause);
- FXCODEC_STATUS GetProcessingStatus() { return m_ProcessingStatus; }
+ FXCODEC_STATUS GetProcessingStatus() const { return m_ProcessingStatus; }
private:
int32_t decode_SquentialOrgnazation(IFX_Pause* pPause);