changeset 6374:60e32e442218

cppcheck: variableScope
author Alain Mazy <am@orthanc.team>
date Mon, 10 Nov 2025 17:33:52 +0100
parents 3167e80eae75
children ab58c6884a8d
files OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp OrthancFramework/UnitTestsSources/JobsTests.cpp OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp OrthancServer/Resources/RunCppCheck.sh OrthancServer/Sources/OrthancGetRequestHandler.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/Sources/ServerJobs/DicomGetScuJob.cpp OrthancServer/Sources/SimpleInstanceOrdering.cpp OrthancServer/Sources/SliceOrdering.cpp
diffstat 10 files changed, 28 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -3630,9 +3630,9 @@
         std::string source;
         Orthanc::SystemToolbox::ReadFile(source, SystemToolbox::PathFromUtf8(path));
 
-        std::string c, k;
         try
         {
+          std::string c, k;
           scu.Transcode(c, k, transcoder, source.c_str(), source.size(),
                         DicomTransferSyntax_LittleEndianExplicit, false, "", 0);
         }
@@ -3678,8 +3678,6 @@
     std::set<DicomTransferSyntax> s;
     s.insert(a);
 
-    std::string t;
-
     IDicomTranscoder::DicomImage source, target;
     source.AcquireParsed(dynamic_cast<DcmFileFormat*>(toto->clone()));
 
@@ -3698,7 +3696,6 @@
                     a == DicomTransferSyntax_JPEGProcess2_4 ||
                     a == DicomTransferSyntax_JPEGLSLossy);
       
-      printf("SIZE: %d\n", static_cast<int>(t.size()));
       if (sourceUid == IDicomTranscoder::GetSopInstanceUid(target.GetParsed()))
       {
         ASSERT_FALSE(lossy);
--- a/OrthancFramework/UnitTestsSources/JobsTests.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancFramework/UnitTestsSources/JobsTests.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -282,10 +282,10 @@
 
 TEST(MultiThreading, SharedMessageQueueClean)
 {
-  std::set<int> s;
-
   try
   {
+    std::set<int> s;
+
     SharedMessageQueue q;
     q.Enqueue(new DynamicInteger(10, s));
     q.Enqueue(new DynamicInteger(20, s));  
@@ -740,10 +740,10 @@
   engine.SetWorkersCount(3);
   engine.Start();
 
-  std::string id;
   SequenceOfOperationsJob* job = NULL;
 
   {
+    std::string id;
     std::unique_ptr<SequenceOfOperationsJob> a(new SequenceOfOperationsJob);
     job = a.get();
     engine.GetRegistry().Submit(id, a.release(), 0);
@@ -1137,9 +1137,9 @@
 TEST(JobsSerialization, Registry)
 {   
   Json::Value s;
-  std::string i1, i2;
 
   {
+    std::string i1, i2;
     JobsRegistry registry(10);
     registry.Submit(i1, new DummyJob(), 10);
     registry.Submit(i2, new SequenceOfOperationsJob(), 30);
--- a/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -107,7 +107,7 @@
   bool isInPeriod() const
   {
     time_t now = time(NULL);
-    tm* nowLocalTime = localtime(&now);
+    const tm* nowLocalTime = localtime(&now);
 
     if (nowLocalTime->tm_wday != weekday_)
     {
--- a/OrthancServer/Resources/RunCppCheck.sh	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Resources/RunCppCheck.sh	Mon Nov 10 17:33:52 2025 +0100
@@ -39,9 +39,18 @@
 assertWithSideEffect:../../OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp:3066
 assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:286
 assertWithSideEffect:../../OrthancFramework/Sources/DicomNetworking/Internals/CommandDispatcher.cpp:454
+variableScope:../../OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp:228
+variableScope:../../OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp:94
 EOF
 
-${CPPCHECK} --enable=all --quiet --std=c++11 \
+# TODO: re-enable nullPointerOutOfMemory
+
+${CPPCHECK} -j 8 --enable=all --quiet --std=c++11 \
+            --suppress=missingIncludeSystem \
+            --suppress=missingInclude \
+            --suppress=useStlAlgorithm \
+            --suppress:nullPointerOutOfMemory \
+            --check-level=exhaustive \
             --suppressions-list=/tmp/cppcheck-suppressions.txt \
             -DBOOST_HAS_DATE_TIME=1 \
             -DBOOST_HAS_FILESYSTEM_V3=1 \
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -137,9 +137,10 @@
       LST_Position(l, (LST_NODE*)pc);
       while (pc)
       {
-        DicomTransferSyntax transferSyntax;
         if (pc->result == ASC_P_ACCEPTANCE)
         {
+          DicomTransferSyntax transferSyntax;
+          
           if (LookupTransferSyntax(transferSyntax, pc->acceptedTransferSyntax))
           {
             /*CLOG(TRACE, DICOM) << "C-GET SCP accepted: SOP class " << pc->abstractSyntax
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -186,10 +186,10 @@
           std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromBuffer(content));
           toStore->SetOrigin(DicomInstanceOrigin::FromRest(call));
 
-          std::string publicId;
-
           try
           {
+            std::string publicId;
+            
             ServerContext::StoreResult result = context.Store(publicId, *toStore, StoreInstanceMode_Default);
 
             Json::Value info;
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -1221,10 +1221,10 @@
             std::unique_ptr<DicomInstanceToStore> instance(DicomInstanceToStore::CreateFromBuffer(uncompressedFile));
             instance->SetOrigin(DicomInstanceOrigin::FromWebDav());
 
-            std::string publicId;
-
             try
             {
+              std::string publicId;
+              
               context_.Store(publicId, *instance, StoreInstanceMode_Default);
             }
             catch (OrthancException& e)
--- a/OrthancServer/Sources/ServerJobs/DicomGetScuJob.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Sources/ServerJobs/DicomGetScuJob.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -75,11 +75,12 @@
     if (connection_.get() == NULL)
     {
       std::set<std::string> sopClassesToPropose;
-      std::set<std::string> acceptedSopClasses;
       std::list<DicomTransferSyntax> proposedTransferSyntaxes;
 
       if (sopClassesFromResourcesToRetrieve_.size() > 0)
       {
+        std::set<std::string> acceptedSopClasses;
+        
         context_.GetAcceptedSopClasses(acceptedSopClasses, 0); 
 
         // keep the sop classes from the resources to retrieve only if they are accepted by Orthanc
--- a/OrthancServer/Sources/SimpleInstanceOrdering.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Sources/SimpleInstanceOrdering.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -96,7 +96,6 @@
     for (size_t i = 0; i < response.GetSize(); ++i)
     {
       const FindResponse::Resource& resource = response.GetResourceByIndex(i);
-      std::string instanceId = resource.GetIdentifier();
 
       std::string strIndexInSeries;
       uint32_t indexInSeries = 0;
@@ -110,6 +109,8 @@
 
       if (resource.LookupAttachment(fileInfo, revisionNotUsed, FileContentType_Dicom))
       {
+        std::string instanceId = resource.GetIdentifier();
+        
         allIndexInSeries.insert(indexInSeries);
         instances_.push_back(new SimpleInstanceOrdering::Instance(instanceId, indexInSeries, fileInfo));
       }
--- a/OrthancServer/Sources/SliceOrdering.cpp	Fri Nov 07 18:51:42 2025 +0100
+++ b/OrthancServer/Sources/SliceOrdering.cpp	Mon Nov 10 17:33:52 2025 +0100
@@ -192,12 +192,12 @@
       }
 
       hasNormal_ = ComputeNormal(normal_, instance);
-
-      std::string s;
       hasIndexInSeries_ = false;
 
       try
       {
+        std::string s;
+  
         if (index.LookupMetadata(s, instanceId, ResourceType_Instance, MetadataType_Instance_IndexInSeries))
         {
           indexInSeries_ = boost::lexical_cast<size_t>(Toolbox::StripSpaces(s));