Skip to content

Commit 002983f

Browse files
committed
[tree] Force calling GetNdata before EvalInstance in BuildIndex
As recommended in https://github.com/root-project/root/pull/18766/files Fixes #11883
1 parent fd48a6d commit 002983f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tree/treeplayer/src/TTreeIndex.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
/** \class TTreeIndex
1313
A Tree Index with majorname and minorname.
14+
15+
If minorname is "0", just majorname will be used.
1416
*/
1517

1618
#include "TTreeIndex.h"
@@ -181,6 +183,14 @@ TTreeIndex::TTreeIndex(const TTree *T, const char *majorname, const char *minorn
181183
fMajorFormula->UpdateFormulaLeaves();
182184
fMinorFormula->UpdateFormulaLeaves();
183185
}
186+
if ((fMajorFormula->GetNdata() + fMinorFormula->GetNdata()) <= 0) {
187+
// Calling GetNdata is essential before calling EvalInstance, otherwise a wrong
188+
// result is silently returned by EvalInstance below if formula is value from a variable-sized array
189+
// We raise an error to prevent the if clause being optimized-out if we do not use the return
190+
Error("TTreeIndex",
191+
"In tree entry %lld, Ndata in formula is zero for both '%s' and '%s'", i,
192+
fMajorName.Data(), fMinorName.Data());
193+
}
184194
auto GetAndRangeCheck = [this](bool isMajor, Long64_t entry) {
185195
LongDouble_t ret = (isMajor ? fMajorFormula : fMinorFormula)->EvalInstance<LongDouble_t>();
186196
// Check whether the value (vs significant bits) of ldRet can represent

0 commit comments

Comments
 (0)