changeset 4201:2d5209153b32

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Sep 2020 08:18:28 +0200
parents 7112a8af0b63
children 2007ab69ac16
files OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp OrthancFramework/Sources/HttpClient.cpp OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h OrthancFramework/Sources/HttpServer/HttpOutput.cpp OrthancFramework/Sources/HttpServer/HttpServer.cpp OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h OrthancFramework/Sources/HttpServer/MultipartStreamReader.h OrthancFramework/Sources/HttpServer/StringHttpOutput.h OrthancFramework/Sources/HttpServer/StringMatcher.cpp OrthancFramework/Sources/HttpServer/StringMatcher.h OrthancFramework/Sources/Images/FontRegistry.cpp OrthancFramework/Sources/Images/ImageAccessor.cpp OrthancFramework/Sources/Images/ImageAccessor.h OrthancFramework/Sources/Images/ImageProcessing.cpp OrthancFramework/Sources/Images/PamReader.cpp OrthancFramework/Sources/Images/PngReader.cpp OrthancFramework/Sources/JobsEngine/Operations/JobOperationValue.h OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h OrthancFramework/Sources/WebServiceParameters.h OrthancServer/Plugins/Engine/OrthancPlugins.cpp
diffstat 21 files changed, 80 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -346,7 +346,7 @@
 
 
   template <typename PixelType>
-  static void CopyPixels(const ImageAccessor& target,
+  static void CopyPixels(ImageAccessor& target,
                          const DicomIntegerPixelAccessor& source)
   {
     // WARNING - "::min()" should be replaced by "::lowest()" if
--- a/OrthancFramework/Sources/HttpClient.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpClient.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -117,7 +117,7 @@
     {
     }
 
-    CurlHeaders(const HttpClient::HttpHeaders& headers)
+    explicit CurlHeaders(const HttpClient::HttpHeaders& headers)
     {
       for (HttpClient::HttpHeaders::const_iterator
              it = headers.begin(); it != headers.end(); ++it)
@@ -318,7 +318,6 @@
       try
       {
         assert(userdata != NULL);
-        CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata));
 
         size_t length = size * nmemb;
         if (length == 0)
@@ -333,6 +332,7 @@
           if (colon != std::string::npos &&
               eol != std::string::npos)
           {
+            CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata));
             std::string tmp(s.substr(0, colon));
 
             if (that.headersLowerCase_)
@@ -345,6 +345,7 @@
             if (!key.empty())
             {
               std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol));
+
               that.answer_.AddHeader(key, value);
             }
           }
@@ -369,7 +370,6 @@
       try
       {
         assert(userdata != NULL);
-        CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata));
 
         size_t length = size * nmemb;
         if (length == 0)
@@ -378,6 +378,7 @@
         }
         else
         {
+          CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata));
           that.answer_.AddChunk(buffer, length);
           return length;
         }
@@ -419,7 +420,7 @@
     }
 
     virtual void AddHeader(const std::string& key,
-                           const std::string& value)
+                           const std::string& value) ORTHANC_OVERRIDE
     {
       if (headers_ != NULL)
       {
@@ -428,7 +429,7 @@
     }
       
     virtual void AddChunk(const void* data,
-                          size_t size)
+                          size_t size) ORTHANC_OVERRIDE
     {
       answer_.AddChunk(data, size);
     }
--- a/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h	Thu Sep 17 08:18:28 2020 +0200
@@ -67,19 +67,19 @@
      * Implementation of the IHttpStreamAnswer interface.
      **/
 
-    virtual uint64_t GetContentLength()
+    virtual uint64_t GetContentLength() ORTHANC_OVERRIDE
     {
       return size_;
     }
 
-    virtual bool ReadNextChunk();
+    virtual bool ReadNextChunk() ORTHANC_OVERRIDE;
 
-    virtual const char* GetChunkContent()
+    virtual const char* GetChunkContent() ORTHANC_OVERRIDE
     {
       return chunk_.c_str();
     }
 
-    virtual size_t GetChunkSize()
+    virtual size_t GetChunkSize() ORTHANC_OVERRIDE
     {
       return chunkSize_;
     }
--- a/OrthancFramework/Sources/HttpServer/HttpOutput.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/HttpOutput.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -51,6 +51,7 @@
     state_(State_WritingHeader),
     status_(HttpStatus_200_Ok),
     hasContentLength_(false),
