4 ms·
> Can you spot the bug? I assume one of your handlers invokes RegisterMessageHandler invalidates the iterators to handlers_[some_queue_name]. As such, the fol
by MaulingMonkey 10y ago
> Can you spot the bug?
I assume one of your handlers invokes RegisterMessageHandler invalidates the iterators to handlers_[some_queue_name]. As such, the following line exhibits UB:
for (auto &h : handlers) {
In practice, the exact behavior is likely to depend on if the vector resized it's underlying storage or not.
EDIT: I'll also note that using a debug build of the SC++L with iterator debugging enabled should give you a useful diagnostic here - given a modern SC++L implementation. Whether or not your application runs well enough, to actually get to the point of being able to reproduce the bug with iterator debugging enabled, is another matter entirely of course.
EDIT x2: I'll further note I'm cheating here by having encountered and fixed this same bug on a different codebase.