summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/edit/cpdf_flateencoder.cpp5
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode.cpp2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode.h2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp5
-rw-r--r--core/fxcodec/codec/ccodec_flatemodule.cpp13
-rw-r--r--core/fxcodec/codec/ccodec_flatemodule.h2
-rw-r--r--core/fxge/win32/cfx_psrenderer.cpp4
7 files changed, 18 insertions, 15 deletions
diff --git a/core/fpdfapi/edit/cpdf_flateencoder.cpp b/core/fpdfapi/edit/cpdf_flateencoder.cpp
index ba04d7d938..7172bf2d7f 100644
--- a/core/fpdfapi/edit/cpdf_flateencoder.cpp
+++ b/core/fpdfapi/edit/cpdf_flateencoder.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/edit/cpdf_flateencoder.h"
#include <memory>
+#include <utility>
#include "constants/stream_dict_common.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -40,10 +41,10 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(const CPDF_Stream* pStream,
}
// TODO(thestig): Move to Init() and check return value.
- uint8_t* buffer = nullptr;
+ std::unique_ptr<uint8_t, FxFreeDeleter> buffer;
::FlateEncode(m_pAcc->GetSpan(), &buffer, &m_dwSize);
- m_pData = std::unique_ptr<uint8_t, FxFreeDeleter>(buffer);
+ m_pData = std::move(buffer);
m_pClonedDict = ToDictionary(pStream->GetDict()->Clone());
m_pClonedDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize));
m_pClonedDict->SetNewFor<CPDF_Name>("Filter", "FlateDecode");
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index 2b27b89970..5e496fd739 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -581,7 +581,7 @@ ByteString PDF_EncodeString(const ByteString& src, bool bHex) {
}
bool FlateEncode(pdfium::span<const uint8_t> src_span,
- uint8_t** dest_buf,
+ std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
uint32_t* dest_size) {
CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
return pEncoders->GetFlateModule()->Encode(src_span.data(), src_span.size(),
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h
index 2b7832fbc2..265263028e 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.h
+++ b/core/fpdfapi/parser/fpdf_parser_decode.h
@@ -43,7 +43,7 @@ std::unique_ptr<CCodec_ScanlineDecoder> CreateFlateDecoder(
const CPDF_Dictionary* pParams);
bool FlateEncode(pdfium::span<const uint8_t> src_span,
- uint8_t** dest_buf,
+ std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
uint32_t* dest_size);
uint32_t FlateDecode(pdfium::span<const uint8_t> src_span,
diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
index 94776e17ea..4c99394221 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
@@ -37,16 +37,15 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateEncode) {
for (size_t i = 0; i < FX_ArraySize(flate_encode_cases); ++i) {
const pdfium::StrFuncTestData& data = flate_encode_cases[i];
- unsigned char* buf = nullptr;
+ std::unique_ptr<uint8_t, FxFreeDeleter> buf;
uint32_t buf_size;
EXPECT_TRUE(FlateEncode({data.input, data.input_size}, &buf, &buf_size));
ASSERT_TRUE(buf);
EXPECT_EQ(data.expected_size, buf_size) << " for case " << i;
if (data.expected_size != buf_size)
continue;
- EXPECT_EQ(0, memcmp(data.expected, buf, data.expected_size))
+ EXPECT_EQ(0, memcmp(data.expected, buf.get(), data.expected_size))
<< " for case " << i;
- FX_Free(buf);
}
}
diff --git a/core/fxcodec/codec/ccodec_flatemodule.cpp b/core/fxcodec/codec/ccodec_flatemodule.cpp
index f35b9581be..f447ec567f 100644
--- a/core/fxcodec/codec/ccodec_flatemodule.cpp
+++ b/core/fxcodec/codec/ccodec_flatemodule.cpp
@@ -834,14 +834,15 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(
return ret ? offset : FX_INVALID_OFFSET;
}
-bool CCodec_FlateModule::Encode(const uint8_t* src_buf,
- uint32_t src_size,
- uint8_t** dest_buf,
- uint32_t* dest_size) {
+bool CCodec_FlateModule::Encode(
+ const uint8_t* src_buf,
+ uint32_t src_size,
+ std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
+ uint32_t* dest_size) {
*dest_size = src_size + src_size / 1000 + 12;
- *dest_buf = FX_Alloc(uint8_t, *dest_size);
+ dest_buf->reset(FX_Alloc(uint8_t, *dest_size));
unsigned long temp_size = *dest_size;
- if (!FlateCompress(*dest_buf, &temp_size, src_buf, src_size))
+ if (!FlateCompress(dest_buf->get(), &temp_size, src_buf, src_size))
return false;
*dest_size = (uint32_t)temp_size;
diff --git a/core/fxcodec/codec/ccodec_flatemodule.h b/core/fxcodec/codec/ccodec_flatemodule.h
index 591d13d42e..d58c1847ce 100644
--- a/core/fxcodec/codec/ccodec_flatemodule.h
+++ b/core/fxcodec/codec/ccodec_flatemodule.h
@@ -41,7 +41,7 @@ class CCodec_FlateModule {
bool Encode(const uint8_t* src_buf,
uint32_t src_size,
- uint8_t** dest_buf,
+ std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
uint32_t* dest_size);
};
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 12795d0cc5..e66e9685ff 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -59,8 +59,10 @@ void PSCompressData(int PSLevel,
uint8_t* dest_buf = nullptr;
uint32_t dest_size = src_size;
if (PSLevel >= 3) {
- if (pEncoders->GetFlateModule()->Encode(src_buf, src_size, &dest_buf,
+ std::unique_ptr<uint8_t, FxFreeDeleter> dest_buf_unique;
+ if (pEncoders->GetFlateModule()->Encode(src_buf, src_size, &dest_buf_unique,
&dest_size)) {
+ dest_buf = dest_buf_unique.release();
*filter = "/FlateDecode filter ";
}
} else {