Skip to content

Commit 6d40ba3

Browse files
authored
add assert to notify incurred UB in case a node was linked during send_down
1 parent 09980c3 commit 6d40ba3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lager/detail/nodes.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,18 @@ class reader_node : public observable_reader_node<T>
218218
needs_send_down_ = false;
219219
needs_notify_ = true;
220220

221-
// We cannot use ranged-for here because children might
222-
// change as a result of recompute(). This can invalidate
223-
// the iterators on children, causing undefined behaviors.
224-
// See also https://github.com/arximboldi/lager/pull/212
225221
const auto& children = this->children();
226-
for (size_t i = 0, size = children.size(); i < size; ++i) {
227-
if (auto child = children[i].lock()) {
222+
const size_t n_children = children.size();
223+
for (auto& wchild : children) {
224+
if (auto child = wchild.lock()) {
228225
child->send_down();
229226
}
230227
}
228+
assert(n_children == children.size() &&
229+
"Children must not change during send_down, \
230+
because iterators would be invalidated leading to UB. \
231+
Maybe you created a new cursor inside a cursor.map(...) \
232+
call?");
231233
}
232234
}
233235

0 commit comments

Comments
 (0)