Skip to content

Commit aa9ced9

Browse files
committed
[hist] Prevent out-of-bounds in RRegularAxis
1 parent 6d0ce85 commit aa9ced9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

hist/histv7/inc/ROOT/RRegularAxis.hxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public:
101101
}
102102

103103
std::size_t bin = (x - fLow) * fInvBinWidth;
104+
if (bin >= fNNormalBins) {
105+
bin = fNNormalBins - 1;
106+
}
104107
return {bin, true};
105108
}
106109

hist/histv7/test/hist_regular.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ TEST(RRegularAxis, ComputeLinearizedIndex)
113113
}
114114
}
115115

116+
TEST(RRegularAxis, ComputeLinearizedIndexMin)
117+
{
118+
static constexpr std::size_t Bins = 20;
119+
const RRegularAxis axis(Bins, {-1, std::numeric_limits<double>::min()});
120+
121+
auto linIndex = axis.ComputeLinearizedIndex(0);
122+
EXPECT_EQ(linIndex.fIndex, Bins - 1);
123+
EXPECT_TRUE(linIndex.fValid);
124+
}
125+
116126
TEST(RRegularAxis, GetLinearizedIndex)
117127
{
118128
static constexpr std::size_t Bins = 20;

0 commit comments

Comments
 (0)