From 9e0bf3bb5954cc8848e33d6806a67e75199e7ceb Mon Sep 17 00:00:00 2001 From: Stephan Hartmann Date: Tue, 16 Feb 2021 19:51:38 +0000 Subject: [PATCH] fix crash if smooth_thread_history_ is empty https://crrev.com/11ce5ea added smooth_thread_history_, but does not handle an empty std::map correctly. Decrementing iterator returned by lower_bound() only works, if the map is non-empty. Bug: 1169818 Change-Id: If75c3d4c7412e77b3ae6c3e68fa3e3821dc75764 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2692534 Reviewed-by: Behdad Bakhshinategh Reviewed-by: Sadrul Chowdhury Commit-Queue: Behdad Bakhshinategh Cr-Commit-Position: refs/heads/master@{#854397} --- diff --git a/cc/metrics/compositor_frame_reporting_controller.cc b/cc/metrics/compositor_frame_reporting_controller.cc index 6713366..dec573d1 100644 --- a/cc/metrics/compositor_frame_reporting_controller.cc +++ b/cc/metrics/compositor_frame_reporting_controller.cc @@ -440,10 +440,12 @@ } // keep the history for the last 3 seconds. - auto expired_smooth_thread = smooth_thread_history_.lower_bound( - Now() - base::TimeDelta::FromSeconds(3))--; - smooth_thread_history_.erase(smooth_thread_history_.begin(), - expired_smooth_thread); + if (!smooth_thread_history_.empty()) { + auto expired_smooth_thread = smooth_thread_history_.lower_bound( + Now() - base::TimeDelta::FromSeconds(3))--; + smooth_thread_history_.erase(smooth_thread_history_.begin(), + expired_smooth_thread); + } // Only trackes the history if there is a change in smooth_thread_ if (current_smooth_thread != GetSmoothThread()) {