From ea776a1c6d91211924cce0375f6a39c0fa53110c Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Wed, 17 Jul 2019 11:54:05 +0200 Subject: [PATCH] Attempt to fix coverity errors. --- DDCore/src/Plugins.cpp | 6 +++- DDCore/src/gdml/ImportPlainRoot.cpp | 14 ++++----- DDG4/plugins/Geant4EventReaderHepMC.cpp | 4 +-- DDG4/plugins/Geant4GDMLWriteAction.cpp | 15 +++++----- DDG4/plugins/Geant4TrackerWeightedSD.cpp | 37 ++++++++++++------------ DDTest/src/test_cellDimensionsRPhi2.cc | 16 +++++++--- examples/DDDigi/src/DigiTestAction.cpp | 10 ++----- 7 files changed, 56 insertions(+), 46 deletions(-) diff --git a/DDCore/src/Plugins.cpp b/DDCore/src/Plugins.cpp index 8297424ff..98cbd54a2 100644 --- a/DDCore/src/Plugins.cpp +++ b/DDCore/src/Plugins.cpp @@ -119,7 +119,11 @@ namespace { plugin_name = "libDD4hepGaudiPluginMgr"; } #if !defined(DD4HEP_PARSERS_NO_ROOT) - gSystem->Load(plugin_name); + if ( 0 != gSystem->Load(plugin_name) ) { + string err = "Failed to load plugin manager library: "; + err += plugin_name; + throw runtime_error(err); + } #else handle = ::dlopen(plugin_name, RTLD_LAZY | RTLD_GLOBAL); #endif diff --git a/DDCore/src/gdml/ImportPlainRoot.cpp b/DDCore/src/gdml/ImportPlainRoot.cpp index fe2480a20..68817d70c 100644 --- a/DDCore/src/gdml/ImportPlainRoot.cpp +++ b/DDCore/src/gdml/ImportPlainRoot.cpp @@ -126,20 +126,20 @@ static long plain_root_dump(Detector& description, int argc, char** argv) { bool do_import = false; string input, in_obj = "Geometry", air, vacuum; for(int i = 0; i < argc && argv[i]; ++i) { - if ( 0 == ::strncmp("-input",argv[i],5) ) + if ( 0 == ::strncmp("-input",argv[i],5) && (i+1)<argc ) input = argv[++i]; - else if ( 0 == ::strncmp("-object",argv[i],5) ) + else if ( 0 == ::strncmp("-object",argv[i],5) && (i+1)<argc ) in_obj = argv[++i]; - else if ( 0 == ::strncmp("-air",argv[i],5) ) + else if ( 0 == ::strncmp("-air",argv[i],5) && (i+1)<argc ) air = argv[++i]; - else if ( 0 == ::strncmp("-vacuum",argv[i],5) ) + else if ( 0 == ::strncmp("-vacuum",argv[i],5) && (i+1)<argc ) vacuum = argv[++i]; - else if ( 0 == ::strncmp("-level",argv[i],5) ) + else if ( 0 == ::strncmp("-level",argv[i],5) && (i+1)<argc ) level = ::atol(argv[++i]); + else if ( 0 == ::strncmp("-print",argv[i],5) && (i+1)<argc ) + prt = decodePrintLevel(argv[++i]); else if ( 0 == ::strncmp("-import",argv[i],5) ) do_import = true; - else if ( 0 == ::strncmp("-print",argv[i],5) ) - prt = decodePrintLevel(argv[++i]); else goto Error; } diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp index e1d0c7560..f3842e9a3 100644 --- a/DDG4/plugins/Geant4EventReaderHepMC.cpp +++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp @@ -309,10 +309,10 @@ void HepMC::fix_particles(EventStream& info) { for(id=v->out.begin(); id!=v->out.end();++id) { EventStream::Particles::iterator ipp = parts.find(*id); Geant4Particle* dau = ipp != parts.end() ? (*ipp).second : 0; - p->daughters.insert(*id); - if ( !p ) { + if ( !dau ) { cout << "ERROR: Invalid daughter particle: " << *id << endl; } + p->daughters.insert(*id); dau->parents.insert(p->id); } } diff --git a/DDG4/plugins/Geant4GDMLWriteAction.cpp b/DDG4/plugins/Geant4GDMLWriteAction.cpp index 5fb30f097..2c79155d4 100644 --- a/DDG4/plugins/Geant4GDMLWriteAction.cpp +++ b/DDG4/plugins/Geant4GDMLWriteAction.cpp @@ -128,18 +128,19 @@ void Geant4GDMLWriteAction::installCommandMessenger() { /// Write geometry to GDML void Geant4GDMLWriteAction::writeGDML() { + string fname = m_output; struct stat buff; - if ( m_output.empty() ) { + if ( fname.empty() ) { error("+++ No GDML file name given. Please set the output file (property Output)"); return; } - if ( 0 == ::stat(m_output.c_str(), &buff) && !m_overWrite ) { + if ( 0 == ::stat(fname.c_str(), &buff) && !m_overWrite ) { error("+++ GDML file elready exists. Please set another output file (property Output)"); return; } - if ( 0 == ::stat(m_output.c_str(), &buff) && m_overWrite ) { - warning("+++ GDML file %s already exists. Overwriting existing file.", m_output.c_str()); - ::unlink(m_output.c_str()); + if ( 0 == ::stat(fname.c_str(), &buff) && m_overWrite ) { + warning("+++ GDML file %s already exists. Overwriting existing file.", fname.c_str()); + ::unlink(fname.c_str()); } unique_ptr<G4GDMLParser> parser(new G4GDMLParser()); parser->SetRegionExport(m_exportRegions != 0); @@ -147,8 +148,8 @@ void Geant4GDMLWriteAction::writeGDML() { #if G4VERSION_NUMBER>=1030 parser->SetSDExport(m_exportSensitiveDetectors != 0); #endif - info("+++ Writing GDML file: %s", m_output.c_str()); - parser->Write(m_output, context()->world()); + info("+++ Writing GDML file: %s", fname.c_str()); + parser->Write(fname, context()->world()); } #include "DDG4/Factories.h" diff --git a/DDG4/plugins/Geant4TrackerWeightedSD.cpp b/DDG4/plugins/Geant4TrackerWeightedSD.cpp index 22b408bab..0c2a831c2 100644 --- a/DDG4/plugins/Geant4TrackerWeightedSD.cpp +++ b/DDG4/plugins/Geant4TrackerWeightedSD.cpp @@ -406,24 +406,25 @@ namespace dd4hep { ///dumpStep void dumpStep(const Geant4StepHandler& h, const G4Step* s) { - std::cout << " ----- step in detector " << h.sdName( s->GetPreStepPoint() ) - << " prePos " << h.prePos() - << " postPos " << h.postPos() - << " preStatus " << h.preStepStatus() - << " postStatus " << h.postStepStatus() - << " preVolume " << h.volName( s->GetPreStepPoint() ) - << " postVolume " << h.volName( s->GetPostStepPoint() ) - << std::endl - << " momentum : " << std::scientific - << s->GetPreStepPoint()->GetMomentum()[0] << ", " - << s->GetPreStepPoint()->GetMomentum()[1]<< ", " - << s->GetPreStepPoint()->GetMomentum()[2] - << " / " - << s->GetPostStepPoint()->GetMomentum()[0] << ", " - << s->GetPostStepPoint()->GetMomentum()[1] << ", " - << s->GetPostStepPoint()->GetMomentum()[2] - << ", PDG: " << s->GetTrack()->GetDefinition()->GetPDGEncoding() - << std::endl ; + std::stringstream str; + str << " ----- step in detector " << h.sdName( s->GetPreStepPoint() ) + << " prePos " << h.prePos() + << " postPos " << h.postPos() + << " preStatus " << h.preStepStatus() + << " postStatus " << h.postStepStatus() + << " preVolume " << h.volName( s->GetPreStepPoint() ) + << " postVolume " << h.volName( s->GetPostStepPoint() ) + << std::endl + << " momentum : " << std::scientific + << s->GetPreStepPoint()->GetMomentum()[0] << ", " + << s->GetPreStepPoint()->GetMomentum()[1]<< ", " + << s->GetPreStepPoint()->GetMomentum()[2] + << " / " + << s->GetPostStepPoint()->GetMomentum()[0] << ", " + << s->GetPostStepPoint()->GetMomentum()[1] << ", " + << s->GetPostStepPoint()->GetMomentum()[2] + << ", PDG: " << s->GetTrack()->GetDefinition()->GetPDGEncoding(); + std::cout << str.str() << std::endl; } }; diff --git a/DDTest/src/test_cellDimensionsRPhi2.cc b/DDTest/src/test_cellDimensionsRPhi2.cc index 1565c4d32..7665b9b3f 100644 --- a/DDTest/src/test_cellDimensionsRPhi2.cc +++ b/DDTest/src/test_cellDimensionsRPhi2.cc @@ -1,6 +1,7 @@ #include "DDSegmentation/Segmentation.h" #include "DDSegmentation/PolarGridRPhi2.h" #include "DDSegmentation/PolarGridRPhi.h" +#include "DD4hep/Printout.h" #include "DD4hep/DDTest.h" #include <iostream> @@ -31,10 +32,17 @@ void testRPhi2(); void testRPhi(); int main() { - - testRPhi2(); - testRPhi(); - + using namespace dd4hep; + try { + testRPhi2(); + testRPhi(); + } + catch(const std::exception& e) { + printout(ERROR,"CellDimensions","+++ Caught unhandled exception: %s",e.what()); + } + catch(...) { + printout(ERROR,"CellDimensions","+++ Caught UNKNOWN unhandled exception."); + } return 0; } diff --git a/examples/DDDigi/src/DigiTestAction.cpp b/examples/DDDigi/src/DigiTestAction.cpp index 6ba3c8e02..c821b65d4 100644 --- a/examples/DDDigi/src/DigiTestAction.cpp +++ b/examples/DDDigi/src/DigiTestAction.cpp @@ -40,13 +40,9 @@ namespace dd4hep { /// Sleep period to fake execution [milliseconds] int m_sleep = 0; protected: - /// Inhibit copy constructor - DigiTestAction() = default; - /// Inhibit copy constructor - DigiTestAction(const DigiTestAction& copy) = delete; - /// Inhibit assignment operator - DigiTestAction& operator=(const DigiTestAction& copy) = delete; - + /// Define standard assignments and constructors + DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiTestAction); + public: /// Standard constructor DigiTestAction(const DigiKernel& kernel, const std::string& nam); -- GitLab