Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hist] prevent nullptr access with copy from default constructor #16773

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions hist/hist/src/TH2Poly.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,20 @@ void TH2Poly::Copy(TObject &newobj) const
newth2p.fCompletelyInside[i] = fCompletelyInside[i];
}
// need to use Clone to copy the contained bin list
newth2p.fBins = dynamic_cast<TList *>(fBins->Clone());
if (!newth2p.fBins)
Error("Copy","Error cloning the TH2Poly bin list");
if (!fBins) {
newth2p.fBins = nullptr;
ferdymercury marked this conversation as resolved.
Show resolved Hide resolved
}
else {
// add bins in the fCells partition. We need to add the TH2PolyBin objects
// of the new copied histograms. For this we call AddBinToPartition
// we could probably optimize this by implementing a copy of the partition
for (auto bin : *(newth2p.fBins)) {
newth2p.AddBinToPartition(dynamic_cast<TH2PolyBin*>(bin));
newth2p.fBins = dynamic_cast<TList *>(fBins->Clone());
if (!newth2p.fBins)
Error("Copy","Error cloning the TH2Poly bin list");
else {
// add bins in the fCells partition. We need to add the TH2PolyBin objects
// of the new copied histograms. For this we call AddBinToPartition
// we could probably optimize this by implementing a copy of the partition
for (auto bin : *(newth2p.fBins)) {
newth2p.AddBinToPartition(dynamic_cast<TH2PolyBin*>(bin));
}
}
}
// copy overflow contents
Expand Down Expand Up @@ -897,7 +902,7 @@ void TH2Poly::SetBinError(Int_t bin, Double_t error)
const char *TH2Poly::GetBinName(Int_t bin) const
{
if (bin > GetNumberOfBins()) return "";
if (bin < 0) return "";
if (bin <= 0) return "";
return ((TH2PolyBin*) fBins->At(bin-1))->GetPolygon()->GetName();
}

Expand All @@ -907,7 +912,7 @@ const char *TH2Poly::GetBinName(Int_t bin) const
const char *TH2Poly::GetBinTitle(Int_t bin) const
{
if (bin > GetNumberOfBins()) return "";
if (bin < 0) return "";
if (bin <= 0) return "";
return ((TH2PolyBin*) fBins->At(bin-1))->GetPolygon()->GetTitle();
}

Expand Down
Loading