Skip to content

Commit 1c3022f

Browse files
MialLewisGlass
authored andcommitted
Handle out of bounds error in nthIterval of FilteredTimeSeriesProperty (#39238)
* throw error if out of bounds in nthIterval * add release note * update nthInterval test * satisfy cppcheck - remove std::move to allow for nrvo * cast size_t to int to resolve compiler warnings * respond to review comments
1 parent 721d9e5 commit 1c3022f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Framework/Kernel/src/FilteredTimeSeriesProperty.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ template <typename TYPE> TimeInterval FilteredTimeSeriesProperty<TYPE>::nthInter
154154
deltaT = TimeSeriesProperty<TYPE>::nthInterval(n);
155155
} else {
156156
this->applyFilter();
157+
// Throw exception if out of bounds
158+
if (n < 0 || n >= static_cast<int>(this->m_filterIntervals.size())) {
159+
const std::string error("nthInterval(): FilteredTimeSeriesProperty '" + this->name() + "' interval " +
160+
std::to_string(n) + " does not exist");
161+
g_log.debug(error);
162+
throw std::runtime_error(error);
163+
}
157164
deltaT = this->m_filterIntervals[std::size_t(n)];
158165
}
159166

@@ -405,7 +412,7 @@ Kernel::TimeROI *FilteredTimeSeriesProperty<TYPE>::intersectFilterWithOther(cons
405412
auto roi = new TimeROI(*m_filter.get());
406413
if (other && (!other->useAll()))
407414
roi->update_or_replace_intersection(*other);
408-
return std::move(roi);
415+
return roi;
409416
}
410417

411418
template <typename TYPE> const Kernel::TimeROI &FilteredTimeSeriesProperty<TYPE>::getTimeROI() const {

Framework/Kernel/test/LogFilterTest.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ class LogFilterTest : public CxxTest::TestSuite {
5757
TS_ASSERT_EQUALS(p->nthInterval(4).end_str(),
5858
"2007-Nov-30 16:17:50"); // nth interval changed to use
5959
// previous interval now.
60+
61+
// test out of bounds check given filter applied
62+
auto testFilter = createTestFilter(1);
63+
LogFilter flt(p);
64+
flt.addFilter(*testFilter);
65+
TS_ASSERT_THROWS_EQUALS(flt.data()->nthInterval(5), const std::runtime_error &e, std::string(e.what()),
66+
"nthInterval(): FilteredTimeSeriesProperty 'test' interval 5 does not exist");
67+
TS_ASSERT_THROWS_EQUALS(flt.data()->nthInterval(-1), const std::runtime_error &e, std::string(e.what()),
68+
"nthInterval(): FilteredTimeSeriesProperty 'test' interval -1 does not exist");
6069
}
6170

6271
void testFilterWithTrueAtStart() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Handled out of bounds error possible when using ``nthTime`` and ``nthInterval`` methods of a ``FilteredTimeSeriesProperty``. This occurred when the argument ``n`` was specified as an invalid index of the time filter intervals vector.

0 commit comments

Comments
 (0)