From 82f66b588f7d0a2edef878fa6c06a0e46d522821 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 5 Apr 2018 19:25:51 +0000 Subject: Fix const casts in CPDF_Encryptor. Change-Id: I4d7661716116969ae80fdac52f6b400a5ff68e50 Reviewed-on: https://pdfium-review.googlesource.com/29855 Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- core/fpdfapi/edit/cpdf_encryptor.cpp | 17 +++++++---------- core/fpdfapi/edit/cpdf_encryptor.h | 12 ++++++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/fpdfapi/edit/cpdf_encryptor.cpp b/core/fpdfapi/edit/cpdf_encryptor.cpp index 45be9f8447..033df38a48 100644 --- a/core/fpdfapi/edit/cpdf_encryptor.cpp +++ b/core/fpdfapi/edit/cpdf_encryptor.cpp @@ -10,23 +10,20 @@ CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler, int objnum, const uint8_t* src_data, - uint32_t src_size) - : m_pData(nullptr), m_dwSize(0), m_bNewBuf(false) { + uint32_t src_size) { if (src_size == 0) return; if (!pHandler) { - m_pData = (uint8_t*)src_data; + m_pData = src_data; m_dwSize = src_size; return; } m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size); - m_pData = FX_Alloc(uint8_t, m_dwSize); - pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); - m_bNewBuf = true; + m_pNewBuf.reset(FX_Alloc(uint8_t, m_dwSize)); + pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pNewBuf.get(), + m_dwSize); + m_pData = m_pNewBuf.get(); } -CPDF_Encryptor::~CPDF_Encryptor() { - if (m_bNewBuf) - FX_Free(m_pData); -} +CPDF_Encryptor::~CPDF_Encryptor() {} diff --git a/core/fpdfapi/edit/cpdf_encryptor.h b/core/fpdfapi/edit/cpdf_encryptor.h index 1da601d491..a62a4ebf22 100644 --- a/core/fpdfapi/edit/cpdf_encryptor.h +++ b/core/fpdfapi/edit/cpdf_encryptor.h @@ -9,6 +9,10 @@ #include +#include + +#include "core/fxcrt/fx_memory.h" + class CPDF_CryptoHandler; class CPDF_Encryptor { @@ -20,12 +24,12 @@ class CPDF_Encryptor { ~CPDF_Encryptor(); uint32_t GetSize() const { return m_dwSize; } - uint8_t* GetData() const { return m_pData; } + const uint8_t* GetData() const { return m_pData; } private: - uint8_t* m_pData; - uint32_t m_dwSize; - bool m_bNewBuf; + const uint8_t* m_pData = nullptr; + std::unique_ptr m_pNewBuf; + uint32_t m_dwSize = 0; }; #endif // CORE_FPDFAPI_EDIT_CPDF_ENCRYPTOR_H_ -- cgit v1.2.3