changeset 6756:c05fdd7eea8c

cland-tidy (cont)
author Alain Mazy <am@orthanc.team>
date Mon, 11 May 2026 16:43:30 +0200
parents a5c8b1dcfaf5
children 8c7e733526b0
files OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp OrthancFramework/Sources/FileStorage/MemoryStorageArea.cpp OrthancFramework/Sources/HttpServer/HttpOutput.cpp OrthancFramework/Sources/MultiThreading/RunnableWorkersPool.cpp OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp OrthancServer/Sources/OrthancInitialization.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp OrthancServer/Sources/main.cpp
diffstat 10 files changed, 26 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Mon May 11 16:43:30 2026 +0200
@@ -301,7 +301,7 @@
       return ss.str();
     }
 
-    
+    // NOLINTBEGIN(bugprone-macro-parentheses)
 #define DCMTK_TO_CTYPE_CONVERTER(converter, cType, dcmtkType, getter, toStringFunction) \
                                                                         \
     struct converter                                                    \
@@ -322,6 +322,7 @@
         return toStringFunction(value);                                 \
       }                                                                 \
     };
+    // NOLINTEND(bugprone-macro-parentheses)
 
     DCMTK_TO_CTYPE_CONVERTER(DcmtkToSint32Converter, Sint32, DcmSignedLong, getSint32, boost::lexical_cast<std::string>)
     DCMTK_TO_CTYPE_CONVERTER(DcmtkToSint16Converter, Sint16, DcmSignedShort, getSint16, boost::lexical_cast<std::string>)
@@ -2611,7 +2612,7 @@
     DcmInputBufferStream is;
     if (size > 0)
     {
-      is.setBuffer(buffer, size);
+      is.setBuffer(buffer, static_cast<offile_off_t>(size));
     }
     is.setEos();
 
--- a/OrthancFramework/Sources/FileStorage/MemoryStorageArea.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancFramework/Sources/FileStorage/MemoryStorageArea.cpp	Mon May 11 16:43:30 2026 +0200
@@ -119,7 +119,7 @@
         range.resize(static_cast<size_t>(size));
         assert(!range.empty());
 
-        memcpy(&range[0], &found->second[start], range.size());
+        memcpy(&range[0], &found->second[start], range.size()); // NOLINT(bugprone-undefined-memory-manipulation)
         
         return StringMemoryBuffer::CreateFromSwap(range);
       }
--- a/OrthancFramework/Sources/HttpServer/HttpOutput.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancFramework/Sources/HttpServer/HttpOutput.cpp	Mon May 11 16:43:30 2026 +0200
@@ -802,7 +802,7 @@
       std::string header = "--" + multipartBoundary_ + "--\r\n";
       stream_.Send(false, header.c_str(), header.size());
     }
-    catch (OrthancException&)
+    catch (OrthancException&) //NOLINT(bugprone-empty-catch)
     {
     }
 
--- a/OrthancFramework/Sources/MultiThreading/RunnableWorkersPool.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancFramework/Sources/MultiThreading/RunnableWorkersPool.cpp	Mon May 11 16:43:30 2026 +0200
@@ -174,7 +174,7 @@
     std::unique_ptr<MetricsRegistry::SharedMetrics> availableWorkers(
       new MetricsRegistry::SharedMetrics(registry, availableWorkersMetricsName, MetricsUpdatePolicy_MinOver10Seconds));
 
-    availableWorkers->Add(countWorkers); // mark all workers as available
+    availableWorkers->Add(static_cast<int64_t>(countWorkers)); // mark all workers as available in the metrics
 
     Start(countWorkers, baseThreadName, availableWorkers.release());
   }
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Mon May 11 16:43:30 2026 +0200
@@ -1381,7 +1381,7 @@
     Float32 u;
     ASSERT_TRUE(f.GetDcmtkObject().getDataset()->findAndGetFloat32(DCM_ExaminedBodyThickness, u).good());
     ASSERT_FLOAT_EQ(u, v);
-    ASSERT_TRUE(memcmp(&u, &v, 4) == 0);
+    ASSERT_TRUE(memcmp(&u, &v, 4) == 0);  // NOLINT(bugprone-suspicious-memory-comparison)
   }
 
   {
@@ -1402,7 +1402,7 @@
     f.Apply(visitor);
     Float32 u = visitor.GetResult() ["00109431"]["Value"][0].asFloat();
     ASSERT_FLOAT_EQ(u, v);
-    ASSERT_TRUE(memcmp(&u, &v, 4) == 0);
+    ASSERT_TRUE(memcmp(&u, &v, 4) == 0);  // NOLINT(bugprone-suspicious-memory-comparison)
   }
 }
 
@@ -1578,7 +1578,7 @@
       throw OrthancException(ErrorCode_InternalError);
     }
 
-    result[i] = static_cast<uint8_t>(a * 16 + b);
+    result[i] = static_cast<char>(a * 16 + b);
   }
 
   return result;
