0

Fix PlatformFontMac under -fsanitize=vptr

The constructor would call the CTFontWithSpec method before the object
was constructed at all, which trips -fsanitize=vptr. However the method
never actually accessed `this`. It should simply have been static the
whole time.

This fixes errors like the following:
https://ci.chromium.org/ui/labs/p/chromium/inv/build-8737084650289924497/test/ninja%3A%2F%2Fui%2Fgfx%3Agfx_unittests%2FFontTest.Ascent/variant/5ed0314f10d9734f?resultIndex=0

Probably also a hair more efficient too, as we won't need to waste
a register on an unused parameter in the calling convention.

Bug: 40248746
Change-Id: I4441dbf8090fa2e2d013a24afabae2702a2915a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5856619
Reviewed-by: Robert Liao <robliao@chromium.org>
Auto-Submit: David Benjamin <davidben@chromium.org>
Commit-Queue: David Benjamin <davidben@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1354854}
This commit is contained in:
David Benjamin
2024-09-12 22:22:20 +00:00
committed by Chromium LUCI CQ
parent 50d9937081
commit aabd38ffda
2 changed files with 4 additions and 3 deletions

@ -97,8 +97,8 @@ class GFX_EXPORT PlatformFontMac : public PlatformFont {
void CalculateMetricsAndInitRenderParams();
// Returns a CTFontRef created with the passed-in specifications.
base::apple::ScopedCFTypeRef<CTFontRef> CTFontWithSpec(
FontSpec font_spec) const;
static base::apple::ScopedCFTypeRef<CTFontRef> CTFontWithSpec(
FontSpec font_spec);
// The CTFontRef instance for this object. If this object was constructed from
// a CTFontRef instance, this holds that instance. Otherwise this instance is

@ -491,8 +491,9 @@ void PlatformFontMac::CalculateMetricsAndInitRenderParams() {
render_params_ = gfx::GetFontRenderParams(query, nullptr);
}
// static
base::apple::ScopedCFTypeRef<CTFontRef> PlatformFontMac::CTFontWithSpec(
FontSpec font_spec) const {
FontSpec font_spec) {
// One might think that a font descriptor with the NSFontWeightTrait/
// kCTFontWeightTrait trait could be used to look up a font with a specific
// weight. That doesn't work, though. You can ask a font for its weight, but