compilerplugins/clang/useuniqueptr.cxx | 62 ++++++++++++++++----------------- sal/qa/osl/condition/osl_Condition.cxx | 14 +++---- sal/qa/osl/file/osl_File.cxx | 36 ++++++++----------- store/source/storbios.cxx | 11 ++--- store/source/storbios.hxx | 2 - 5 files changed, 59 insertions(+), 66 deletions(-)
New commits: commit 4db9b09cf035e2c9efe44e64c00999be08ccab01 Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Thu Apr 12 15:08:04 2018 +0200 loplugin:useuniqueptr in sal/qa/ Change-Id: I20b5cfe2fd95da3f37a6812af5683bcc4d918b06 Reviewed-on: https://gerrit.libreoffice.org/52882 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sal/qa/osl/condition/osl_Condition.cxx b/sal/qa/osl/condition/osl_Condition.cxx index b1203e9787d7..cac87532b8d8 100644 --- a/sal/qa/osl/condition/osl_Condition.cxx +++ b/sal/qa/osl/condition/osl_Condition.cxx @@ -196,18 +196,18 @@ namespace osl_Condition { public: bool bRes, bRes1, bRes2; - TimeValue *tv1; + std::unique_ptr<TimeValue> tv1; void setUp() override { - tv1 = new TimeValue; + tv1.reset(new TimeValue); tv1->Seconds = 1; tv1->Nanosec = 0; } void tearDown() override { - delete tv1; + tv1.reset(); } void wait_testAllCombos( ) @@ -219,9 +219,9 @@ namespace osl_Condition cond1.set(); cond2.set(); - osl::Condition::Result r1=cond1.wait(tv1); + osl::Condition::Result r1=cond1.wait(tv1.get()); osl::Condition::Result r2=cond2.wait(); - osl::Condition::Result r3=cond3.wait(tv1); + osl::Condition::Result r3=cond3.wait(tv1.get()); CPPUNIT_ASSERT_EQUAL_MESSAGE( "#test comment#: test three types of wait.", ::osl::Condition::result_ok, r1 ); @@ -238,10 +238,10 @@ namespace osl_Condition aCond.reset(); bRes = aCond.check(); - wRes = aCond.wait(tv1); + wRes = aCond.wait(tv1.get()); aCond.set(); - wRes1 = aCond.wait(tv1); + wRes1 = aCond.wait(tv1.get()); bRes1 = aCond.check(); CPPUNIT_ASSERT_MESSAGE("#test comment#: wait a condition after set/reset.", diff --git a/sal/qa/osl/file/osl_File.cxx b/sal/qa/osl/file/osl_File.cxx index 8a57c2471df7..e853fb135cc5 100644 --- a/sal/qa/osl/file/osl_File.cxx +++ b/sal/qa/osl/file/osl_File.cxx @@ -1210,38 +1210,35 @@ namespace osl_FileBase osl::FileBase::RC nError1, nError2; bool bOK; - oslFileHandle *pHandle; - OUString *pUStr_DirURL; - OUString *pUStr_FileURL; + std::unique_ptr<oslFileHandle> pHandle; + std::unique_ptr<OUString> pUStr_DirURL; + std::unique_ptr<OUString> pUStr_FileURL; public: createTempFile() : nError1(osl::FileBase::E_None) , nError2(osl::FileBase::E_None) , bOK(false) - , pHandle(nullptr) - , pUStr_DirURL(nullptr) - , pUStr_FileURL(nullptr) { } void setUp() override { - pHandle = new oslFileHandle(); - pUStr_DirURL = new OUString(aUserDirectoryURL); - pUStr_FileURL = new OUString(); + pHandle.reset(new oslFileHandle()); + pUStr_DirURL.reset(new OUString(aUserDirectoryURL)); + pUStr_FileURL.reset(new OUString()); } void tearDown() override { - delete pUStr_DirURL; - delete pUStr_FileURL; - delete pHandle; + pUStr_DirURL.reset(); + pUStr_FileURL.reset(); + pHandle.reset(); } void createTempFile_001() { - nError1 = osl::FileBase::createTempFile(pUStr_DirURL, pHandle, pUStr_FileURL); + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), pUStr_FileURL.get()); File testFile(*pUStr_FileURL); nError2 = testFile.open(osl_File_OpenFlag_Create); @@ -1262,7 +1259,7 @@ namespace osl_FileBase void createTempFile_002() { bOK = false; - nError1 = osl::FileBase::createTempFile(pUStr_DirURL, pHandle, pUStr_FileURL); + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), pUStr_FileURL.get()); File testFile(*pUStr_FileURL); nError2 = testFile.open(osl_File_OpenFlag_Create); @@ -1287,7 +1284,7 @@ namespace osl_FileBase void createTempFile_003() { - nError1 = osl::FileBase::createTempFile(pUStr_DirURL, pHandle, nullptr); + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), nullptr); // the temp file will be removed when return from createTempFile bOK = (pHandle != nullptr && nError1 == osl::FileBase::E_None); if (bOK) @@ -1301,7 +1298,7 @@ namespace osl_FileBase void createTempFile_004() { - nError1 = osl::FileBase::createTempFile(pUStr_DirURL, nullptr, pUStr_FileURL); + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), nullptr, pUStr_FileURL.get()); bOK = (pUStr_FileURL != nullptr); CPPUNIT_ASSERT(bOK); File testFile(*pUStr_FileURL); @@ -1403,12 +1400,11 @@ namespace osl_FileStatus class isValid : public CppUnit::TestFixture { private: - Directory *pDir; + std::unique_ptr<Directory> pDir; DirectoryItem rItem_file, rItem_link; public: isValid() - : pDir(nullptr) { } @@ -1418,7 +1414,7 @@ namespace osl_FileStatus createTestDirectory(aTmpName3); createTestFile(aTmpName4); - pDir = new Directory(aTmpName3); + pDir.reset(new Directory(aTmpName3)); osl::FileBase::RC nError1 = pDir->open(); CPPUNIT_ASSERT_EQUAL(nError1, osl::FileBase::E_None); nError1 = pDir->getNextItem(rItem_file, 1); @@ -1428,7 +1424,7 @@ namespace osl_FileStatus void tearDown() override { osl::FileBase::RC nError1 = pDir->close(); - delete pDir; + pDir.reset(); CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), nError1, osl::FileBase::E_None); // remove the tempfile in $TEMP/tmpdir/tmpname. commit d911b3d37d13e84e0c6cb8eb990e58a0939a6f6a Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Thu Apr 12 11:23:58 2018 +0200 loplugin:useuniqueptr in OStorePageBIOS update the plugin to check all methods for deleting fields. Also remove the dead checks for new failing here, can never have worked, because it is not calling the std::nothrow variant. Change-Id: I139410e42f83ae2db0cd38ceee81c8b4c310268c Reviewed-on: https://gerrit.libreoffice.org/52881 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 5d00c1a637e8..192ae50a4eba 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -46,40 +46,40 @@ public: TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } - bool VisitCXXDestructorDecl(const CXXDestructorDecl* ); + bool VisitCXXMethodDecl(const CXXMethodDecl* ); bool VisitCompoundStmt(const CompoundStmt* ); private: - void CheckForUnconditionalDelete(const CXXDestructorDecl*, const CompoundStmt* ); - void CheckForSimpleDelete(const CXXDestructorDecl*, const CompoundStmt* ); - void CheckRangedLoopDelete(const CXXDestructorDecl*, const CXXForRangeStmt* ); - void CheckLoopDelete(const CXXDestructorDecl*, const Stmt* ); - void CheckLoopDelete(const CXXDestructorDecl*, const CXXDeleteExpr* ); - void CheckDeleteExpr(const CXXDestructorDecl*, const CXXDeleteExpr*); - void CheckDeleteExpr(const CXXDestructorDecl*, const CXXDeleteExpr*, + void CheckForUnconditionalDelete(const CXXMethodDecl*, const CompoundStmt* ); + void CheckForSimpleDelete(const CXXMethodDecl*, const CompoundStmt* ); + void CheckRangedLoopDelete(const CXXMethodDecl*, const CXXForRangeStmt* ); + void CheckLoopDelete(const CXXMethodDecl*, const Stmt* ); + void CheckLoopDelete(const CXXMethodDecl*, const CXXDeleteExpr* ); + void CheckDeleteExpr(const CXXMethodDecl*, const CXXDeleteExpr*); + void CheckDeleteExpr(const CXXMethodDecl*, const CXXDeleteExpr*, const MemberExpr*, StringRef message); }; -bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDecl) +bool UseUniquePtr::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) { - if (ignoreLocation(destructorDecl)) + if (ignoreLocation(methodDecl)) return true; - if (isInUnoIncludeFile(destructorDecl)) + if (isInUnoIncludeFile(methodDecl)) return true; - const CompoundStmt* compoundStmt = dyn_cast_or_null< CompoundStmt >( destructorDecl->getBody() ); + const CompoundStmt* compoundStmt = dyn_cast_or_null< CompoundStmt >( methodDecl->getBody() ); if (!compoundStmt || compoundStmt->size() == 0) return true; - CheckForSimpleDelete(destructorDecl, compoundStmt); + CheckForSimpleDelete(methodDecl, compoundStmt); for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i) { if (auto cxxForRangeStmt = dyn_cast<CXXForRangeStmt>(*i)) - CheckRangedLoopDelete(destructorDecl, cxxForRangeStmt); + CheckRangedLoopDelete(methodDecl, cxxForRangeStmt); else if (auto forStmt = dyn_cast<ForStmt>(*i)) - CheckLoopDelete(destructorDecl, forStmt->getBody()); + CheckLoopDelete(methodDecl, forStmt->getBody()); else if (auto whileStmt = dyn_cast<WhileStmt>(*i)) - CheckLoopDelete(destructorDecl, whileStmt->getBody()); + CheckLoopDelete(methodDecl, whileStmt->getBody()); } return true; @@ -88,14 +88,14 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec /** * check for simple call to delete in a destructor i.e. direct unconditional call, or if-guarded call */ -void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl, const CompoundStmt* compoundStmt) +void UseUniquePtr::CheckForSimpleDelete(const CXXMethodDecl* methodDecl, const CompoundStmt* compoundStmt) { for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i) { auto deleteExpr = dyn_cast<CXXDeleteExpr>(*i); if (deleteExpr) { - CheckDeleteExpr(destructorDecl, deleteExpr); + CheckDeleteExpr(methodDecl, deleteExpr); continue; } // Check for conditional deletes like: @@ -125,7 +125,7 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl, deleteExpr = dyn_cast<CXXDeleteExpr>(ifStmt->getThen()); if (deleteExpr) { - CheckDeleteExpr(destructorDecl, deleteExpr); + CheckDeleteExpr(methodDecl, deleteExpr); continue; } @@ -136,7 +136,7 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl, { auto ifDeleteExpr = dyn_cast<CXXDeleteExpr>(*j); if (ifDeleteExpr) - CheckDeleteExpr(destructorDecl, ifDeleteExpr); + CheckDeleteExpr(methodDecl, ifDeleteExpr); } } } @@ -144,7 +144,7 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl, /** * Check the delete expression in a destructor. */ -void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr) +void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDeleteExpr* deleteExpr) { const ImplicitCastExpr* castExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument()); if (!castExpr) @@ -152,14 +152,14 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons const MemberExpr* memberExpr = dyn_cast<MemberExpr>(castExpr->getSubExpr()); if (!memberExpr) return; - CheckDeleteExpr(destructorDecl, deleteExpr, memberExpr, + CheckDeleteExpr(methodDecl, deleteExpr, memberExpr, "unconditional call to delete on a member, should be using std::unique_ptr"); } /** * Check the delete expression in a destructor. */ -void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr, +void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDeleteExpr* deleteExpr, const MemberExpr* memberExpr, StringRef message) { // ignore union games @@ -171,7 +171,7 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons return; // ignore calling delete on someone else's field - if (fieldDecl->getParent() != destructorDecl->getParent() ) + if (fieldDecl->getParent() != methodDecl->getParent() ) return; if (ignoreLocation(fieldDecl)) @@ -240,21 +240,21 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons << fieldDecl->getSourceRange(); } -void UseUniquePtr::CheckLoopDelete(const CXXDestructorDecl* destructorDecl, const Stmt* bodyStmt) +void UseUniquePtr::CheckLoopDelete(const CXXMethodDecl* methodDecl, const Stmt* bodyStmt) { if (auto deleteExpr = dyn_cast<CXXDeleteExpr>(bodyStmt)) - CheckLoopDelete(destructorDecl, deleteExpr); + CheckLoopDelete(methodDecl, deleteExpr); else if (auto compoundStmt = dyn_cast<CompoundStmt>(bodyStmt)) { for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i) { if (auto deleteExpr = dyn_cast<CXXDeleteExpr>(*i)) - CheckLoopDelete(destructorDecl, deleteExpr); + CheckLoopDelete(methodDecl, deleteExpr); } } } -void UseUniquePtr::CheckLoopDelete(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr) +void UseUniquePtr::CheckLoopDelete(const CXXMethodDecl* methodDecl, const CXXDeleteExpr* deleteExpr) { const MemberExpr* memberExpr = nullptr; const Expr* subExpr = deleteExpr->getArgument(); @@ -280,10 +280,10 @@ void UseUniquePtr::CheckLoopDelete(const CXXDestructorDecl* destructorDecl, cons if (!memberExpr) return; - CheckDeleteExpr(destructorDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>"); + CheckDeleteExpr(methodDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>"); } -void UseUniquePtr::CheckRangedLoopDelete(const CXXDestructorDecl* destructorDecl, const CXXForRangeStmt* cxxForRangeStmt) +void UseUniquePtr::CheckRangedLoopDelete(const CXXMethodDecl* methodDecl, const CXXForRangeStmt* cxxForRangeStmt) { CXXDeleteExpr const * deleteExpr = nullptr; if (auto compoundStmt = dyn_cast<CompoundStmt>(cxxForRangeStmt->getBody())) @@ -299,7 +299,7 @@ void UseUniquePtr::CheckRangedLoopDelete(const CXXDestructorDecl* destructorDecl if (!fieldDecl) return; - CheckDeleteExpr(destructorDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>"); + CheckDeleteExpr(methodDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>"); } bool UseUniquePtr::VisitCompoundStmt(const CompoundStmt* compoundStmt) diff --git a/store/source/storbios.cxx b/store/source/storbios.cxx index 38673f7b8165..1a34da60d420 100644 --- a/store/source/storbios.cxx +++ b/store/source/storbios.cxx @@ -591,10 +591,9 @@ storeError OStorePageBIOS::initialize_Impl ( if (eAccessMode != storeAccessMode::Create) { // Load SuperBlock page. - if ((m_pSuper = new SuperBlockPage()) == nullptr) - return store_E_OutOfMemory; + m_pSuper.reset(new SuperBlockPage()); - eErrCode = read (0, m_pSuper, SuperBlockPage::theSize); + eErrCode = read (0, m_pSuper.get(), SuperBlockPage::theSize); if (eErrCode == store_E_None) { // Verify SuperBlock page (with repair). @@ -630,8 +629,7 @@ storeError OStorePageBIOS::initialize_Impl ( rnPageSize = ((rnPageSize + STORE_MINIMUM_PAGESIZE - 1) & ~(STORE_MINIMUM_PAGESIZE - 1)); // Create initial page (w/ SuperBlock). - if ((m_pSuper = new(rnPageSize) SuperBlockPage(rnPageSize)) == nullptr) - return store_E_OutOfMemory; + m_pSuper.reset(new(rnPageSize) SuperBlockPage(rnPageSize)); eErrCode = m_pSuper->save (*this, rnPageSize); } if (eErrCode == store_E_None) @@ -670,8 +668,7 @@ void OStorePageBIOS::cleanup_Impl() } // Release SuperBlock page. - delete m_pSuper; - m_pSuper = nullptr; + m_pSuper.reset(); // Release PageCache. m_xCache.clear(); diff --git a/store/source/storbios.hxx b/store/source/storbios.hxx index bea29f9f37fa..8c2abd54f5a7 100644 --- a/store/source/storbios.hxx +++ b/store/source/storbios.hxx @@ -120,7 +120,7 @@ private: rtl::Reference<ILockBytes> m_xLockBytes; osl::Mutex m_aMutex; - SuperBlockPage * m_pSuper; + std::unique_ptr<SuperBlockPage> m_pSuper; bool m_bWriteable; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits