changeset 252:33fa478c119a

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Apr 2021 13:33:48 +0200
parents ed12248ad791
children 3bc442765b88
files Framework/MySQL/MySQLDatabase.cpp Framework/MySQL/MySQLTransaction.h Framework/Plugins/DatabaseBackendAdapterV2.cpp Framework/Plugins/StorageBackend.cpp Framework/Plugins/StorageBackend.h Framework/PostgreSQL/PostgreSQLDatabase.cpp Framework/PostgreSQL/PostgreSQLParameters.cpp Framework/SQLite/SQLiteDatabase.cpp MySQL/Plugins/MySQLIndex.cpp MySQL/Plugins/MySQLStorageArea.cpp MySQL/Plugins/MySQLStorageArea.h MySQL/UnitTests/UnitTestsMain.cpp PostgreSQL/Plugins/PostgreSQLStorageArea.h SQLite/Plugins/SQLiteIndex.h
diffstat 14 files changed, 49 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/MySQL/MySQLDatabase.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/MySQL/MySQLDatabase.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -558,7 +558,7 @@
       }
 
     public:
-      MySQLImplicitTransaction(MySQLDatabase& db) :
+      explicit MySQLImplicitTransaction(MySQLDatabase& db) :
         db_(db)
       {
       }
@@ -678,7 +678,7 @@
       }
       
     public:
-      Factory(const MySQLParameters& parameters) :
+      explicit Factory(const MySQLParameters& parameters) :
         RetryDatabaseFactory(parameters.GetMaxConnectionRetries(),
                              parameters.GetConnectionRetryInterval()),
         parameters_(parameters)
--- a/Framework/MySQL/MySQLTransaction.h	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/MySQL/MySQLTransaction.h	Wed Apr 14 13:33:48 2021 +0200
@@ -57,17 +57,17 @@
     virtual void ExecuteWithoutResult(IPrecompiledStatement& transaction,
                                       const Dictionary& parameters) ORTHANC_OVERRIDE;
 
-    virtual bool DoesTableExist(const std::string& name)
+    virtual bool DoesTableExist(const std::string& name) ORTHANC_OVERRIDE
     {
       return db_.DoesTableExist(*this, name);
     }
 
-    virtual bool DoesTriggerExist(const std::string& name)
+    virtual bool DoesTriggerExist(const std::string& name) ORTHANC_OVERRIDE
     {
       return db_.DoesTriggerExist(*this, name);
     }
 
-    virtual void ExecuteMultiLines(const std::string& query)
+    virtual void ExecuteMultiLines(const std::string& query) ORTHANC_OVERRIDE
     {
       db_.ExecuteMultiLines(query, false /* don't deal with arobases */);
     }
--- a/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -69,7 +69,7 @@
     std::unique_ptr<DatabaseManager>   manager_;
 
   public:
-    Adapter(IDatabaseBackend* backend) :
+    explicit Adapter(IDatabaseBackend* backend) :
       backend_(backend)
     {
       if (backend == NULL)
@@ -119,7 +119,7 @@
       DatabaseManager*           manager_;
       
     public:
-      DatabaseAccessor(Adapter& adapter) :
+      explicit DatabaseAccessor(Adapter& adapter) :
         lock_(adapter.managerMutex_),
         manager_(adapter.manager_.get())
       {
--- a/Framework/Plugins/StorageBackend.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/Plugins/StorageBackend.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -458,6 +458,20 @@
       {
       }
 
+      ~Visitor()
+      {
+        if (data_ != NULL /* this condition is invalidated by "Release()" */ &&
+            *data_ != NULL)
+        {
+          free(*data_);
+        }
+      }
+
+      void Release()
+      {
+        data_ = NULL;
+      }      
+
       virtual bool IsSuccess() const ORTHANC_OVERRIDE
       {
         return success_;
@@ -469,6 +483,11 @@
         {
           throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
         }
+        else if (data_ == NULL)
+        {
+          // "Release()" has been called
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+        }
         else
         {
           if (content.empty())
@@ -521,6 +540,8 @@
           accessor->ReadWhole(visitor, uuid, type);
         }
 
+        visitor.Release();
+
         return OrthancPluginErrorCode_Success;
       }
     }
@@ -609,7 +630,7 @@
     bool          success_;
       
   public:
-    StringVisitor(std::string& target) :
+    explicit StringVisitor(std::string& target) :
       target_(target),
       success_(false)
     {
--- a/Framework/Plugins/StorageBackend.h	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/Plugins/StorageBackend.h	Wed Apr 14 13:33:48 2021 +0200
@@ -87,7 +87,7 @@
       DatabaseManager&           manager_;
 
     public:
-      AccessorBase(StorageBackend& backend) :
+      explicit AccessorBase(StorageBackend& backend) :
         lock_(backend.mutex_),
         manager_(backend.GetManager())
       {
@@ -101,20 +101,20 @@
       virtual void Create(const std::string& uuid,
                           const void* content,
                           size_t size,
-                          OrthancPluginContentType type);
+                          OrthancPluginContentType type) ORTHANC_OVERRIDE;
 
       virtual void ReadWhole(IFileContentVisitor& visitor,
                              const std::string& uuid,
-                             OrthancPluginContentType type);
+                             OrthancPluginContentType type) ORTHANC_OVERRIDE;
 
       virtual void ReadRange(IFileContentVisitor& visitor,
                              const std::string& uuid,
                              OrthancPluginContentType type,
                              uint64_t start,
-                             size_t length);
+                             size_t length) ORTHANC_OVERRIDE;
       
       virtual void Remove(const std::string& uuid,
-                          OrthancPluginContentType type);
+                          OrthancPluginContentType type) ORTHANC_OVERRIDE;
     };
     
     void SetDatabase(IDatabase* database);  // Takes ownership
