Fix an incorrect use of iterator.

This change uses index instead of iterator to access elements in
`all_targets` to avoid using invalidated iterator after insertion.

MSVC 2019 reports "cannot increment value-initialized deque iterator".
And C++ standard says "an insertion at either end of the deque
invalidates all the iterators to the deque".

Bug: webrtc:11255
Change-Id: I2167bfe875bb0059e81eba334bbd6921e287d6d9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176101
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31354}
This commit is contained in:
Jianjun Zhu 2020-05-26 17:43:17 +08:00 committed by Commit Bot
parent cdbebb086e
commit c33eeab2ca

View file

@ -168,8 +168,8 @@ void ThreadManager::RegisterSendAndCheckForCycles(Thread* source,
// We check the pre-existing who-sends-to-who graph for any path from target
// to source. This loop is guaranteed to terminate because per the send graph
// invariant, there are no cycles in the graph.
for (auto it = all_targets.begin(); it != all_targets.end(); ++it) {
const auto& targets = send_graph_[*it];
for (size_t i = 0; i < all_targets.size(); i++) {
const auto& targets = send_graph_[all_targets[i]];
all_targets.insert(all_targets.end(), targets.begin(), targets.end());
}
RTC_CHECK_EQ(absl::c_count(all_targets, source), 0)