Skip to content

Commit 79ad5f3

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 8b04b9f commit 79ad5f3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tree/treeplayer/src/TTreeIndex.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ TTreeIndex::TTreeIndex(const TTree *T, const char *majorname, const char *minorn
180180
fMajorFormula->UpdateFormulaLeaves();
181181
fMinorFormula->UpdateFormulaLeaves();
182182
}
183+
if ((fMajorFormula->GetNdata() + fMinorFormula->GetNdata()) <= 0) {
184+
// Calling GetNdata is essential before calling EvalInstance, otherwise a wrong
185+
// result is silently returned by EvalInstance below if formula is value from a variable-sized array
186+
// We raise an error to prevent the if clause being optimized-out if we do not use the return
187+
Error("TTreeIndex",
188+
"In tree entry %lld, Ndata in formula is zero for both '%s' and '%s'", i,
189+
fMajorName.Data(), fMinorName.Data());
190+
}
183191
auto GetAndRangeCheck = [this](bool isMajor, Long64_t entry) {
184192
LongDouble_t ret = (isMajor ? fMajorFormula : fMinorFormula)->EvalInstance<LongDouble_t>();
185193
// Check whether the value (vs significant bits) of ldRet can represent

0 commit comments

Comments
 (0)