fix: -Wunsafe-buffer-usage warnings in GetNextZoomLevel() (#44149) (#44216)

fixup e8948397 really fix the warning this time
This commit is contained in:
Charles Kerr 2024-10-13 13:04:18 -05:00 committed by GitHub
parent e206378680
commit dce705efc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -124,22 +124,20 @@ void SetZoomLevelForWebContents(content::WebContents* web_contents,
content::HostZoomMap::SetZoomLevel(web_contents, level); content::HostZoomMap::SetZoomLevel(web_contents, level);
} }
double GetNextZoomLevel(const double level, const bool out) { double GetNextZoomLevel(double level, bool out) {
static constexpr std::array<double, 16U> kPresetFactors{ static constexpr std::array<double, 16U> kPresetFactors{
0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, 1.1, 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}; 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0};
static constexpr auto kBegin = kPresetFactors.begin(); static constexpr size_t size = std::size(kPresetFactors);
static constexpr auto kEnd = kPresetFactors.end();
const double factor = blink::PageZoomLevelToZoomFactor(level); const double factor = blink::PageZoomLevelToZoomFactor(level);
auto matches = [=](auto val) { for (size_t i = 0U; i < size; ++i) {
return blink::PageZoomValuesEqual(factor, val); if (!blink::PageZoomValuesEqual(kPresetFactors[i], factor))
}; continue;
if (auto iter = std::find_if(kBegin, kEnd, matches); iter != kEnd) { if (out && i > 0U)
if (out && iter != kBegin) return blink::PageZoomFactorToZoomLevel(kPresetFactors[i - 1U]);
return blink::PageZoomFactorToZoomLevel(*--iter); if (!out && i + 1U < size)
if (!out && ++iter != kEnd) return blink::PageZoomFactorToZoomLevel(kPresetFactors[i + 1U]);
return blink::PageZoomFactorToZoomLevel(*iter);
} }
return level; return level;
} }