From a35c12cb176e6b6855e4fd73739267c022e0a267 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2024 09:12:48 -0500 Subject: [PATCH] fix: -Wunsafe-buffer-usage warnings in GetNextZoomLevel() (#44149) fixup e8948397 really fix the warning this time --- shell/browser/ui/inspectable_web_contents.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index 4c7d1717d95813..fa1b054f46f0c4 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -118,20 +118,20 @@ void SetZoomLevelForWebContents(content::WebContents* web_contents, content::HostZoomMap::SetZoomLevel(web_contents, level); } -double GetNextZoomLevel(const double level, const bool out) { +double GetNextZoomLevel(double level, bool out) { static constexpr std::array kPresetFactors{ 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0}; - static constexpr auto kBegin = kPresetFactors.begin(); - static constexpr auto kEnd = kPresetFactors.end(); + static constexpr size_t size = std::size(kPresetFactors); const double factor = blink::ZoomLevelToZoomFactor(level); - auto matches = [=](auto val) { return blink::ZoomValuesEqual(factor, val); }; - if (auto iter = std::find_if(kBegin, kEnd, matches); iter != kEnd) { - if (out && iter != kBegin) - return blink::ZoomFactorToZoomLevel(*--iter); - if (!out && ++iter != kEnd) - return blink::ZoomFactorToZoomLevel(*iter); + for (size_t i = 0U; i < size; ++i) { + if (!blink::ZoomValuesEqual(kPresetFactors[i], factor)) + continue; + if (out && i > 0U) + return blink::ZoomFactorToZoomLevel(kPresetFactors[i - 1U]); + if (!out && i + 1U < size) + return blink::ZoomFactorToZoomLevel(kPresetFactors[i + 1U]); } return level; }