Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Framework/Kernel/src/FilteredTimeSeriesProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,15 @@ template <typename TYPE> TimeInterval FilteredTimeSeriesProperty<TYPE>::nthInter
deltaT = TimeSeriesProperty<TYPE>::nthInterval(n);
} else {
this->applyFilter();
deltaT = this->m_filterIntervals[std::size_t(n)];
// Throw exception if out of bounds
if (n >= static_cast<int>(this->m_filterIntervals.size())) {
const std::string error("nthInterval(): FilteredTimeSeriesProperty '" + this->name() + "' interval " +
std::to_string(n) + " does not exist");
g_log.debug(error);
throw std::runtime_error(error);
} else {
deltaT = this->m_filterIntervals[std::size_t(n)];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do this with at(), supposed to be a safe way to access vectors, although it still throws an exception?
https://en.cppreference.com/w/cpp/container/array/at
Just letting you know about it, the code is fine as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think we want the custom error message in this case, in keeping with other error handling within the function.

}

return deltaT;
Expand Down Expand Up @@ -405,7 +413,7 @@ Kernel::TimeROI *FilteredTimeSeriesProperty<TYPE>::intersectFilterWithOther(cons
auto roi = new TimeROI(*m_filter.get());
if (other && (!other->useAll()))
roi->update_or_replace_intersection(*other);
return std::move(roi);
return roi;
}

template <typename TYPE> const Kernel::TimeROI &FilteredTimeSeriesProperty<TYPE>::getTimeROI() const {
Expand Down
6 changes: 6 additions & 0 deletions Framework/Kernel/test/LogFilterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class LogFilterTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(p->nthInterval(4).end_str(),
"2007-Nov-30 16:17:50"); // nth interval changed to use
// previous interval now.

// test out of bounds check given filter applied
auto testFilter = createTestFilter(1);
LogFilter flt(p);
flt.addFilter(*testFilter);
TS_ASSERT_THROWS(flt.data()->nthInterval(5), const std::runtime_error &);
}

void testFilterWithTrueAtStart() {
Expand Down
1 change: 1 addition & 0 deletions docs/source/release/v6.13.0/Framework/Bugfixes/39238.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Handled out of bounds error possible when using get ``nthTime`` and ``nthInterval`` methods of a ``FilteredTimeSeriesProperty``. This occurred when the argument ``n`` was specified to be greater than the maximum index of the time filter intervals present.