Skip to content

Commit

Permalink
Fix various problems indicated by coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch committed May 16, 2024
1 parent da374ac commit 4cbc4d0
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 161 deletions.
2 changes: 2 additions & 0 deletions DDAlign/include/DDAlign/GlobalDetectorAlignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace dd4hep {
public:
/// Initializing constructor
GlobalDetectorAlignment(DetElement e);
/// Initializing constructor
GlobalDetectorAlignment(DetElement&& e);
/// Access debugging flag
static bool debug();
/// Set debugging flag
Expand Down
6 changes: 6 additions & 0 deletions DDAlign/src/GlobalDetectorAlignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ GlobalDetectorAlignment::GlobalDetectorAlignment(DetElement e)
{
}

/// Initializing constructor
GlobalDetectorAlignment::GlobalDetectorAlignment(DetElement&& e)
: DetElement(e)
{
}

/// Access debugging flag
bool GlobalDetectorAlignment::debug() {
return s_GlobalDetectorAlignment_debug;
Expand Down
15 changes: 9 additions & 6 deletions DDCAD/src/ASSIMPWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ namespace {
std::unique_ptr<TGeoHMatrix> mother(new TGeoHMatrix(to_global));
mother->Multiply(p->GetMatrix());

if ( use )
cont.push_back(std::make_pair(p, mother.get()));
if ( recursive )
_collect(cont, recursive, *mother, p);
if ( use )
mother.release();
if ( use ) {
TGeoHMatrix* m = mother.release();
cont.push_back(std::make_pair(p, m));
if ( recursive )
_collect(cont, recursive, *m, p);
}
else if ( recursive ) {
_collect(cont, recursive, *mother, p);
}
}
}
bool equals(Vertex const &lhs, Vertex const &rhs) {
Expand Down
52 changes: 26 additions & 26 deletions DDCore/src/Grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,24 @@ dd4hep::BasicGrammar::~BasicGrammar() {
#include <iostream>
/// Prenote loadable grammar
void dd4hep::BasicGrammar::pre_note(const std::type_info& info,
const BasicGrammar& (*fcn)(),
specialization_t specs) {
const BasicGrammar& (*fcn)(),
specialization_t specs) {
key_type hash = dd4hep::detail::hash64(typeName(info));
#ifdef DD4HEP_DEBUG_PROPERTIES
std::cout << "pre_note(1) " << typeName(info)
<< " " << (void*)specs.str
<< " " << (void*)specs.fromString
<< std::endl;
<< " " << (void*)specs.str
<< " " << (void*)specs.fromString
<< std::endl;
#endif
if ( !prenote_registry().emplace(hash, std::make_pair(fcn,specs)).second ) {
auto j = prenote_registry().find(hash);
const auto& entry = (*j).second;
#ifdef DD4HEP_DEBUG_PROPERTIES
const auto& gramm = entry.first();
std::cout << "pre_note(2) " << typeName(info)
<< " " << (void*)gramm.specialization.fromString
<< " " << (void*)entry.second.fromString
<< std::endl;
<< " " << (void*)gramm.specialization.fromString
<< " " << (void*)entry.second.fromString
<< std::endl;
#endif
if ( !(entry.first == fcn && entry.second == specs) ) {
// Error: Already existing grammar.
Expand All @@ -157,10 +157,10 @@ const dd4hep::BasicGrammar& dd4hep::BasicGrammar::get(key_type hash) {
const auto& entry = (*i).second;
const auto& gramm = *entry;
std::cout << "get(1) " << hash
<< " grammar: " << (void*)&gramm
<< " " << (void*)gramm.specialization.fromString
<< " " << (void*)entry->specialization.fromString
<< std::endl;
<< " grammar: " << (void*)&gramm
<< " " << (void*)gramm.specialization.fromString
<< " " << (void*)entry->specialization.fromString
<< std::endl;
#endif
return *(i->second);
}
Expand All @@ -170,9 +170,9 @@ const dd4hep::BasicGrammar& dd4hep::BasicGrammar::get(key_type hash) {
const auto& entry = (*j).second;
const auto& gramm = entry.first();
std::cout << "get(2) " << hash
<< " " << (void*)gramm.specialization.fromString
<< " " << (void*)entry.second.fromString
<< std::endl;
<< " " << (void*)gramm.specialization.fromString
<< " " << (void*)entry.second.fromString
<< std::endl;
#endif
return (j->second.first)();
}
Expand Down Expand Up @@ -270,7 +270,7 @@ bool dd4hep::BasicGrammar::fromString(void* ptr, const std::string& value) const
if ( specialization.fromString )
return specialization.fromString(*this, ptr, value);
except("Grammar", "Cannot deserialize object with incomplete grammar: %s [%s] %p fromString: %s",
type_name().c_str(), this->name.c_str(), (void*)this, (void*)specialization.fromString);
type_name().c_str(), this->name.c_str(), (void*)this, (void*)specialization.fromString);
return false;
}

Expand Down Expand Up @@ -310,7 +310,7 @@ std::string dd4hep::detail::grammar_pre_parse_map(const std::string& in) {
if ( str_open ) { str_open = false; }
break;
case ':':
if ( str_open ) { res += '\''; str_open = false; }
if ( str_open ) { res += '\''; }
res += *c;
res += ' ';
res += '\'';
Expand Down Expand Up @@ -340,8 +340,8 @@ std::string dd4hep::detail::grammar_pre_parse_map(const std::string& in) {
case ']':
case '}':
if ( str_open ) {
res += '\'';
str_open = false;
res += '\'';
str_open = false;
}
res += *c ;
break;
Expand All @@ -350,9 +350,9 @@ std::string dd4hep::detail::grammar_pre_parse_map(const std::string& in) {
break;
default:
if ( start ) {
if ( !obj_open ) res += '\'';
start = false;
str_open = true;
if ( !obj_open ) res += '\'';
start = false;
str_open = true;
}
ignore_blanks = false;
res += *c;
Expand All @@ -379,7 +379,7 @@ std::string dd4hep::detail::grammar_pre_parse_cont(const std::string& in) {
if ( str_open ) { str_open = false; }
break;
case ':':
if ( str_open ) { res += '\''; str_open = false; }
if ( str_open ) { res += '\''; }
res += *c;
res += ' ';
res += '\'';
Expand Down Expand Up @@ -410,9 +410,9 @@ std::string dd4hep::detail::grammar_pre_parse_cont(const std::string& in) {
break;
default:
if ( start ) {
res += '\'';
start = false;
str_open = true;
res += '\'';
start = false;
str_open = true;
}
ignore_blanks = false;
res += *c;
Expand Down
60 changes: 34 additions & 26 deletions DDCore/src/plugins/LCDDConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,9 @@ xml_h LCDDConverter::handleField(const std::string& /* name */, OverlayedField f
if (!fld.isValid()) {
PluginDebug dbg;
PluginService::Create<NamedObject*>(type + "_Convert2Detector", &m_detDesc, &field, &fld);
throw std::runtime_error("Failed to locate plugin to convert electromagnetic field:"
+ std::string(f->GetName()) + " of type " + type + ". "
+ dbg.missingFactory(type));
except("LCDDConverter", "Failed to locate plugin to convert electromagnetic field:"
+ std::string(f->GetName()) + " of type " + type + ". "
+ dbg.missingFactory(type));
}
geo.doc_fields.append(field);
}
Expand Down Expand Up @@ -1055,23 +1055,28 @@ void LCDDConverter::handleProperties(Detector::Properties& prp) const {
const GeoHandler* ptr = this;
std::string nam = (*i).second;
const Detector::PropertyValues& vals = prp[nam];
std::string type = vals.find("type")->second;
std::string tag = type + "_Geant4_action";
long result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals);
if (0 == result) {
PluginDebug dbg;
result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals);
auto iter = vals.find("type");
if ( iter != vals.end() ) {
std::string type = iter->second;
std::string tag = type + "_Geant4_action";
long result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals);
if (0 == result) {
throw std::runtime_error("Failed to locate plugin to interprete files of type"
" \"" + tag + "\" - no factory:" + type + ". " +
dbg.missingFactory(tag));
PluginDebug dbg;
result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals);
if (0 == result) {
except("LCDDConverter", "Failed to locate plugin to interprete files of type"
" \"" + tag + "\" - no factory:" + type + ". " +
dbg.missingFactory(tag));
}
}
result = *(long*) result;
if (result != 1) {
except("LCDDConverter", "Failed to invoke the plugin " + tag + " of type " + type);
}
printout(INFO,"","+++ Executed Successfully Detector setup module %s.", type.c_str());
continue;
}
result = *(long*) result;
if (result != 1) {
throw std::runtime_error("Failed to invoke the plugin " + tag + " of type " + type);
}
printout(INFO,"","+++ Executed Successfully Detector setup module %s.",type.c_str());
printout(INFO,"","+++ FAILED to execute Detector setup module %s.", nam.c_str());
}
}

Expand Down Expand Up @@ -1317,15 +1322,18 @@ static long create_visASCII(Detector& description, int /* argc */, char** argv)
for (xml_coll_t c(geo.doc_structure, _U(volume)); c; ++c) {
xml_comp_t vol = c;
xml_comp_t ref = c.child(_U(visref));
xml_comp_t vis = (*vis_map.find(ref.refStr())).second;
xml_comp_t col = vis.child(_U(color));
os << "vol:" << vol.nameStr() << sep << "vis:" << vis.nameStr() << sep
<< "visible:" << vis.visible() << sep << "r:"
<< col.R() << sep << "g:" << col.G() << sep << "b:" << col.B() << sep
<< "alpha:" << col.alpha() << sep << "line_style:"
<< vis.attr < std::string > (_U(line_style)) << sep
<< "drawing_style:" << vis.attr < std::string> (_U(drawing_style)) << sep
<< "show_daughters:" << vis.show_daughters() << sep << std::endl;
auto iter = vis_map.find(ref.refStr());
if ( iter != vis_map.end() ) {
xml_comp_t vis = iter->second;
xml_comp_t col = vis.child(_U(color));
os << "vol:" << vol.nameStr() << sep << "vis:" << vis.nameStr() << sep
<< "visible:" << vis.visible() << sep << "r:"
<< col.R() << sep << "g:" << col.G() << sep << "b:" << col.B() << sep
<< "alpha:" << col.alpha() << sep << "line_style:"
<< vis.attr < std::string > (_U(line_style)) << sep
<< "drawing_style:" << vis.attr < std::string> (_U(drawing_style)) << sep
<< "show_daughters:" << vis.show_daughters() << sep << std::endl;
}
}
os.close();
return 1;
Expand Down
1 change: 1 addition & 0 deletions DDDigi/plugins/DigiDepositDropKilled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace dd4hep {
if ( iter->second.flag&EnergyDeposit::KILLED ) {
m->remove(iter);
iter = (last_cell != ~0x0ULL) ? m->data.find(last_cell) : m->begin();
if ( iter == m->end() ) iter = m->begin();
continue;
}
last_cell = iter->first;
Expand Down
Loading

0 comments on commit 4cbc4d0

Please sign in to comment.