root icon indicating copy to clipboard operation
root copied to clipboard

[hist] Fix segfault when calling `GetNumberOfBins()` on an empty TH2Poly

Open hqucms opened this issue 1 year ago • 8 comments

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 #

hqucms avatar Sep 03 '24 19:09 hqucms

I'd say it's better:

If(!fBins) { Warning() return; } else if(nbins...)

ferdymercury avatar Sep 03 '24 19:09 ferdymercury

I changed it to

if (nbins != (fBins ? fBins->GetSize() : 0))

which should cover both cases. Let me know what you think.

hqucms avatar Sep 03 '24 20:09 hqucms

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)?

dpiparo avatar Sep 04 '24 04:09 dpiparo

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

guitargeek avatar Sep 04 '24 07:09 guitargeek

That would be useful. Do we also maybe want to cure crashes which might be occurring for example in presence of default values?

dpiparo avatar Sep 06 '24 11:09 dpiparo

I added a unittest in https://github.com/root-project/root/pull/16370/commits/daa74274b51e4174bfdf23ecd26248e5f400a8e7.

hqucms avatar Oct 01 '24 19:10 hqucms

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.

hqucms avatar Oct 01 '24 19:10 hqucms

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.

github-actions[bot] avatar Oct 16 '24 17:10 github-actions[bot]

Thanks a lot @hageboeck ! Is it possible to backport this to 6.32 and 6.30?

hqucms avatar Oct 23 '24 09:10 hqucms

Thanks a lot @hageboeck ! Is it possible to backport this to 6.32 and 6.30?

Sure! See the PRs referenced above.

hageboeck avatar Oct 23 '24 11:10 hageboeck

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 !

hqucms avatar Oct 23 '24 12:10 hqucms