+    contentLength_(0),
     contentPosition_(0),
     keepAlive_(isKeepAlive)
   {
--- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -83,7 +83,8 @@
       struct mg_connection* connection_;
 
     public:
-      MongooseOutputStream(struct mg_connection* connection) : connection_(connection)
+      explicit MongooseOutputStream(struct mg_connection* connection) :
+        connection_(connection)
       {
       }
 
@@ -146,7 +147,7 @@
     std::string filename_;
 
   public:
-    ChunkedFile(const std::string& filename) :
+    explicit ChunkedFile(const std::string& filename) :
       filename_(filename)
     {
     }
@@ -284,6 +285,11 @@
   {
     struct mg_context *context_;
     ChunkStore chunkStore_;
+
+    PImpl() :
+      context_(NULL)
+    {
+    }
   };
 
 
@@ -300,18 +306,19 @@
     size_t length;
     try
     {
-      length = boost::lexical_cast<size_t>(contentLength);
+      int64_t tmp = boost::lexical_cast<int64_t>(contentLength);
+      if (tmp < 0)
+      {
+        return PostDataStatus_NoLength;
+      }
+
+      length = static_cast<size_t>(tmp);
     }
     catch (boost::bad_lexical_cast&)
     {
       return PostDataStatus_NoLength;
     }
 
-    if (length < 0)
-    {
-      length = 0;
-    }
-
     body.resize(length);
 
     size_t pos = 0;
@@ -500,10 +507,7 @@
               {
                 // This file is stored in a single chunk
                 completedFile.resize(chunkSize);
-                if (chunkSize > 0)
-                {
-                  memcpy(&completedFile[0], chunkData, chunkSize);
-                }
+                memcpy(&completedFile[0], chunkData, chunkSize);
                 return PostDataStatus_Success;
               }
               else
@@ -1053,24 +1057,23 @@
   }
 
 
