Skip to content
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

Fix some static analysis warnings #1958

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ASDisplayNodeExtras.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ASInterfaceState ASInterfaceStateForDisplayNode(ASDisplayNode *displayNode, UIWi
// if not already, about to be set to invisible as it is not possible for an element to be visible
// while outside of a window.
ASInterfaceState interfaceState = displayNode.pendingInterfaceState;
return (window == nil ? (interfaceState &= (~ASInterfaceStateVisible)) : interfaceState);
return (window == nil ? (interfaceState & (~ASInterfaceStateVisible)) : interfaceState);
Copy link
Contributor

Choose a reason for hiding this comment

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

while Xcode may flag this, I think the comment above indicates its intentional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe it is intentional. The stuff about directly clearing the interface bit would be satisfied by interfaceState & (~ASInterfaceStateVisible). The &= is also leaving interfaceState different after the expression is run, but it doesn't matter because interfaceState is never used again. This code is only working because &= also returns the value of the newly mutated variable. You couldn't write this code in Swift, because I believe &= doesn't return anything by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

regardless, since I have no idea, but that seems more in-depth thinking is required than the other one. I think splitting this PR up is best.

For this change, I think I'd want unit tests that ensure the existing behavior persists. I've no idea how much work that would be w/o an expert weighing in on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened a new PR for this. If you still want a unit test after reading my description, I'm happy to add one :)

} else {
// For not range managed nodes we might be on our own to try to guess if we're visible.
return (window == nil ? ASInterfaceStateNone : (ASInterfaceStateVisible | ASInterfaceStateDisplay));
Expand Down
2 changes: 1 addition & 1 deletion Source/TextExperiment/Component/ASTextLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2385,7 +2385,7 @@ static void ASTextDrawRun(ASTextLine *line, CTRunRef run, CGContextRef context,
if (mode) { // CJK glyph, need rotated
CGFloat ofs = (ascent - descent) * 0.5;
CGFloat w = glyphAdvances[g].width * 0.5;
CGFloat x = x = line.position.x + verticalOffset + glyphPositions[g].y + (ofs - w);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems good. small diffs are terrific. Would you mind splitting this up? Thanks.

CGFloat x = line.position.x + verticalOffset + glyphPositions[g].y + (ofs - w);
CGFloat y = -line.position.y + size.height - glyphPositions[g].x - (ofs + w);
if (mode == ASTextRunGlyphDrawModeVerticalRotateMove) {
x += w;
Expand Down