Skip to content
Snippets Groups Projects
Commit 937b6768 authored by scott snyder's avatar scott snyder Committed by scott snyder
Browse files

Check result of dynamic_cast<> for null before dereferencing.

Fixes compilation warnings seen with gcc11.
parent cc4e52b9
No related branches found
No related tags found
1 merge request!1168Check result of dynamic_cast<> for null before dereferencing.
......@@ -1411,13 +1411,22 @@ StatusCode THistSvc::io_reinit() {
// migrate the objects to the new file.
// thanks to the object model of ROOT, it is super easy.
if ( cl->InheritsFrom( "TTree" ) ) {
dynamic_cast<TTree*>( hid.obj )->SetDirectory( newdir );
dynamic_cast<TTree*>( hid.obj )->Reset();
TTree* tree = dynamic_cast<TTree*>( hid.obj );
if (tree) {
tree->SetDirectory( newdir );
tree->Reset();
}
} else if ( cl->InheritsFrom( "TH1" ) ) {
dynamic_cast<TH1*>( hid.obj )->SetDirectory( newdir );
dynamic_cast<TH1*>( hid.obj )->Reset();
TH1* th1 = dynamic_cast<TH1*>( hid.obj );
if (th1) {
th1->SetDirectory( newdir );
th1->Reset();
}
} else if ( cl->InheritsFrom( "TEfficiency" ) ) {
dynamic_cast<TEfficiency*>( hid.obj )->SetDirectory( newdir );
TEfficiency* teff = dynamic_cast<TEfficiency*>( hid.obj );
if (teff) {
teff->SetDirectory( newdir );
}
} else if ( cl->InheritsFrom( "TGraph" ) ) {
olddir->Remove( hid.obj );
newdir->Append( hid.obj );
......
......@@ -120,12 +120,12 @@ StatusCode THistSvc::regHist_i( std::unique_ptr<T> hist_unique, const std::strin
hid.shared = shared;
TDirectory* dir = changeDir( hid );
if ( dynamic_cast<TTree*>( hist ) ) {
dynamic_cast<TTree*>( hist )->SetDirectory( dir );
} else if ( dynamic_cast<TH1*>( hist ) ) {
dynamic_cast<TH1*>( hist )->SetDirectory( dir );
} else if ( dynamic_cast<TEfficiency*>( hist ) ) {
dynamic_cast<TEfficiency*>( hist )->SetDirectory( dir );
if ( TTree* tree = dynamic_cast<TTree*>( hist ) ) {
tree->SetDirectory( dir );
} else if ( TH1* th1 = dynamic_cast<TH1*>( hist ) ) {
th1->SetDirectory( dir );
} else if ( TEfficiency* teff = dynamic_cast<TEfficiency*>( hist ) ) {
teff->SetDirectory( dir );
} else if ( dynamic_cast<TGraph*>( hist ) ) {
dir->Append( hist );
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment