Hello All,
Sometimes, when making variable width histograms, I by accident create a histogram with an axis like this -
TH2D* h2 = new TH2D("h2","h2", 1, 0, 1, 5, 0, 5)
double x[4] = {1.2, 1.8, 2.1, 4};
h2->GetXaxis()->Set( 4, x );
Then I go fill, and draw. The axis ranges look fine, and even the bin divisions look fine so at first glance it is hard to see the problem. However, memory has not been allocated for 3x5 bins, but only for 1x5 (excluding under and overflow) and as a result, there is some strange behaviour. The bins are not filled correctly, and this leads to some memory problem when trying to delete the histogram.
For example I have gotten, free(): invalid next size and double free or corruption memory problems.
Looking at the source of the function there does not seem to be a check. Only reason nBins is needed is to loop over the array correctly and set fNbins (which is dangerous!). Would it be useful to have this in there to avoid the problem later? It is just sometimes hard to see until you have stumbled over it a couple times.
-Yakov