-  HttpServer::HttpServer() : pimpl_(new PImpl)
+  HttpServer::HttpServer() :
+    pimpl_(new PImpl),
+    handler_(NULL),
+    remoteAllowed_(false),
+    authentication_(false),
+    sslVerifyPeers_(false),
+    ssl_(false),
+    port_(8000),
+    filter_(NULL),
+    keepAlive_(false),
+    httpCompression_(true),
+    exceptionFormatter_(NULL),
+    realm_(ORTHANC_REALM),
+    threadsCount_(50),  // Default value in mongoose
+    tcpNoDelay_(true),
+    requestTimeout_(30)  // Default value in mongoose/civetweb (30 seconds)    
   {
-    pimpl_->context_ = NULL;
-    handler_ = NULL;
-    remoteAllowed_ = false;
-    authentication_ = false;
-    ssl_ = false;
-    sslVerifyPeers_ = false;
-    port_ = 8000;
-    filter_ = NULL;
-    keepAlive_ = false;
-    httpCompression_ = true;
-    exceptionFormatter_ = NULL;
-    realm_ = ORTHANC_REALM;
-    threadsCount_ = 50;  // Default value in mongoose
-    tcpNoDelay_ = true;
-    requestTimeout_ = 30;  // Default value in mongoose/civetweb (30 seconds)
-
 #if ORTHANC_ENABLE_MONGOOSE == 1
     LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server";
 #endif
@@ -1384,7 +1387,7 @@
 
   void HttpServer::SetThreadsCount(unsigned int threads)
   {
-    if (threads <= 0)
+    if (threads == 0)
     {
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
@@ -1407,7 +1410,7 @@
 
   void HttpServer::SetRequestTimeout(unsigned int seconds)
   {
-    if (seconds <= 0)
+    if (seconds == 0)
     {
       throw OrthancException(ErrorCode_ParameterOutOfRange,
                              "Request timeout must be a stricly positive integer");
--- a/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h	Thu Sep 17 08:18:28 2020 +0200
@@ -60,24 +60,24 @@
 
     // This is the first method to be called
     virtual HttpCompression SetupHttpCompression(bool gzipAllowed,
-                                                 bool deflateAllowed);
+                                                 bool deflateAllowed) ORTHANC_OVERRIDE;
 
-    virtual bool HasContentFilename(std::string& filename)
+    virtual bool HasContentFilename(std::string& filename) ORTHANC_OVERRIDE
     {
       return source_.HasContentFilename(filename);
     }
 
-    virtual std::string GetContentType()
+    virtual std::string GetContentType() ORTHANC_OVERRIDE
     {
       return source_.GetContentType();
     }
 
-    virtual uint64_t GetContentLength();
+    virtual uint64_t GetContentLength() ORTHANC_OVERRIDE;
 
-    virtual bool ReadNextChunk();
+    virtual bool ReadNextChunk() ORTHANC_OVERRIDE;
 
-    virtual const char* GetChunkContent();
+    virtual const char* GetChunkContent() ORTHANC_OVERRIDE;
 
-    virtual size_t GetChunkSize();
+    virtual size_t GetChunkSize() ORTHANC_OVERRIDE;
   };
 }
--- a/OrthancFramework/Sources/HttpServer/MultipartStreamReader.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/MultipartStreamReader.h	Thu Sep 17 08:18:28 2020 +0200
@@ -64,7 +64,7 @@
     void ParseStream();
 
   public:
-    MultipartStreamReader(const std::string& boundary);
+    explicit MultipartStreamReader(const std::string& boundary);
 
     void SetBlockSize(size_t size);
 
--- a/OrthancFramework/Sources/HttpServer/StringHttpOutput.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/StringHttpOutput.h	Thu Sep 17 08:18:28 2020 +0200
@@ -39,11 +39,11 @@
     {
     }
 
-    virtual void OnHttpStatusReceived(HttpStatus status);
+    virtual void OnHttpStatusReceived(HttpStatus status) ORTHANC_OVERRIDE;
 
-    virtual void Send(bool isHeader, const void* buffer, size_t length);
+    virtual void Send(bool isHeader, const void* buffer, size_t length) ORTHANC_OVERRIDE;
 
-    virtual void DisableKeepAlive()
+    virtual void DisableKeepAlive() ORTHANC_OVERRIDE
     {
     }
 
--- a/OrthancFramework/Sources/HttpServer/StringMatcher.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/StringMatcher.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -42,7 +42,7 @@
   public:
     // WARNING - The lifetime of "pattern_" must be larger than
     // "search_", as the latter internally keeps a pointer to "pattern" (*)
-    Search(const std::string& pattern) :
+    explicit Search(const std::string& pattern) :
       algorithm_(pattern.begin(), pattern.end())
     {
     }
--- a/OrthancFramework/Sources/HttpServer/StringMatcher.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/HttpServer/StringMatcher.h	Thu Sep 17 08:18:28 2020 +0200
@@ -46,7 +46,7 @@
     Iterator                   matchEnd_;
     
   public:
-    StringMatcher(const std::string& pattern);
+    explicit StringMatcher(const std::string& pattern);
 
     const std::string& GetPattern() const
     {
--- a/OrthancFramework/Sources/Images/FontRegistry.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/Images/FontRegistry.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -70,7 +70,7 @@
 
   const Font* FontRegistry::FindFont(const std::string& fontName) const
   {
-    for (Fonts::const_iterator it = fonts_.begin(); it != fonts_.end(); it++)
+    for (Fonts::const_iterator it = fonts_.begin(); it != fonts_.end(); ++it)
     {
       if ((*it)->GetName() == fontName)
       {
--- a/OrthancFramework/Sources/Images/ImageAccessor.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/Images/ImageAccessor.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -92,7 +92,7 @@
   }
 
 
-  void* ImageAccessor::GetBuffer() const
+  void* ImageAccessor::GetBuffer()
   {
     if (readOnly_)
     {
@@ -117,7 +117,7 @@
   }
 
 
-  void* ImageAccessor::GetRow(unsigned int y) const
+  void* ImageAccessor::GetRow(unsigned int y)
   {
     if (readOnly_)
     {
--- a/OrthancFramework/Sources/Images/ImageAccessor.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/Images/ImageAccessor.h	Thu Sep 17 08:18:28 2020 +0200
@@ -110,11 +110,11 @@
       return buffer_;
     }
 
-    void* GetBuffer() const;
+    void* GetBuffer();
 
     const void* GetConstRow(unsigned int y) const;
 
-    void* GetRow(unsigned int y) const;
+    void* GetRow(unsigned int y);
 
     void AssignEmpty(PixelFormat format);
 
--- a/OrthancFramework/Sources/Images/ImageProcessing.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/Images/ImageProcessing.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -418,7 +418,7 @@
     for (unsigned int y = 0; y < height; y++)
     {
       TargetType* p = reinterpret_cast<TargetType*>(target.GetRow(y));
-      const SourceType* q = reinterpret_cast<const SourceType*>(source.GetRow(y));
+      const SourceType* q = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
 
       for (unsigned int x = 0; x < width; x++, p++, q++)
       {
@@ -1860,15 +1860,15 @@
 
     std::vector<int32_t> nodeX;
     nodeX.resize(cpSize);
-    int  nodes, pixelX, pixelY, i, j, swap ;
+    int  pixelX, pixelY, i, swap ;
 
     //  Loop through the rows of the image.
     for (pixelY = top; pixelY < bottom; pixelY++)
     {
       double y = (double)pixelY;
       //  Build a list of nodes.
-      nodes = 0;
-      j = static_cast<int>(cpSize) - 1;
+      int nodes = 0;
+      int j = static_cast<int>(cpSize) - 1;
 
       for (i = 0; i < static_cast<int>(cpSize); i++)
       {
@@ -2047,7 +2047,7 @@
   void ImageProcessing::Resize(ImageAccessor& target,
                                const ImageAccessor& source)
   {
-    if (source.GetFormat() != source.GetFormat())
+    if (source.GetFormat() != target.GetFormat())
     {
       throw OrthancException(ErrorCode_IncompatibleImageFormat);
     }
--- a/OrthancFramework/Sources/Images/PamReader.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/Images/PamReader.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -180,7 +180,7 @@
 
     unsigned int bytesPerChannel;
     PixelFormat format;
-    GetPixelFormat(format, bytesPerChannel, maxValue, channelCount, tupleType.c_str());
+    GetPixelFormat(format, bytesPerChannel, maxValue, channelCount, tupleType);
 
     unsigned int pitch = width * channelCount * bytesPerChannel;
 
--- a/OrthancFramework/Sources/Images/PngReader.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/Images/PngReader.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -42,7 +42,7 @@
     {
       FILE* fp_;
 
-      FileRabi(const char* filename)
+      explicit FileRabi(const char* filename)
       {
         fp_ = SystemToolbox::OpenFile(filename, FileMode_ReadBinary);
         if (!fp_)
@@ -81,12 +81,11 @@
       }
     }
 
-    PngRabi()
+    PngRabi() :
+      png_(NULL),
+      info_(NULL),
+      endInfo_(NULL)
     {
-      png_ = NULL;
-      info_ = NULL;
-      endInfo_ = NULL;
-
       png_ = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
       if (!png_)
       {
--- a/OrthancFramework/Sources/JobsEngine/Operations/JobOperationValue.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/JobsEngine/Operations/JobOperationValue.h	Thu Sep 17 08:18:28 2020 +0200
@@ -43,7 +43,7 @@
     Type  type_;
 
   protected:
-    JobOperationValue(Type type) :
+    explicit JobOperationValue(Type type) :
       type_(type)
     {
     }
--- a/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h	Thu Sep 17 08:18:28 2020 +0200
@@ -83,7 +83,7 @@
       boost::mutex::scoped_lock  lock_;
 
     public:
-      Lock(SequenceOfOperationsJob& that) :
+      explicit Lock(SequenceOfOperationsJob& that) :
         that_(that),
         lock_(that.mutex_)
       {
--- a/OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h	Thu Sep 17 08:18:28 2020 +0200
@@ -34,7 +34,7 @@
     std::string  content_;
 
   public:
-    StringOperationValue(const std::string& content) :
+    explicit StringOperationValue(const std::string& content) :
       JobOperationValue(JobOperationValue::Type_String),
       content_(content)
     {
--- a/OrthancFramework/Sources/WebServiceParameters.h	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancFramework/Sources/WebServiceParameters.h	Thu Sep 17 08:18:28 2020 +0200
@@ -58,7 +58,7 @@
   public:
     WebServiceParameters();
 
-    WebServiceParameters(const Json::Value& serialized)
+    explicit WebServiceParameters(const Json::Value& serialized)
     {
       Unserialize(serialized);
     }
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Sep 16 20:53:31 2020 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Thu Sep 17 08:18:28 2020 +0200
@@ -3901,7 +3901,7 @@
       case _OrthancPluginService_GetImageBuffer:
       {
         const _OrthancPluginGetImageInfo& p = *reinterpret_cast<const _OrthancPluginGetImageInfo*>(parameters);
-        *(p.resultBuffer) = reinterpret_cast<const ImageAccessor*>(p.image)->GetBuffer();
+        *(p.resultBuffer) = const_cast<void*>(reinterpret_cast<const ImageAccessor*>(p.image)->GetConstBuffer());
         return true;
       }