@@ -3564,7 +3564,7 @@
   {
     DicomTransferSyntax a = (DicomTransferSyntax) i;
 
-    std::string path = (std::string(getenv("HOME")) +
+    std::string path = (std::string(getenv("HOME")) +                                     // NOLINT(clang-analyzer-cplusplus.StringChecker)
                         "/Subversion/orthanc-tests/Database/TransferSyntaxes/" +
                         std::string(GetTransferSyntaxUid(a)) + ".dcm");
     if (Orthanc::SystemToolbox::IsRegularFile(SystemToolbox::PathFromUtf8(path)))
@@ -3629,7 +3629,7 @@
     {
       DicomTransferSyntax a = (DicomTransferSyntax) i;
 
-      std::string path = (std::string(getenv("HOME")) +
+      std::string path = (std::string(getenv("HOME")) +                                 // NOLINT(clang-analyzer-cplusplus.StringChecker)
                           "/Subversion/orthanc-tests/Database/TransferSyntaxes/" +
                           std::string(GetTransferSyntaxUid(a)) + ".dcm");
       if (Orthanc::SystemToolbox::IsRegularFile(SystemToolbox::PathFromUtf8(path)))
@@ -3668,7 +3668,7 @@
 
   {
     std::string source;
-    Orthanc::SystemToolbox::ReadFile(source, std::string(getenv("HOME")) +
+    Orthanc::SystemToolbox::ReadFile(source, std::string(getenv("HOME")) +                        // NOLINT(clang-analyzer-cplusplus.StringChecker)
                                      "/Subversion/orthanc-tests/Database/KarstenHilbertRF.dcm");
     toto.reset(FromDcmtkBridge::LoadFromMemoryBuffer(source.c_str(), source.size()));
   }
--- a/OrthancServer/Sources/OrthancInitialization.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancServer/Sources/OrthancInitialization.cpp	Mon May 11 16:43:30 2026 +0200
@@ -404,7 +404,7 @@
     {
       // https://man7.org/linux/man-pages/man3/mallopt.3.html
       LOG(INFO) << "Calling mallopt(M_ARENA_MAX, " << maxArena << ")";
-      if (mallopt(M_ARENA_MAX, maxArena) != 1 /* success */)
+      if (mallopt(M_ARENA_MAX, static_cast<int>(maxArena)) != 1 /* success */)
       {
         throw OrthancException(ErrorCode_InternalError, "The call to mallopt(M_ARENA_MAX, " +
                                boost::lexical_cast<std::string>(maxArena) + ") has failed");
@@ -449,8 +449,9 @@
     {
       boost::filesystem::create_directories(indexDirectory);
     }
-    catch (boost::filesystem::filesystem_error&)
+    catch (boost::filesystem::filesystem_error& e)
     {
+      LOG(WARNING) << "Error encountered while creating IndexDirectory: " << e.what(); // the exception was ignored before 1.12.12; let's log it
     }
 
     return new SQLiteDatabaseWrapper(Orthanc::SystemToolbox::PathToUtf8(indexDirectory) + "/index");
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon May 11 16:43:30 2026 +0200
@@ -400,8 +400,9 @@
           return;
         }
       }
-      catch (OrthancException&)
+      catch (OrthancException&) // NOLINT(bugprone-empty-catch)
       {
+        // ignore any error when there is an accept header -> continue in normal mode to download the DICOM file
       }
     }
 
@@ -751,14 +752,10 @@
         std::string v = call.GetArgument("quality", "90" /* default JPEG quality */);
         bool ok = false;
 
-        try
+        if (SerializationToolbox::ParseUnsignedInteger(quality_, v))
         {
-          quality_ = boost::lexical_cast<unsigned int>(v);
           ok = (quality_ >= 1 && quality_ <= 100);
         }
-        catch (boost::bad_lexical_cast&)
-        {
-        }
 
         if (!ok)
         {
@@ -1865,19 +1862,15 @@
       std::string value = Toolbox::StripSpaces(found->second);
       Toolbox::RemoveSurroundingQuotes(value);
 
-      try
+      size_t comma = value.find('-');
+      if (comma != std::string::npos)
       {
-        size_t comma = value.find('-');
-        if (comma != std::string::npos)
+        if (SerializationToolbox::ParseInteger64(revision, value.substr(0, comma)))
         {
-          revision = boost::lexical_cast<int64_t>(value.substr(0, comma));
           md5 = value.substr(comma + 1);
           return true;
-        }        
-      }
-      catch (boost::bad_lexical_cast&)
-      {
-      }
+        }
+      }        
 
       throw OrthancException(ErrorCode_ParameterOutOfRange, "The \"" + header +
                              "\" HTTP header should contain the ETag (revision followed by MD5 hash), but found: " + value);
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Mon May 11 16:43:30 2026 +0200
@@ -1257,7 +1257,7 @@
             success = true;
           }
         }
-        catch (const OrthancException&)
+        catch (const OrthancException&) // NOLINT(bugprone-empty-catch)
         {
         }
       }
--- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp	Mon May 11 16:43:30 2026 +0200
@@ -475,7 +475,7 @@
           context.GetIndex().LookupResourceType(level, *it);
           parentResources_[*it] = level;
         }
-        catch(...)
+        catch(...) // NOLINT(bugprone-empty-catch)
         {
           // ignore errors, the resource might have disappear
         }
--- a/OrthancServer/Sources/main.cpp	Mon May 11 15:50:09 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Mon May 11 16:43:30 2026 +0200
@@ -2268,7 +2268,7 @@
         boost::posix_time::ptime converted(boost::posix_time::from_time_t(creation));
         version += " (" + boost::posix_time::to_iso_string(converted) + ")";
       }
-      catch (...)
+      catch (...) // NOLINT(bugprone-empty-catch)
       {
       }
     }