Skip to content

Integer overflow in TTree::Scan #20226

@vepadulano

Description

@vepadulano

Check duplicate issues.

  • Checked for duplicates

Description

Found while working on #20033 for the CMS DAS framework. in case one wants to print events via TTree::Scan starting from a certain entry greater than zero, if the default argument value for the nentries argument is used, i.e. TTree::kMaxEntries, then Scan doesn't even start the event loop. This is due to an integer overflow happening in the for loop condition

entry<(firstentry+nentries) && !exitloop;

$: ./ttree_scan_int_overflow.out
************************************
*    Row   *     index *     value *
************************************
************************************

Reproducer

#include <TChain.h>
#include <TFile.h>
#include <TTree.h>

#include <memory>
#include <iostream>

void make_step_zero_file(const char *name, const char *treename, int first, int last)
{
    auto file = std::make_unique<TFile>(name, "RECREATE");
    auto tree = std::make_unique<TTree>(treename, treename);

    int index{};
    int value{};
    tree->Branch("index", &index);
    tree->Branch("value", &value);

    for (index = first; index < last; ++index)
    {
        value = 2 * index;
        tree->Fill();
    }

    file->Write();
}

int main()
{
    make_step_zero_file("friends-hybrid-step0-0.root", "stepzerotree", 0, 10);
    auto file = std::make_unique<TFile>("friends-hybrid-step0-0.root");
    std::unique_ptr<TTree> tree{file->Get<TTree>("stepzerotree")};

    tree->Scan("index:value", "", "", TTree::kMaxEntries, 3);
}

ROOT version

Any

Installation method

Any

Operating system

Any

Additional context

No response

Metadata

Metadata

Labels

bugexperimentAffects an experiment / reported by its software & computimng expertsin:TTree

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions