changeset 6763:1884e48a3207

clang-tidy (cont)
author Alain Mazy <am@orthanc.team>
date Mon, 11 May 2026 17:52:27 +0200
parents 8fb371d94576
children 18de08ccdd26
files OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.cpp OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp OrthancFramework/Sources/HttpServer/StringMatcher.cpp OrthancFramework/Sources/Toolbox.cpp OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp OrthancServer/Sources/SliceOrdering.cpp
diffstat 8 files changed, 40 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.cpp	Mon May 11 17:52:27 2026 +0200
@@ -435,7 +435,7 @@
       DIMSE_storeUser(&association_->GetDcmtkAssociation(), presID, &request,
                       NULL, dicom.getDataset(), ProgressCallback, NULL,
                       /*opt_blockMode*/ (GetParameters().HasTimeout() ? DIMSE_NONBLOCKING : DIMSE_BLOCKING),
-                      /*opt_dimse_timeout*/ GetParameters().GetTimeout(),
+                      /*opt_dimse_timeout*/ static_cast<int>(GetParameters().GetTimeout()),
                       &response, &statusDetail, NULL),
       GetParameters(), "C-STORE");
 
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Mon May 11 17:52:27 2026 +0200
@@ -670,7 +670,7 @@
           fastVersionSuccess = true;
         }
       }
-      catch (OrthancException&)
+      catch (OrthancException&) // NOLINT(bugprone-empty-catch)
       {
         // Unsupported conversion, use the slow version
       }
--- a/OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp	Mon May 11 17:52:27 2026 +0200
@@ -261,7 +261,7 @@
               }
             }
           }
-          catch (fs::filesystem_error&)
+          catch (fs::filesystem_error&)  // NOLINT(bugprone-empty-catch)
           {
           }
         }
@@ -298,7 +298,7 @@
     {
       fs::remove(p);
     }
-    catch (...)
+    catch (...) // NOLINT(bugprone-empty-catch)
     {
       // Ignore the error
     }
@@ -317,7 +317,7 @@
       fs::remove(p.parent_path().parent_path());
 #endif
     }
-    catch (...)
+    catch (...) // NOLINT(bugprone-empty-catch)
     {
       // Ignore the error
     }
--- a/OrthancFramework/Sources/HttpServer/StringMatcher.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancFramework/Sources/HttpServer/StringMatcher.cpp	Mon May 11 17:52:27 2026 +0200
@@ -95,7 +95,7 @@
     }
     else
     {
-      matchEnd_ = matchBegin_ + pattern_.size();
+      matchEnd_ = matchBegin_ + static_cast<off_t>(pattern_.size());
       assert(matchEnd_ <= end);
       valid_ = true;
     }
--- a/OrthancFramework/Sources/Toolbox.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancFramework/Sources/Toolbox.cpp	Mon May 11 17:52:27 2026 +0200
@@ -1250,8 +1250,8 @@
 
   static char Hex2Dec(char c)
   {
-    return ((c >= '0' && c <= '9') ? c - '0' :
-            ((c >= 'a' && c <= 'f') ? c - 'a' + 10 : c - 'A' + 10));
+    return static_cast<char>(((c >= '0' && c <= '9') ? c - '0' :
+            ((c >= 'a' && c <= 'f') ? c - 'a' + 10 : c - 'A' + 10)));
   }
 
   void Toolbox::UrlDecode(std::string& s)
@@ -1275,7 +1275,7 @@
           isalnum(s[source + 1]) &&
           isalnum(s[source + 2]))
       {
-        s[target] = (Hex2Dec(s[source + 1]) << 4) | Hex2Dec(s[source + 2]);
+        s[target] = static_cast<char>((Hex2Dec(s[source + 1]) << 4) | Hex2Dec(s[source + 2]));
         source += 3;
         target += 1;
       }
@@ -1738,8 +1738,8 @@
         uint8_t b = byte & 0x0f;
 
         target.push_back('%');
-        target.push_back(a < 10 ? a + '0' : a - 10 + 'A');
-        target.push_back(b < 10 ? b + '0' : b - 10 + 'A');
+        target.push_back(static_cast<char>(a < 10 ? a + '0' : a - 10 + 'A'));
+        target.push_back(static_cast<char>(b < 10 ? b + '0' : b - 10 + 'A'));
       }
     }
   }
@@ -1814,7 +1814,12 @@
                                                     const std::string& key,
                                                     unsigned int defaultValue)
   {
-    int v = GetJsonIntegerField(json, key, defaultValue);
+    if (defaultValue > std::numeric_limits<int>::max())
+    {
+      throw OrthancException(ErrorCode_InternalError, "Default value too large to fit in a int");
+    }
+
+    int v = GetJsonIntegerField(json, key, static_cast<int>(defaultValue));
 
     if (v < 0)
     {
@@ -2654,7 +2659,7 @@
 
     for (size_t i = decimal.size(); i > start; i--)
     {
-      s.push_back(decimal[i - 1] + '0');
+      s.push_back(static_cast<char>(decimal[i - 1] + '0'));
     }
 
     return s;
@@ -3017,7 +3022,7 @@
 
     for (size_t i = 0; i < converted.size(); i++)
     {
-      unsigned char c = converted[i];
+      char c = converted[i];
       bool allowRepetitions = true;
 
       if (isspace(c) ||
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Mon May 11 17:52:27 2026 +0200
@@ -28,7 +28,7 @@
 #include <boost/move/unique_ptr.hpp>
 #include <boost/thread.hpp>
 #include <boost/algorithm/string/join.hpp>
-
+#include <limits>
 
 #include <json/reader.h>
 #include <json/version.h>
@@ -227,7 +227,7 @@
     {
       Clear();
     }
-    catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&)
+    catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) // NOLINT(bugprone-empty-catch)
     {
       // Don't throw exceptions in destructors
     }
@@ -675,7 +675,7 @@
     {
       Clear();
     }
-    catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&)
+    catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) // NOLINT(bugprone-empty-catch)
     {
       // Don't throw exceptions in destructors
     }
@@ -977,7 +977,15 @@
         return true;
 
       case Json::uintValue:
-        target = configuration_[key].asUInt();
+        if (configuration_[key].asUInt() > std::numeric_limits<int>::max())
+        {
+          ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                    "\" is too large to fit in an integer");
+
+          ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);          
+        }
+
+        target = static_cast<int>(configuration_[key].asUInt());
         return true;
 
       default:
@@ -1338,7 +1346,7 @@
     {
       Clear();
     }
-    catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&)
+    catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) // NOLINT(bugprone-empty-catch)
     {
       // Don't throw exceptions in destructors
     }
--- a/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp	Mon May 11 17:52:27 2026 +0200
@@ -308,7 +308,7 @@
           }
         }
       }
-      catch (OrthancException&)
+      catch (OrthancException&)  // NOLINT(bugprone-empty-catch)
       {
       }
 
--- a/OrthancServer/Sources/SliceOrdering.cpp	Mon May 11 17:20:23 2026 +0200
+++ b/OrthancServer/Sources/SliceOrdering.cpp	Mon May 11 17:52:27 2026 +0200
@@ -26,6 +26,7 @@
 
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/Toolbox.h"
+#include "../../OrthancFramework/Sources/SerializationToolbox.h"
 #include "ServerEnumerations.h"
 #include "ServerIndex.h"
 
@@ -151,7 +152,7 @@
     bool          hasNormal_;
     Vector        normal_;   
     bool          hasIndexInSeries_;
-    size_t        indexInSeries_;
+    unsigned int  indexInSeries_;
     unsigned int  framesCount_;
 
   public:
@@ -171,14 +172,7 @@
           !frames->IsNull() &&
           !frames->IsBinary())
       {
-        try
-        {
-          const std::string token = Toolbox::StripSpaces(frames->GetContent());
-          framesCount_ = boost::lexical_cast<unsigned int>(token);
-        }
-        catch (boost::bad_lexical_cast&)
-        {
-        }
+        SerializationToolbox::ParseUnsignedInteger(framesCount_, Toolbox::StripSpaces(frames->GetContent()));
       }
       
       std::vector<float> tmp;
@@ -194,18 +188,11 @@
       hasNormal_ = ComputeNormal(normal_, instance);
       hasIndexInSeries_ = false;
 
-      try
-      {
-        std::string s;
+      std::string s;
   
-        if (index.LookupMetadata(s, instanceId, ResourceType_Instance, MetadataType_Instance_IndexInSeries))
-        {
-          indexInSeries_ = boost::lexical_cast<size_t>(Toolbox::StripSpaces(s));
-          hasIndexInSeries_ = true;
-        }
-      }
-      catch (boost::bad_lexical_cast&)
+      if (index.LookupMetadata(s, instanceId, ResourceType_Instance, MetadataType_Instance_IndexInSeries))
       {
+        hasIndexInSeries_ = SerializationToolbox::ParseUnsignedInteger(indexInSeries_, Toolbox::StripSpaces(s));
       }
     }
 
@@ -232,7 +219,7 @@
       return hasIndexInSeries_;
     }
     
-    size_t GetIndexInSeries() const
+    unsigned int GetIndexInSeries() const
     {
       assert(HasIndexInSeries());
       return indexInSeries_;