Skip to content

Address Safer cpp failures in TextPainter #47356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

iidmsa
Copy link
Member

@iidmsa iidmsa commented Jun 29, 2025

df16d2d

Address Safer cpp failures in TextPainter
https://bugs.webkit.org/show_bug.cgi?id=295182
rdar://problem/154618319

Reviewed by Chris Dumez.

Fix clang static analyzer warnings in TextPainter.

* Source/WebCore/SaferCPPExpectations/ForwardDeclCheckerExpectations:
* Source/WebCore/SaferCPPExpectations/NoUncheckedPtrMemberCheckerExpectations:
* Source/WebCore/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations:
* Source/WebCore/SaferCPPExpectations/UncheckedLocalVarsCheckerExpectations:
* Source/WebCore/rendering/TextPainter.cpp:
(WebCore::TextPainter::paintTextWithShadows):
(WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
* Source/WebCore/rendering/TextPainter.h:

Canonical link: https://commits.webkit.org/296830@main

1ae8733

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@iidmsa iidmsa self-assigned this Jun 29, 2025
@iidmsa iidmsa added the Layout and Rendering For bugs with layout and rendering of Web pages. label Jun 29, 2025
@iidmsa iidmsa requested a review from cdumez June 29, 2025 19:29
@@ -97,7 +96,7 @@ ShadowApplier::~ShadowApplier()
m_context.clearDropShadow();
}

TextPainter::TextPainter(GraphicsContext& context, const FontCascade& font, const RenderStyle& renderStyle, const TextPaintStyle& textPaintStyle, const FixedVector<Style::TextShadow>& shadow, const FilterOperations* shadowColorFilter, const AtomString& emphasisMark, float emphasisMarkOffset, const RenderCombineText* combinedText)
TextPainter::TextPainter(GraphicsContext& context, const CheckedRef<const FontCascade> font, const CheckedRef<const RenderStyle> renderStyle, const TextPaintStyle& textPaintStyle, const FixedVector<Style::TextShadow>& shadow, const FilterOperations* shadowColorFilter, const AtomString& emphasisMark, float emphasisMarkOffset, const CheckedPtr<const RenderCombineText> combinedText)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in safer cpp should cause you to update parameter types. This change is incorrect, we do not pass smart pointers as parameters, unless we transfer ownership and then we use r-value references.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Fixed.

@@ -203,13 +202,13 @@ void TextPainter::paintTextAndEmphasisMarksIfNeeded(const TextRun& textRun, cons
FloatPoint boxOrigin = boxRect.location();
updateGraphicsContext(m_context, paintStyle, UseEmphasisMarkColor);
static NeverDestroyed<TextRun> objectReplacementCharacterTextRun(StringView { span(objectReplacementCharacter) });
const TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun.get() : textRun;
FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + boxRect.width() / 2, boxOrigin.y() + m_font.metricsOfPrimaryFont().intAscent()) : textOrigin;
const CheckedRef emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun.get() : textRun;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop const now.

@@ -54,7 +53,7 @@ static inline AffineTransform rotation(const FloatRect& boxRect, RotationDirecti

class TextPainter {
public:
TextPainter(GraphicsContext&, const FontCascade&, const RenderStyle&, const TextPaintStyle&, const FixedVector<Style::TextShadow>&, const FilterOperations*, const AtomString& emphasisMark, float emphasisMarkOffset, const RenderCombineText*);
TextPainter(GraphicsContext&, const CheckedRef<const FontCascade>, const CheckedRef<const RenderStyle>, const TextPaintStyle&, const FixedVector<Style::TextShadow>&, const FilterOperations*, const AtomString& emphasisMark, float emphasisMarkOffset, const CheckedPtr<const RenderCombineText>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not follow our style.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@iidmsa iidmsa force-pushed the eng/Address-Safer-cpp-failures-in-TextPainter branch from 31e5dea to fc35b59 Compare June 29, 2025 21:48
@iidmsa iidmsa requested a review from cdumez June 29, 2025 21:49
@iidmsa iidmsa force-pushed the eng/Address-Safer-cpp-failures-in-TextPainter branch from fc35b59 to 2384f1c Compare June 30, 2025 00:13
@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #42018 (2384f1c)

❌ Found 1 failing file with 2 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@iidmsa iidmsa force-pushed the eng/Address-Safer-cpp-failures-in-TextPainter branch from 2384f1c to a4e4d5d Compare June 30, 2025 01:44
@iidmsa iidmsa force-pushed the eng/Address-Safer-cpp-failures-in-TextPainter branch from a4e4d5d to de6af53 Compare June 30, 2025 01:50
@iidmsa iidmsa force-pushed the eng/Address-Safer-cpp-failures-in-TextPainter branch from de6af53 to 3c2e218 Compare June 30, 2025 01:53
@@ -244,7 +244,7 @@ String TextPainter::cachedGlyphDisplayListsForTextNodeAsText(Text& textNode, Opt

StringBuilder builder;

for (auto textBox : InlineIterator::textBoxesFor(*textNode.renderer())) {
for (auto textBox : InlineIterator::textBoxesFor(*CheckedPtr { textNode.renderer() })) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use *textNode.checkedRenderer() here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

*/

#pragma once

#include "AffineTransform.h"
#include "FloatRect.h"
#include "GlyphDisplayListCache.h"
#include "RenderCombineText.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might regress compile times. I suspect that instead you need to include CheckedPtr if that's what you get an error for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I bet it wouldn't be needed if we moved ~TextPainter() out of line. Currently, it is implicit and thus inline in the header.

@iidmsa iidmsa force-pushed the eng/Address-Safer-cpp-failures-in-TextPainter branch from 3c2e218 to 1ae8733 Compare June 30, 2025 17:59
@iidmsa iidmsa added the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label Jun 30, 2025
@webkit-ews-buildbot webkit-ews-buildbot added merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Jun 30, 2025
@webkit-ews-buildbot
Copy link
Collaborator

Safe-Merge-Queue: Build #61886.

https://bugs.webkit.org/show_bug.cgi?id=295182
rdar://problem/154618319

Reviewed by Chris Dumez.

Fix clang static analyzer warnings in TextPainter.

* Source/WebCore/SaferCPPExpectations/ForwardDeclCheckerExpectations:
* Source/WebCore/SaferCPPExpectations/NoUncheckedPtrMemberCheckerExpectations:
* Source/WebCore/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations:
* Source/WebCore/SaferCPPExpectations/UncheckedLocalVarsCheckerExpectations:
* Source/WebCore/rendering/TextPainter.cpp:
(WebCore::TextPainter::paintTextWithShadows):
(WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
* Source/WebCore/rendering/TextPainter.h:

Canonical link: https://commits.webkit.org/296830@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Address-Safer-cpp-failures-in-TextPainter branch from 1ae8733 to df16d2d Compare June 30, 2025 21:59
@webkit-commit-queue
Copy link
Collaborator

Committed 296830@main (df16d2d): https://commits.webkit.org/296830@main

Reviewed commits have been landed. Closing PR #47356 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit df16d2d into WebKit:main Jun 30, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Layout and Rendering For bugs with layout and rendering of Web pages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants