summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-05 19:25:51 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-05 19:25:51 +0000
commit82f66b588f7d0a2edef878fa6c06a0e46d522821 (patch)
treea2561f86f19ca83ad234def6d9d6dd54252e10ca /core
parent2cc287aec96752d8c36b4178bb75f737842b649b (diff)
downloadpdfium-82f66b588f7d0a2edef878fa6c06a0e46d522821.tar.xz
Fix const casts in CPDF_Encryptor.
Change-Id: I4d7661716116969ae80fdac52f6b400a5ff68e50 Reviewed-on: https://pdfium-review.googlesource.com/29855 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_encryptor.cpp17
-rw-r--r--core/fpdfapi/edit/cpdf_encryptor.h12
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 <stdint.h>
+#include <memory>
+
+#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<uint8_t, FxFreeDeleter> m_pNewBuf;
+ uint32_t m_dwSize = 0;
};
#endif // CORE_FPDFAPI_EDIT_CPDF_ENCRYPTOR_H_