Skip to content

Commit

Permalink
Check if Solid is valid before getting its name to avoid segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
cvuosalo committed Dec 13, 2019
1 parent 7f30694 commit 3f87ce2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions DetectorDescription/DDCMS/src/DDNamespace.cc
Expand Up @@ -153,11 +153,14 @@ dd4hep::Volume DDNamespace::addVolumeNS(dd4hep::Volume vol) const {
dd4hep::Material m = vol.material();
vol->SetName(n.c_str());
m_context->volumes[n] = vol;
const char* solidName = "Invalid solid";
if (s.isValid()) // Protect against seg fault
solidName = s.name(); // If Solid is not valid, s.name() will seg fault.
dd4hep::printout(m_context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG,
"DD4CMS",
"+++ Add volume:%-38s Solid:%-26s[%-16s] Material:%s",
"+++ Add volumeNS:%-38s Solid:%-26s[%-16s] Material:%s",
vol.name(),
s.name(),
solidName,
s.type(),
m.name());
return vol;
Expand All @@ -170,12 +173,15 @@ dd4hep::Volume DDNamespace::addVolume(dd4hep::Volume vol) const {
dd4hep::Material m = vol.material();
//vol->SetName(n.c_str());
m_context->volumes[n] = vol;
const char* solidName = "Invalid solid";
if (s.isValid()) // Protect against seg fault
solidName = s.name(); // If Solid is not valid, s.name() will seg fault.
dd4hep::printout(m_context->debug_volumes ? dd4hep::ALWAYS : dd4hep::DEBUG,
"DD4CMS",
"+++ Add volume:%-38s as [%s] Solid:%-26s[%-16s] Material:%s",
vol.name(),
n.c_str(),
s.name(),
solidName,
s.type(),
m.name());
return vol;
Expand Down

0 comments on commit 3f87ce2

Please sign in to comment.