Avoiding to increase an iterator when the result can be larger than their container end.

Bug: webrtc:15438
Change-Id: I0d75436bc845590c76466bde7007e921f842a9d4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/317320
Commit-Queue: Jesus de Vicente Pena <devicentepena@webrtc.org>
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40605}
diff --git a/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc b/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc
index 8eb27c3..c8ac417 100644
--- a/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc
+++ b/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc
@@ -162,7 +162,8 @@
     float penalization_per_delay = 1.0f;
     float max_histogram_value = -1.0f;
     for (auto it = histogram_.begin();
-         it + kMatchedFilterWindowSizeSubBlocks <= histogram_.end();
+         std::distance(it, histogram_.end()) >=
+         static_cast<int>(kMatchedFilterWindowSizeSubBlocks);
          it = it + kMatchedFilterWindowSizeSubBlocks) {
       auto it_max_element =
           std::max_element(it, it + kMatchedFilterWindowSizeSubBlocks);