From 991f61869cfba58206cc7ec038fe8d5305bbb2ba Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 1 Dec 2016 15:15:49 -0500 Subject: Move Init to constructor in CXFA_FMProgram MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6b2d1a5b06211b32f3053aad4d7ae7501ec8d8f6 Reviewed-on: https://pdfium-review.googlesource.com/2093 Commit-Queue: Nicolás Peña Reviewed-by: Tom Sepez --- testing/libfuzzer/pdf_fm2js_fuzzer.cc | 4 ++-- xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 10 ++-------- xfa/fxfa/fm2js/xfa_fmparse.cpp | 13 +++++-------- xfa/fxfa/fm2js/xfa_fmparse.h | 5 ++--- xfa/fxfa/fm2js/xfa_program.cpp | 7 ++----- xfa/fxfa/fm2js/xfa_program.h | 3 +-- 6 files changed, 14 insertions(+), 28 deletions(-) diff --git a/testing/libfuzzer/pdf_fm2js_fuzzer.cc b/testing/libfuzzer/pdf_fm2js_fuzzer.cc index ced5e18399..9afaa915ec 100644 --- a/testing/libfuzzer/pdf_fm2js_fuzzer.cc +++ b/testing/libfuzzer/pdf_fm2js_fuzzer.cc @@ -17,8 +17,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { CFX_WideString input = CFX_WideString::FromUTF8(CFX_ByteStringC(data, safe_size.ValueOrDie())); - CXFA_FMProgram program; - if (program.Init(input.AsStringC()) || program.ParseProgram()) + CXFA_FMProgram program(input.AsStringC()); + if (program.ParseProgram()) return 0; CFX_WideTextBuf js; diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index 4394455c74..8bcdcdda31 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -6482,14 +6482,8 @@ int32_t CXFA_FM2JSContext::Translate(const CFX_WideStringC& wsFormcalc, wsError.clear(); return 0; } - int32_t status = 0; - CXFA_FMProgram program; - status = program.Init(wsFormcalc); - if (status) { - wsError = program.GetError().message; - return status; - } - status = program.ParseProgram(); + CXFA_FMProgram program(wsFormcalc); + int32_t status = program.ParseProgram(); if (status) { wsError = program.GetError().message; return status; diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp index 2d287da3b1..53e94666de 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.cpp +++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp @@ -12,17 +12,14 @@ #include "third_party/base/ptr_util.h" -CXFA_FMParse::CXFA_FMParse() : m_pToken(nullptr), m_pErrorInfo(0) {} - -CXFA_FMParse::~CXFA_FMParse() {} - -int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc, - CXFA_FMErrorInfo* pErrorInfo) { - m_pErrorInfo = pErrorInfo; +CXFA_FMParse::CXFA_FMParse(const CFX_WideStringC& wsFormcalc, + CXFA_FMErrorInfo* pErrorInfo) + : m_pToken(nullptr), m_pErrorInfo(pErrorInfo) { m_lexer = pdfium::MakeUnique(wsFormcalc, m_pErrorInfo); - return 0; } +CXFA_FMParse::~CXFA_FMParse() {} + void CXFA_FMParse::NextToken() { m_pToken = m_lexer->NextToken(); while (m_pToken->m_type == TOKreserver) { diff --git a/xfa/fxfa/fm2js/xfa_fmparse.h b/xfa/fxfa/fm2js/xfa_fmparse.h index 5f8022f270..8f2671d1b0 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.h +++ b/xfa/fxfa/fm2js/xfa_fmparse.h @@ -15,10 +15,9 @@ class CXFA_FMParse { public: - CXFA_FMParse(); + CXFA_FMParse(const CFX_WideStringC& wsFormcalc, CXFA_FMErrorInfo* pErrorInfo); ~CXFA_FMParse(); - int32_t Init(const CFX_WideStringC& wsFormcalc, CXFA_FMErrorInfo* pErrorInfo); void NextToken(); void Check(XFA_FM_TOKEN op); void Error(uint32_t lineNum, const FX_WCHAR* msg, ...); @@ -51,7 +50,7 @@ class CXFA_FMParse { private: std::unique_ptr m_lexer; CXFA_FMToken* m_pToken; - CXFA_FMErrorInfo* m_pErrorInfo; + CXFA_FMErrorInfo* const m_pErrorInfo; }; #endif // XFA_FXFA_FM2JS_XFA_FMPARSE_H_ diff --git a/xfa/fxfa/fm2js/xfa_program.cpp b/xfa/fxfa/fm2js/xfa_program.cpp index ac18c15e6d..4d37f74767 100644 --- a/xfa/fxfa/fm2js/xfa_program.cpp +++ b/xfa/fxfa/fm2js/xfa_program.cpp @@ -11,14 +11,11 @@ #include "third_party/base/ptr_util.h" -CXFA_FMProgram::CXFA_FMProgram() {} +CXFA_FMProgram::CXFA_FMProgram(const CFX_WideStringC& wsFormcalc) + : m_parse(wsFormcalc, &m_pErrorInfo) {} CXFA_FMProgram::~CXFA_FMProgram() {} -int32_t CXFA_FMProgram::Init(const CFX_WideStringC& wsFormcalc) { - return m_parse.Init(wsFormcalc, &m_pErrorInfo); -} - int32_t CXFA_FMProgram::ParseProgram() { m_parse.NextToken(); if (!m_pErrorInfo.message.IsEmpty()) diff --git a/xfa/fxfa/fm2js/xfa_program.h b/xfa/fxfa/fm2js/xfa_program.h index aa29bba87b..7a2dade6fd 100644 --- a/xfa/fxfa/fm2js/xfa_program.h +++ b/xfa/fxfa/fm2js/xfa_program.h @@ -14,10 +14,9 @@ class CXFA_FMProgram { public: - CXFA_FMProgram(); + explicit CXFA_FMProgram(const CFX_WideStringC& wsFormcalc); ~CXFA_FMProgram(); - int32_t Init(const CFX_WideStringC& wsFormcalc); int32_t ParseProgram(); int32_t TranslateProgram(CFX_WideTextBuf& wsJavaScript); -- cgit v1.2.3