Commit a5b9e50f by Cliff Burdick Committed by GitHub

fix: added check on iterator end position (#5129)

* Added check on iterator end position

* Always use assert without conditional check

* Addressing code review comments

* style: pre-commit fixes

* Remove assert and throw

* Changed style slightly

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
parent ce08e370
...@@ -388,7 +388,11 @@ inline void clear_patients(PyObject *self) { ...@@ -388,7 +388,11 @@ inline void clear_patients(PyObject *self) {
auto *instance = reinterpret_cast<detail::instance *>(self); auto *instance = reinterpret_cast<detail::instance *>(self);
auto &internals = get_internals(); auto &internals = get_internals();
auto pos = internals.patients.find(self); auto pos = internals.patients.find(self);
assert(pos != internals.patients.end());
if (pos == internals.patients.end()) {
pybind11_fail("FATAL: Internal consistency check failed: Invalid clear_patients() call.");
}
// Clearing the patients can cause more Python code to run, which // Clearing the patients can cause more Python code to run, which
// can invalidate the iterator. Extract the vector of patients // can invalidate the iterator. Extract the vector of patients
// from the unordered_map first. // from the unordered_map first.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment