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] Fix segfault when calling GetNumberOfBins() on an empty TH2Poly #16370

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion hist/hist/src/TH2Poly.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ Double_t TH2Poly::GetBinError(Int_t bin) const
/// it should be the size of the bin list
Int_t TH2Poly::GetNumberOfBins() const {
Int_t nbins = fNcells-kNOverflow;
if (nbins != fBins->GetSize())
if (nbins != (fBins ? fBins->GetSize() : 0))
Fatal("GetNumberOfBins","Object has an invalid number of bins");
return nbins;
}
Expand Down
1 change: 1 addition & 0 deletions hist/hist/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ROOT_ADD_GTEST(testTProfile2Poly test_tprofile2poly.cxx LIBRARIES Hist Matrix MathCore RIO)
ROOT_ADD_GTEST(testTH2PolyBinError test_TH2Poly_BinError.cxx LIBRARIES Hist Matrix MathCore RIO)
ROOT_ADD_GTEST(testTH2PolyAdd test_TH2Poly_Add.cxx LIBRARIES Hist Matrix MathCore RIO)
ROOT_ADD_GTEST(testTH2PolyGetNumberOfBins test_TH2Poly_GetNumberOfBins.cxx LIBRARIES Hist Matrix MathCore RIO)
ROOT_ADD_GTEST(testTHn THn.cxx LIBRARIES Hist Matrix MathCore RIO)
ROOT_ADD_GTEST(testTH1 test_TH1.cxx LIBRARIES Hist)
ROOT_ADD_GTEST(testTHStack test_THStack.cxx LIBRARIES Hist)
Expand Down
14 changes: 14 additions & 0 deletions hist/hist/test/test_TH2Poly_GetNumberOfBins.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// test TH2Poly GetNumberOfBins

#include "gtest/gtest.h"

#include "TH2Poly.h"

TEST(TH2Poly, GetNumberOfBins)
{
TH2Poly h2p;
EXPECT_EQ(0, h2p.GetNumberOfBins());

h2p.AddBin(1, 1, 1, 1);
EXPECT_EQ(1, h2p.GetNumberOfBins());
}
Loading