From 1876812b7eb66f73f086386552f798d62e0b30be Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Wed, 16 Dec 2015 19:25:52 +0000
Subject: [PATCH] Remove some CppCheck warnings

---
 DDCond/src/ConditionTest.cpp             |  2 ++
 DDCore/src/Evaluator/Evaluator.cpp       |  8 ++++----
 DDCore/src/LCDDImp.cpp                   | 10 ++++++++--
 DDCore/src/LCDDImp.h                     | 12 +++++++-----
 DDCore/src/VolumeManager.cpp             |  4 ++--
 DDEve/src/EventControl.cpp               |  3 ++-
 DDG4/lcio/LCIOSDTestActions.cpp          |  2 +-
 DDG4/plugins/Geant4EventReaderHepEvt.cpp |  6 +++---
 DDG4/plugins/Geant4EventReaderHepMC.cpp  |  2 +-
 DDG4/python/DDG4Dict.C                   | 14 +++++++-------
 10 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/DDCond/src/ConditionTest.cpp b/DDCond/src/ConditionTest.cpp
index 903d243c5..a9bf27c5c 100644
--- a/DDCond/src/ConditionTest.cpp
+++ b/DDCond/src/ConditionTest.cpp
@@ -90,6 +90,8 @@ DECLARE_APPLY(ConditionsTest1,conditions_test)
 namespace {
 
   struct Callee  {
+    int m_param;
+    Callee() : m_param(0) {}
     void call(unsigned long tags, DetElement& det, void* param)    {
       if ( DetElement::CONDITIONS_CHANGED == (tags&DetElement::CONDITIONS_CHANGED) )
         printout(INFO,"Callee","+++ Conditions update %s param:%p",det.path().c_str(),param);
diff --git a/DDCore/src/Evaluator/Evaluator.cpp b/DDCore/src/Evaluator/Evaluator.cpp
index 14cd8b46d..ab833a5de 100644
--- a/DDCore/src/Evaluator/Evaluator.cpp
+++ b/DDCore/src/Evaluator/Evaluator.cpp
@@ -21,10 +21,10 @@ struct Item {
   string expression;
   void   *function;
 
-  Item()         : what(UNKNOWN),   variable(0),expression(), function(0) {}
-  Item(double x) : what(VARIABLE),  variable(x),expression(), function(0) {}
-  Item(string x) : what(EXPRESSION),variable(0),expression(x),function(0) {}
-  Item(void  *x) : what(FUNCTION),  variable(0),expression(), function(x) {}
+  explicit Item()         : what(UNKNOWN),   variable(0),expression(), function(0) {}
+  explicit Item(double x) : what(VARIABLE),  variable(x),expression(), function(0) {}
+  explicit Item(string x) : what(EXPRESSION),variable(0),expression(x),function(0) {}
+  explicit Item(void  *x) : what(FUNCTION),  variable(0),expression(), function(x) {}
 };
 
 typedef char * pchar;
diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp
index 080043b16..016d0a684 100644
--- a/DDCore/src/LCDDImp.cpp
+++ b/DDCore/src/LCDDImp.cpp
@@ -86,11 +86,17 @@ namespace {
 }
 
 /// Disable copy constructor
-LCDDImp::LCDDImp(const LCDDImp&) : LCDD(), LCDDData(), LCDDLoad(this), m_buildType(BUILD_NONE)  {
+LCDDImp::LCDDImp(const LCDDImp& copy) : LCDD(copy), LCDDData(copy), LCDDLoad(this),
+                                        m_detectorTypes(copy.m_detectorTypes),
+                                        m_buildType(copy.m_buildType)
+{
 }
 
 /// Disable assignment operator
-LCDDImp& LCDDImp::operator=(const LCDDImp&) {
+LCDDImp& LCDDImp::operator=(const LCDDImp& c) {
+  // Useless, but keep code checker happy....
+  m_detectorTypes = c.m_detectorTypes;
+  m_buildType = c.m_buildType;
   return *this;
 }
 
diff --git a/DDCore/src/LCDDImp.h b/DDCore/src/LCDDImp.h
index 5dd269977..e3af755d1 100644
--- a/DDCore/src/LCDDImp.h
+++ b/DDCore/src/LCDDImp.h
@@ -41,14 +41,19 @@ namespace DD4hep {
     protected:
       /// Cached map with detector types:
       typedef std::map<std::string, std::vector<DetElement> > DetectorTypeMap;
+
+      /// Inventory of detector types
       DetectorTypeMap m_detectorTypes;
 
+      /// VolumeManager m_volManager;
+      LCDDBuildType m_buildType;
+
     private:
       /// Disable copy constructor
-      LCDDImp(const LCDDImp&);
+      LCDDImp(const LCDDImp& copy);
 
       /// Disable assignment operator
-      LCDDImp& operator=(const LCDDImp&);
+      LCDDImp& operator=(const LCDDImp& copy);
 
       /// Internal helper to map detector types once the geometry is closed
       void mapDetectorTypes();
@@ -57,9 +62,6 @@ namespace DD4hep {
       /// Local method (no interface): Load volume manager.
       void imp_loadVolumeManager();
 
-      /// VolumeManager m_volManager;
-      LCDDBuildType m_buildType;
-
       /// Default constructor
       LCDDImp();
 
diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp
index 5601fff60..446f44eb8 100644
--- a/DDCore/src/VolumeManager.cpp
+++ b/DDCore/src/VolumeManager.cpp
@@ -153,7 +153,7 @@ namespace {
     }
 
     /// Compute the encoding for a set of VolIDs within a readout descriptor
-    pair<VolumeID, VolumeID> encoding(const IDDescriptor iddesc, const VolIDs& ids) const {
+    static pair<VolumeID, VolumeID> encoding(const IDDescriptor iddesc, const VolIDs& ids) const {
       VolumeID volume_id = 0, mask = 0;
       for (VolIDs::const_iterator i = ids.begin(); i != ids.end(); ++i) {
         const PlacedVolume::VolID& id = (*i);
@@ -202,7 +202,7 @@ namespace {
     }
 
     void print_node(SensitiveDetector sd, DetElement parent, DetElement e,
-                    const TGeoNode* n, const VolIDs& ids, const Chain& /* nodes */)
+                    const TGeoNode* n, const VolIDs& ids, const Chain& /* nodes */) const
     {
       static int s_count = 0;
       Readout ro = sd.readout();
diff --git a/DDEve/src/EventControl.cpp b/DDEve/src/EventControl.cpp
index 950df9b07..0cbd78871 100644
--- a/DDEve/src/EventControl.cpp
+++ b/DDEve/src/EventControl.cpp
@@ -90,7 +90,8 @@ bool EventControl::Open()   {
 /// EventConsumer overload: New event data file
 void EventControl::OnFileOpen(EventHandler* handler)  {
   char text[1024], fname[1024];
-  ::strncpy(fname, handler->datasourceName().c_str(), sizeof(fname));
+  ::strncpy(fname, handler->datasourceName().c_str(), sizeof(fname)-1);
+  fname[sizeof(fname)-1] = 0;
   // -----------------------------------------------------------------------------------------
   if ( handler && handler->hasFile() )   {
     ::snprintf(text,sizeof(text),"Number of events: %ld",handler->numEvents());
diff --git a/DDG4/lcio/LCIOSDTestActions.cpp b/DDG4/lcio/LCIOSDTestActions.cpp
index 0377f7b94..1603f814b 100644
--- a/DDG4/lcio/LCIOSDTestActions.cpp
+++ b/DDG4/lcio/LCIOSDTestActions.cpp
@@ -140,7 +140,7 @@ namespace  Tests {
     // hit->momentum      = direction;
     // hit->length        = hit_len;
     collection(m_collectionID)->add(hit);
-    return hit != 0;
+    return true;
   }
 
   typedef Geant4SensitiveAction<LcioTestTracker> LcioTestTrackerAction;
diff --git a/DDG4/plugins/Geant4EventReaderHepEvt.cpp b/DDG4/plugins/Geant4EventReaderHepEvt.cpp
index 2369ca88b..f8fc99737 100644
--- a/DDG4/plugins/Geant4EventReaderHepEvt.cpp
+++ b/DDG4/plugins/Geant4EventReaderHepEvt.cpp
@@ -42,7 +42,7 @@ namespace DD4hep {
 
     public:
       /// Initializing constructor
-      Geant4EventReaderHepEvt(const std::string& nam, int format);
+      explicit Geant4EventReaderHepEvt(const std::string& nam, int format);
       /// Default destructor
       virtual ~Geant4EventReaderHepEvt();
       /// Read an event and fill a vector of MCParticles.
@@ -81,14 +81,14 @@ namespace {
   class Geant4EventReaderHepEvtShort : public Geant4EventReaderHepEvt  {
   public:
     /// Initializing constructor
-    Geant4EventReaderHepEvtShort(const string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtShort) {}
+    explicit Geant4EventReaderHepEvtShort(const string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtShort) {}
     /// Default destructor
     virtual ~Geant4EventReaderHepEvtShort() {}
   };
   class Geant4EventReaderHepEvtLong : public Geant4EventReaderHepEvt  {
   public:
     /// Initializing constructor
-    Geant4EventReaderHepEvtLong(const string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtLong) {}
+    explicit Geant4EventReaderHepEvtLong(const string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtLong) {}
     /// Default destructor
     virtual ~Geant4EventReaderHepEvtLong() {}
   };
diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp
index 306158256..d032b2d8a 100644
--- a/DDG4/plugins/Geant4EventReaderHepMC.cpp
+++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp
@@ -46,7 +46,7 @@ namespace DD4hep {
       EventStream* m_events;
     public:
       /// Initializing constructor
-      Geant4EventReaderHepMC(const std::string& nam);
+      explicit Geant4EventReaderHepMC(const std::string& nam);
       /// Default destructor
       virtual ~Geant4EventReaderHepMC();
       /// Read an event and fill a vector of MCParticles.
diff --git a/DDG4/python/DDG4Dict.C b/DDG4/python/DDG4Dict.C
index 2378a28ed..150a19a73 100644
--- a/DDG4/python/DDG4Dict.C
+++ b/DDG4/python/DDG4Dict.C
@@ -29,16 +29,16 @@ namespace DD4hep {
 
     using std::string;
 
-#define ACTIONHANDLE(x)                                                 \
-    struct x##Handle  {                                                 \
-      Geant4##x* action;                                                \
-      x##Handle(Geant4##x* a)       : action(a)        { if ( action ) action->addRef();} \
+#define ACTIONHANDLE(x)                                                                   \
+    struct x##Handle  {                                                                   \
+      Geant4##x* action;                                                                  \
+      explicit x##Handle(Geant4##x* a) : action(a)     { if ( action ) action->addRef();} \
       x##Handle(const x##Handle& h) : action(h.action) { if ( action ) action->addRef();} \
       ~x##Handle()                  { if ( action) action->release();                   } \
       Geant4##x* release()          { Geant4##x* tmp = action; action=0; return tmp;    } \
-      operator DD4hep::Simulation::Geant4##x* () const  { return action;     } \
-      Geant4##x* operator->() const { return action;     }              \
-      Geant4##x* get() const        { return action;     }              \
+      operator DD4hep::Simulation::Geant4##x* () const  { return action;     }            \
+      Geant4##x* operator->() const                     { return action;     }            \
+      Geant4##x* get() const                            { return action;     }            \
     }
 
     ACTIONHANDLE(Filter);
-- 
GitLab