[Libreoffice-commits] core.git: basic/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 4 13:39:26 UTC 2018


 basic/source/runtime/ddectrl.cxx |   41 +++++++++++++--------------------------
 basic/source/runtime/ddectrl.hxx |    2 -
 2 files changed, 15 insertions(+), 28 deletions(-)

New commits:
commit bdfa446d2e79ca1d8f45e39ad4ee0bfc753ed553
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Sep 4 13:19:39 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 4 15:39:05 2018 +0200

    loplugin:useuniqueptr in SbiDdeControl
    
    Change-Id: I7bded977d12b6105c15a4343206dc43d66b910c6
    Reviewed-on: https://gerrit.libreoffice.org/59974
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/basic/source/runtime/ddectrl.cxx b/basic/source/runtime/ddectrl.cxx
index adb2e7aebf2d..47858f2b97ff 100644
--- a/basic/source/runtime/ddectrl.cxx
+++ b/basic/source/runtime/ddectrl.cxx
@@ -22,8 +22,6 @@
 #include "ddectrl.hxx"
 #include <basic/sberrors.hxx>
 
-#define DDE_FREECHANNEL (reinterpret_cast<DdeConnection*>(sal_IntPtr(-1)))
-
 #define DDE_FIRSTERR    0x4000
 #define DDE_LASTERR     0x4011
 
@@ -88,13 +86,13 @@ size_t SbiDdeControl::GetFreeChannel()
 
     for (; nChannel < nListSize; ++nChannel)
     {
-        if (aConvList[nChannel] == DDE_FREECHANNEL)
+        if (!aConvList[nChannel])
         {
             return nChannel+1;
         }
     }
 
-    aConvList.push_back(DDE_FREECHANNEL);
+    aConvList.push_back(nullptr);
     return nChannel+1;
 }
 
@@ -102,17 +100,16 @@ ErrCode SbiDdeControl::Initiate( const OUString& rService, const OUString& rTopi
                                  size_t& rnHandle )
 {
     ErrCode nErr;
-    DdeConnection* pConv = new DdeConnection( rService, rTopic );
-    nErr = GetLastErr( pConv );
+    std::unique_ptr<DdeConnection> pConv(new DdeConnection( rService, rTopic ));
+    nErr = GetLastErr( pConv.get() );
     if( nErr )
     {
-        delete pConv;
         rnHandle = 0;
     }
     else
     {
         size_t nChannel = GetFreeChannel();
-        aConvList[nChannel-1] = pConv;
+        aConvList[nChannel-1] = std::move(pConv);
         rnHandle = nChannel;
     }
     return ERRCODE_NONE;
@@ -124,30 +121,20 @@ ErrCode SbiDdeControl::Terminate( size_t nChannel )
     {
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
-    DdeConnection* pConv = aConvList[nChannel-1];
+    DdeConnection* pConv = aConvList[nChannel-1].get();
 
-    if( pConv == DDE_FREECHANNEL )
+    if( !pConv )
     {
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
-    delete pConv;
-    aConvList[nChannel-1] = DDE_FREECHANNEL;
+    aConvList[nChannel-1].reset();
 
     return ERRCODE_NONE;
 }
 
 ErrCode SbiDdeControl::TerminateAll()
 {
-    for (DdeConnection* conv : aConvList)
-    {
-        if (conv != DDE_FREECHANNEL)
-        {
-            delete conv;
-        }
-    }
-
     aConvList.clear();
-
     return ERRCODE_NONE;
 }
 
@@ -158,9 +145,9 @@ ErrCode SbiDdeControl::Request( size_t nChannel, const OUString& rItem, OUString
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
 
-    DdeConnection* pConv = aConvList[nChannel-1];
+    DdeConnection* pConv = aConvList[nChannel-1].get();
 
-    if( pConv == DDE_FREECHANNEL )
+    if( !pConv )
     {
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
@@ -179,9 +166,9 @@ ErrCode SbiDdeControl::Execute( size_t nChannel, const OUString& rCommand )
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
 
-    DdeConnection* pConv = aConvList[nChannel-1];
+    DdeConnection* pConv = aConvList[nChannel-1].get();
 
-    if( pConv == DDE_FREECHANNEL )
+    if( !pConv )
     {
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
@@ -196,9 +183,9 @@ ErrCode SbiDdeControl::Poke( size_t nChannel, const OUString& rItem, const OUStr
     {
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
-    DdeConnection* pConv = aConvList[nChannel-1];
+    DdeConnection* pConv = aConvList[nChannel-1].get();
 
-    if( pConv == DDE_FREECHANNEL )
+    if( !pConv )
     {
         return ERRCODE_BASIC_DDE_NO_CHANNEL;
     }
diff --git a/basic/source/runtime/ddectrl.hxx b/basic/source/runtime/ddectrl.hxx
index 356fe42d684c..dd12241a31b5 100644
--- a/basic/source/runtime/ddectrl.hxx
+++ b/basic/source/runtime/ddectrl.hxx
@@ -32,7 +32,7 @@ private:
     DECL_LINK( Data, const DdeData*, void );
     static ErrCode GetLastErr( DdeConnection* );
     size_t GetFreeChannel();
-    std::vector<DdeConnection*> aConvList;
+    std::vector<std::unique_ptr<DdeConnection>> aConvList;
     OUString aData;
 
 public:


More information about the Libreoffice-commits mailing list