Skip to content

Commit a5b9e50

Browse files
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>
1 parent ce08e37 commit a5b9e50

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/pybind11/detail/class.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,11 @@ inline void clear_patients(PyObject *self) {
388388
auto *instance = reinterpret_cast<detail::instance *>(self);
389389
auto &internals = get_internals();
390390
auto pos = internals.patients.find(self);
391-
assert(pos != internals.patients.end());
391+
392+
if (pos == internals.patients.end()) {
393+
pybind11_fail("FATAL: Internal consistency check failed: Invalid clear_patients() call.");
394+
}
395+
392396
// Clearing the patients can cause more Python code to run, which
393397
// can invalidate the iterator. Extract the vector of patients
394398
// from the unordered_map first.

0 commit comments

Comments
 (0)