Skip to content

Commit

Permalink
Try to fix some coverity problems
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch committed Jun 20, 2024
1 parent d119e3f commit 5642826
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
5 changes: 5 additions & 0 deletions DDG4/plugins/Geant4EventReaderHepMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace dd4hep {

// C/C++ include files
#include <cerrno>
#include <climits>
#include <algorithm>

using namespace dd4hep::sim;
Expand Down Expand Up @@ -505,6 +506,10 @@ int HepMC::read_vertex(EventStream &info, std::istream& is, std::istringstream &
delete v;
return 0;
}
if ( weights_size < 0 || weights_size > USHRT_MAX ) {
delete v;
return 0;
}
#if defined(DD4HEP_DEBUG_HEP_MC_VERTEX)
if ( id == DD4HEP_DEBUG_HEP_MC_VERTEX ) {
printout(ALWAYS,"HepMC","++ Created Vertex ID=%d",id);
Expand Down
2 changes: 1 addition & 1 deletion GaudiPluginService/src/listcomponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main( int argc, char* argv[] ) {
++i;
}
if ( libs.empty() ) {
usage( argv0 );
usage( std::move(argv0) );
return EXIT_FAILURE;
}
}
Expand Down
18 changes: 9 additions & 9 deletions UtilityApps/src/graphicalScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
//
//==========================================================================

#include "TError.h"

#include "TFile.h"
#include "TH2F.h"
#include <TError.h>
#include <TFile.h>
#include <TH2F.h>

// Framework include files
#include "DD4hep/Detector.h"
#include "DD4hep/Printout.h"
#include "DDRec/MaterialManager.h"
#include <DD4hep/Detector.h>
#include <DD4hep/Printout.h>
#include <DDRec/MaterialManager.h>

#include <iostream>
#include <climits>
#include <cerrno>
#include <string>
#include <map>
Expand Down Expand Up @@ -123,9 +123,9 @@ int main_wrapper(int argc, char** argv) {
if ( y0>y1 ) { double temp=y0; y0=y1; y1=temp; }
if ( z0>z1 ) { double temp=z0; z0=z1; z1=temp; }

if ( ! ( nbins>0 && nslice>0 ) ) {
if ( ! (nbins>0 && nbins<USHRT_MAX && nslice>0 && nslice<USHRT_MAX) ) {
cout << "funny # bins/slices " << endl;
return 1;
::exit(EINVAL);
}

bool scanField(false);
Expand Down
26 changes: 16 additions & 10 deletions UtilityApps/src/materialBudget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
//
//==========================================================================

#include "TError.h"
#include <TError.h>

// Framework include files
#include "DD4hep/Detector.h"
#include "DD4hep/DetType.h"
#include "DD4hep/Printout.h"
#include "DDRec/MaterialManager.h"
#include <DD4hep/Detector.h>
#include <DD4hep/DetType.h>
#include <DD4hep/Printout.h>
#include <DDRec/MaterialManager.h>

// #include "TGeoVolume.h"
// #include "TGeoManager.h"
// #include "TGeoNode.h"
#include "TFile.h"
#include "TH1F.h"
// #include <TGeoVolume.h>
// #include <TGeoManager.h>
// #include <TGeoNode.h>
#include <TFile.h>
#include <TH1F.h>

#include <cerrno>
#include <fstream>
#include <climits>

#include "main.h"

Expand Down Expand Up @@ -219,6 +220,11 @@ int main_wrapper(int argc, char** argv) {
std::cout << "theta:f/" ;
for(auto& det : subdets){ std::cout << det.name << "_x0:f/" << det.name << "_lam:f/" ; }
std::cout << std::endl ;

if ( nbins <= 0 || nbins > USHRT_MAX ) {
std::cout << "Unreasonable number of bins: " << nbins << std::endl;
::exit(EINVAL);
}

for(int i=0 ; i< nbins ;++i){

Expand Down
18 changes: 8 additions & 10 deletions UtilityApps/src/test_cellid_position_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@

#include <sstream>

using namespace std ;
using namespace dd4hep ;
using namespace std;
using namespace dd4hep;
using namespace dd4hep::detail;
using namespace dd4hep::rec ;

using namespace dd4hep::rec;
using namespace lcio;


Expand Down Expand Up @@ -181,16 +180,15 @@ int main_wrapper(int argc, char** argv ){
std::cout << "\n ----------------------- summary ---------------------- " << std::endl ;


for( auto res : tMap ){

std::string name = res.first ;
unsigned total = res.second.position.passed+res.second.position.failed ;
for( const auto& res : tMap ) {
const std::string& name = res.first;
unsigned total = res.second.position.passed+res.second.position.failed ;
unsigned pos_failed = res.second.position.failed ;
unsigned id_failed = res.second.cellid.failed ;
unsigned id_failed = res.second.cellid.failed ;


printf(" %-30s \t failed position: %5d failed cellID: %5d of total: %5d \n",
name.c_str(), pos_failed , id_failed, total ) ;
name.c_str(), pos_failed , id_failed, total ) ;

}
std::cout << "\n -------------------------------------------------------- " << std::endl ;
Expand Down

0 comments on commit 5642826

Please sign in to comment.