From a3d5248b4e508ccacf7e90116df0bed347719e33 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 29 Oct 2018 14:25:59 +0200 Subject: loplugin:useuniqueptr in codemaker Change-Id: I1d6ec5a5c06a32242773c857444bb63b7b4207b6 Reviewed-on: https://gerrit.libreoffice.org/62648 Tested-by: Jenkins Reviewed-by: Noel Grandin --- codemaker/source/javamaker/classfile.cxx | 6 +++--- codemaker/source/javamaker/classfile.hxx | 3 ++- codemaker/source/javamaker/javatype.cxx | 9 ++------- 3 files changed, 7 insertions(+), 11 deletions(-) (limited to 'codemaker') diff --git a/codemaker/source/javamaker/classfile.cxx b/codemaker/source/javamaker/classfile.cxx index 1df31aea6947..23bc000248bb 100644 --- a/codemaker/source/javamaker/classfile.cxx +++ b/codemaker/source/javamaker/classfile.cxx @@ -312,7 +312,7 @@ void ClassFile::Code::instrSwap() { void ClassFile::Code::instrTableswitch( Code const * defaultBlock, sal_Int32 low, - std::vector< Code * > const & blocks) + std::vector< std::unique_ptr > const & blocks) { // tableswitch <0--3 byte pad> // @@ -331,7 +331,7 @@ void ClassFile::Code::instrTableswitch( pos2 += defaultBlock->m_code.size(); //FIXME: overflow appendU4(m_code, static_cast< sal_uInt32 >(low)); appendU4(m_code, static_cast< sal_uInt32 >(low + (size - 1))); - for (Code *pCode : blocks) + for (std::unique_ptr const & pCode : blocks) { if (pCode == nullptr) { appendU4(m_code, defaultOffset); @@ -342,7 +342,7 @@ void ClassFile::Code::instrTableswitch( } } appendStream(m_code, defaultBlock->m_code); - for (Code *pCode : blocks) + for (std::unique_ptr const & pCode : blocks) { if (pCode != nullptr) { appendStream(m_code, pCode->m_code); diff --git a/codemaker/source/javamaker/classfile.hxx b/codemaker/source/javamaker/classfile.hxx index be6e3a36abe4..179fea21ef77 100644 --- a/codemaker/source/javamaker/classfile.hxx +++ b/codemaker/source/javamaker/classfile.hxx @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -107,7 +108,7 @@ public: void instrTableswitch( Code const * defaultBlock, sal_Int32 low, - std::vector< Code * > const & blocks); + std::vector< std::unique_ptr > const & blocks); void loadIntegerConstant(sal_Int32 value); void loadStringConstant(rtl::OString const & value); diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx index 9d683a53ce08..4cd5b50050b0 100644 --- a/codemaker/source/javamaker/javatype.cxx +++ b/codemaker/source/javamaker/javatype.cxx @@ -749,7 +749,7 @@ void handleEnumType( std::unique_ptr< ClassFile::Code > defCode(cf->newCode()); defCode->instrAconstNull(); defCode->instrAreturn(); - std::vector< ClassFile::Code * > blocks; + std::vector< std::unique_ptr > blocks; //FIXME: pointers contained in blocks may leak sal_Int32 last = SAL_MAX_INT32; for (const auto& pair : map) @@ -764,14 +764,9 @@ void handleEnumType( std::unique_ptr< ClassFile::Code > blockCode(cf->newCode()); blockCode->instrGetstatic(className, pair.second, classDescriptor); blockCode->instrAreturn(); - blocks.push_back(blockCode.get()); - blockCode.release(); + blocks.push_back(std::move(blockCode)); } code->instrTableswitch(defCode.get(), min, blocks); - for (ClassFile::Code *p : blocks) - { - delete p; - } } else{ std::unique_ptr< ClassFile::Code > defCode(cf->newCode()); defCode->instrAconstNull(); -- cgit