summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-01-26 17:11:51 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-26 17:11:51 +0000
commit4b9d69806c30775f55563e72b0842daa06483f99 (patch)
treede54ec0133b6ad5ee625060adbfb02c45a0b9c83
parent49363202ce06ca9ff418b4df384cffadf924303c (diff)
downloadpdfium-4b9d69806c30775f55563e72b0842daa06483f99.tar.xz
Clean up construction of CFX_Barcode
Because certain enum values can cause the initialization of the class to fail there is a seperate init method from the constructor. This CL is converting the code to use a standard factory pattern for this, instead of the existing implementation. Change-Id: Ia2293ce94ad0db5862db9796aeb8a224fd2b45f9 Reviewed-on: https://pdfium-review.googlesource.com/24230 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
-rw-r--r--testing/libfuzzer/pdf_cfx_barcode_fuzzer.cc14
-rw-r--r--xfa/fwl/cfwl_barcode.cpp4
-rw-r--r--xfa/fwl/cfx_barcode.cpp8
-rw-r--r--xfa/fwl/cfx_barcode.h5
-rw-r--r--xfa/fwl/cfx_barcode_unittest.cpp4
5 files changed, 18 insertions, 17 deletions
diff --git a/testing/libfuzzer/pdf_cfx_barcode_fuzzer.cc b/testing/libfuzzer/pdf_cfx_barcode_fuzzer.cc
index 3334e86bfc..aaeebf3ace 100644
--- a/testing/libfuzzer/pdf_cfx_barcode_fuzzer.cc
+++ b/testing/libfuzzer/pdf_cfx_barcode_fuzzer.cc
@@ -17,20 +17,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
data += sizeof(wchar_t);
size -= sizeof(wchar_t);
- CFX_Barcode barcode;
- if (!barcode.Create(type))
+ auto barcode = CFX_Barcode::Create(type);
+ if (!barcode)
return 0;
// TODO(tsepez): Setup more options from |data|.
- barcode.SetModuleHeight(300);
- barcode.SetModuleWidth(420);
- barcode.SetHeight(298);
- barcode.SetWidth(418);
+ barcode->SetModuleHeight(300);
+ barcode->SetModuleWidth(420);
+ barcode->SetHeight(298);
+ barcode->SetWidth(418);
WideStringView content(reinterpret_cast<const wchar_t*>(data),
size / sizeof(wchar_t));
- if (!barcode.Encode(content))
+ if (!barcode->Encode(content))
return 0;
// TODO(tsepez): Output to device.
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index f5d6ea98b2..74ac7dd9c2 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -213,7 +213,5 @@ void CFWL_Barcode::CreateBarcodeEngine() {
if (m_pBarcodeEngine || m_type == BC_UNKNOWN)
return;
- auto pBarcode = pdfium::MakeUnique<CFX_Barcode>();
- if (pBarcode->Create(m_type))
- m_pBarcodeEngine = std::move(pBarcode);
+ m_pBarcodeEngine = CFX_Barcode::Create(m_type);
}
diff --git a/xfa/fwl/cfx_barcode.cpp b/xfa/fwl/cfx_barcode.cpp
index 9d667c67b9..2d1253630e 100644
--- a/xfa/fwl/cfx_barcode.cpp
+++ b/xfa/fwl/cfx_barcode.cpp
@@ -59,9 +59,11 @@ CFX_Barcode::CFX_Barcode() {}
CFX_Barcode::~CFX_Barcode() {}
-bool CFX_Barcode::Create(BC_TYPE type) {
- m_pBCEngine = CreateBarCodeEngineObject(type);
- return !!m_pBCEngine;
+std::unique_ptr<CFX_Barcode> CFX_Barcode::Create(BC_TYPE type) {
+ auto barcodeEngine = CreateBarCodeEngineObject(type);
+ std::unique_ptr<CFX_Barcode> barcode(new CFX_Barcode());
+ barcode->m_pBCEngine.swap(barcodeEngine);
+ return barcode;
}
BC_TYPE CFX_Barcode::GetType() {
diff --git a/xfa/fwl/cfx_barcode.h b/xfa/fwl/cfx_barcode.h
index eec4648e82..a5f0513241 100644
--- a/xfa/fwl/cfx_barcode.h
+++ b/xfa/fwl/cfx_barcode.h
@@ -22,10 +22,9 @@ class CFX_Matrix;
class CFX_Barcode {
public:
- CFX_Barcode();
~CFX_Barcode();
- bool Create(BC_TYPE type);
+ static std::unique_ptr<CFX_Barcode> Create(BC_TYPE type);
BC_TYPE GetType();
bool Encode(const WideStringView& contents);
@@ -56,6 +55,8 @@ class CFX_Barcode {
bool SetTruncated(bool truncated);
private:
+ CFX_Barcode();
+
std::unique_ptr<CBC_CodeBase> m_pBCEngine;
};
diff --git a/xfa/fwl/cfx_barcode_unittest.cpp b/xfa/fwl/cfx_barcode_unittest.cpp
index fe8aee4709..585d92f2db 100644
--- a/xfa/fwl/cfx_barcode_unittest.cpp
+++ b/xfa/fwl/cfx_barcode_unittest.cpp
@@ -20,7 +20,6 @@ class BarcodeTest : public testing::Test {
public:
void SetUp() override {
BC_Library_Init();
- barcode_ = pdfium::MakeUnique<CFX_Barcode>();
auto device = pdfium::MakeUnique<CFX_DefaultRenderDevice>();
auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
@@ -41,7 +40,8 @@ class BarcodeTest : public testing::Test {
CFX_Barcode* barcode() const { return barcode_.get(); }
bool Create(BC_TYPE type) {
- if (!barcode_->Create(type))
+ barcode_ = CFX_Barcode::Create(type);
+ if (!barcode_)
return false;
barcode_->SetModuleHeight(300);