# HG changeset patch # User Sebastien Jodogne # Date 1618400028 -7200 # Node ID 33fa478c119a1fd2df440a21442b2efe0b3ea33a # Parent ed12248ad791a4fb2276af35c83eeffca7e4bbe9 cppcheck diff -r ed12248ad791 -r 33fa478c119a Framework/MySQL/MySQLDatabase.cpp --- 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) diff -r ed12248ad791 -r 33fa478c119a Framework/MySQL/MySQLTransaction.h --- 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 */); } diff -r ed12248ad791 -r 33fa478c119a Framework/Plugins/DatabaseBackendAdapterV2.cpp --- 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 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()) { diff -r ed12248ad791 -r 33fa478c119a Framework/Plugins/StorageBackend.cpp --- 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) { diff -r ed12248ad791 -r 33fa478c119a Framework/Plugins/StorageBackend.h --- 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 diff -r ed12248ad791 -r 33fa478c119a Framework/PostgreSQL/PostgreSQLDatabase.cpp --- 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) diff -r ed12248ad791 -r 33fa478c119a Framework/PostgreSQL/PostgreSQLParameters.cpp --- 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); diff -r ed12248ad791 -r 33fa478c119a Framework/SQLite/SQLiteDatabase.cpp --- 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) { } diff -r ed12248ad791 -r 33fa478c119a MySQL/Plugins/MySQLIndex.cpp --- 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), diff -r ed12248ad791 -r 33fa478c119a MySQL/Plugins/MySQLStorageArea.cpp --- 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) { } diff -r ed12248ad791 -r 33fa478c119a MySQL/Plugins/MySQLStorageArea.h --- 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; }; } diff -r ed12248ad791 -r 33fa478c119a MySQL/UnitTests/UnitTestsMain.cpp --- 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(i); std::string expected = "Value " + boost::lexical_cast(i * 2); - std::string content; if (i == 5) { diff -r ed12248ad791 -r 33fa478c119a PostgreSQL/Plugins/PostgreSQLStorageArea.h --- 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; } diff -r ed12248ad791 -r 33fa478c119a SQLite/Plugins/SQLiteIndex.h --- 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; }; }