--- a/Framework/PostgreSQL/PostgreSQLDatabase.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/PostgreSQL/PostgreSQLDatabase.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -250,7 +250,7 @@
       }
 
     public:
-      PostgreSQLImplicitTransaction(PostgreSQLDatabase& db) :
+      explicit PostgreSQLImplicitTransaction(PostgreSQLDatabase& db) :
         db_(db)
       {
       }
@@ -341,7 +341,7 @@
       }
       
     public:
-      Factory(const PostgreSQLParameters& parameters) :
+      explicit Factory(const PostgreSQLParameters& parameters) :
         RetryDatabaseFactory(parameters.GetMaxConnectionRetries(),
                              parameters.GetConnectionRetryInterval()),
         parameters_(parameters)
--- a/Framework/PostgreSQL/PostgreSQLParameters.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/PostgreSQL/PostgreSQLParameters.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -150,7 +150,7 @@
 
   void PostgreSQLParameters::SetPortNumber(unsigned int port)
   {
-    if (port <= 0 ||
+    if (port == 0 ||
         port >= 65535)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
--- a/Framework/SQLite/SQLiteDatabase.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/SQLite/SQLiteDatabase.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -65,7 +65,7 @@
       }
 
     public:
-      SQLiteImplicitTransaction(SQLiteDatabase& db) :
+      explicit SQLiteImplicitTransaction(SQLiteDatabase& db) :
         db_(db)
       {
       }
--- a/MySQL/Plugins/MySQLIndex.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/MySQL/Plugins/MySQLIndex.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -343,8 +343,6 @@
 
     while (!done)
     {
-      int64_t parentId;
-      
       {
         DatabaseManager::CachedStatement lookupSiblings(
           STATEMENT_FROM_HERE, manager,
@@ -365,7 +363,7 @@
         }
         else
         {
-          parentId = ReadInteger64(lookupSiblings, 0);
+          int64_t parentId = ReadInteger64(lookupSiblings, 0);
           lookupSiblings.Next();
 
           if (lookupSiblings.IsDone())
@@ -385,10 +383,10 @@
             
             parent.SetParameterType("id", ValueType_Integer64);
 
-            Dictionary args;
-            args.SetIntegerValue("id", parentId);
+            Dictionary args2;
+            args2.SetIntegerValue("id", parentId);
     
-            parent.Execute(args);
+            parent.Execute(args2);
 
             output.SignalRemainingAncestor(
               ReadString(parent, 0),
--- a/MySQL/Plugins/MySQLStorageArea.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/MySQL/Plugins/MySQLStorageArea.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -104,7 +104,7 @@
   class MySQLStorageArea::Accessor : public StorageBackend::AccessorBase
   {
   public:
-    Accessor(MySQLStorageArea& backend) :
+    explicit Accessor(MySQLStorageArea& backend) :
       AccessorBase(backend)
     {
     }
--- a/MySQL/Plugins/MySQLStorageArea.h	Wed Apr 14 11:20:51 2021 +0200
+++ b/MySQL/Plugins/MySQLStorageArea.h	Wed Apr 14 13:33:48 2021 +0200
@@ -37,7 +37,7 @@
                            bool clearAll);
 
   protected:
-    virtual bool HasReadRange() const
+    virtual bool HasReadRange() const ORTHANC_OVERRIDE
     {
       return true;
     }
@@ -46,6 +46,6 @@
     MySQLStorageArea(const MySQLParameters& parameters,
                      bool clearAll);
 
-    virtual IAccessor* CreateAccessor();
+    virtual IAccessor* CreateAccessor() ORTHANC_OVERRIDE;
   };
 }
--- a/MySQL/UnitTests/UnitTestsMain.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/MySQL/UnitTests/UnitTestsMain.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -187,7 +187,6 @@
     {
       std::string uuid = boost::lexical_cast<std::string>(i);
       std::string expected = "Value " + boost::lexical_cast<std::string>(i * 2);
-      std::string content;
 
       if (i == 5)
       {
--- a/PostgreSQL/Plugins/PostgreSQLStorageArea.h	Wed Apr 14 11:20:51 2021 +0200
+++ b/PostgreSQL/Plugins/PostgreSQLStorageArea.h	Wed Apr 14 13:33:48 2021 +0200
@@ -34,7 +34,7 @@
                            bool clearAll);
 
   protected:
-    virtual bool HasReadRange() const
+    virtual bool HasReadRange() const ORTHANC_OVERRIDE
     {
       return true;
     }
--- a/SQLite/Plugins/SQLiteIndex.h	Wed Apr 14 11:20:51 2021 +0200
+++ b/SQLite/Plugins/SQLiteIndex.h	Wed Apr 14 13:33:48 2021 +0200
@@ -32,7 +32,7 @@
     bool         fast_;
 
   public:
-    SQLiteIndex(OrthancPluginContext* context);  // Opens in memory
+    explicit SQLiteIndex(OrthancPluginContext* context);  // Opens in memory
 
     SQLiteIndex(OrthancPluginContext* context,
                 const std::string& path);
@@ -48,9 +48,9 @@
     
     virtual int64_t CreateResource(DatabaseManager& manager,
                                    const char* publicId,
-                                   OrthancPluginResourceType type);
+                                   OrthancPluginResourceType type) ORTHANC_OVERRIDE;
 
     // New primitive since Orthanc 1.5.2
-    virtual int64_t GetLastChangeIndex(DatabaseManager& manager);
+    virtual int64_t GetLastChangeIndex(DatabaseManager& manager) ORTHANC_OVERRIDE;
   };
 }