From c33eeab2ca42bdb8c6d6477b11dff17d26d7ef6c Mon Sep 17 00:00:00 2001 From: Jianjun Zhu Date: Tue, 26 May 2020 17:43:17 +0800 Subject: [PATCH] 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 Reviewed-by: Sebastian Jansson Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#31354} --- rtc_base/thread.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc index 5e48e4b857..f8e299afd9 100644 --- a/rtc_base/thread.cc +++ b/rtc_base/thread.cc @@ -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)