[hist] Fix segfault when calling `GetNumberOfBins()` on an empty TH2Poly
This Pull request:
This pull request fixes a segfault when calling GetNumberOfBins() on an empty TH2Poly by first checking whether fBins is null.
To reproduce the original segfault:
TH2Poly h; h.GetNumberOfBins();
Changes or fixes:
Checklist:
- [ ] tested changes locally
- [ ] updated the docs (if necessary)
This PR fixes #
I'd say it's better:
If(!fBins) { Warning() return; } else if(nbins...)
I changed it to
if (nbins != (fBins ? fBins->GetSize() : 0))
which should cover both cases. Let me know what you think.
Hi @hqucms . Thanks for this fix! Do you think you could also add a unit test (https://github.com/root-project/root/tree/master/hist/hist/test)?
How much sense does it actually make to use these constructors without arguments of the hist classes? I thought they were reserved for IO. Maybe this is a documentation issue? @lmoneta
That would be useful. Do we also maybe want to cure crashes which might be occurring for example in presence of default values?
I added a unittest in https://github.com/root-project/root/pull/16370/commits/daa74274b51e4174bfdf23ecd26248e5f400a8e7.
How much sense does it actually make to use these constructors without arguments of the hist classes? I thought they were reserved for IO. Maybe this is a documentation issue? @lmoneta
It's not just the default constructor. For TH2Poly, one needs to call AddBin() explicitly to create the bins, otherwise it will crash regardless of which constructor is called.
Test Results
18 files 18 suites 4d 2h 8m 18s :stopwatch: 2 716 tests 2 714 :white_check_mark: 0 :zzz: 2 :x: 46 047 runs 46 045 :white_check_mark: 0 :zzz: 2 :x:
For more details on these failures, see this check.
Results for commit 76760e7b.
:recycle: This comment has been updated with latest results.
Thanks a lot @hageboeck ! Is it possible to backport this to 6.32 and 6.30?
Thanks a lot @hageboeck ! Is it possible to backport this to 6.32 and 6.30?
Sure! See the PRs referenced above.
Thanks a lot @hageboeck ! Is it possible to backport this to 6.32 and 6.30?
Sure! See the PRs referenced above.
Thanks a lot @hageboeck !