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

[1.14] Remove most uses of CompareInBounds #13313

Closed

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented Jun 16, 2022

Summary of the Pull Request

⚠️Targets 1.14⚠️

Replaces most uses of Viewport::CompareInBounds() with til::point's < and > operators. CompareInBounds has been the cause of a bunch of UIA crashes over the years. Replacing them entirely ensures that the FAILFAST_IF isn't ever touched.

This was a bit tricky to do because I wanted to ensure the same functionality was maintained. Since we still have a ton of COORDs floating around, I just cast to til::point when we're about to do a comparison. We could do smarter changes, but I'm concerned that could cause a bug we could miss.

References

#13183
#13244 - same PR but for main

Comment on lines +1539 to +1540
const til::point endInclusive{ bufferSize.RightInclusive(), bufferSize.BottomInclusive() };
const auto val = limitOptional.value_or(endInclusive);
Copy link
Member

Choose a reason for hiding this comment

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

The old code uses bufferSize.EndExclusive() and not the "inclusive" variant?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only reason we used EndExclusive before was for the CompareInBounds call below. So instead, we're using EndInclusive (a valid point in the buffer), so that CompareInBounds works fine. Then we add 1 if we were past EndInclusive (i.e. EndExclusive).

src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalCore/TerminalSelection.cpp Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jun 16, 2022
@@ -1142,7 +1142,7 @@ const COORD TextBuffer::GetWordStart(const COORD target, const std::wstring_view
// that it actually points to a space in the buffer
copy = { bufferSize.RightInclusive(), bufferSize.BottomInclusive() };
}
else if (bufferSize.CompareInBounds(target, limit.to_win32_coord(), true) >= 0)
else if (til::point{ target.X, target.Y } >= limit)
Copy link
Member

Choose a reason for hiding this comment

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

i still don't totally get this. can't you use til::point{ target }?

@@ -1730,20 +1726,20 @@ void UiaTextRangeBase::_moveEndpointByUnitDocument(_In_ const int moveCount,
{
case MovementDirection::Forward:
{
auto documentEnd{ bufferSize.EndExclusive() };
til::point documentEnd{ bufferSize.EndExclusive().X, bufferSize.EndExclusive().Y };
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
til::point documentEnd{ bufferSize.EndExclusive().X, bufferSize.EndExclusive().Y };
til::point documentEnd{ bufferSize.EndExclusive() };

?

Comment on lines +1121 to +1127
if (til::point{ _start } > documentEnd)
{
_start = documentEnd;
_start = documentEnd.to_win32_coord();
}
if (bufferSize.CompareInBounds(_end, documentEnd, true) > 0)
if (til::point{ _end } > documentEnd)
{
_end = documentEnd;
_end = documentEnd.to_win32_coord();
Copy link
Member

Choose a reason for hiding this comment

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

i have to admit, I somewhat thought that "porting the coordinate system change for UIA only" would mean that _start and _end were natively til::point, and didn't have to be converted every time we encountered them

Copy link
Member Author

Choose a reason for hiding this comment

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

I wish. But the problem is Viewport and TextBuffer still need them to be COORDs. And occasionally, they'll be copied by reference. It's doable, but I figured this would be the easiest path forward with the least risk. Especially since this is a servicing update after all haha

@DHowett
Copy link
Member

DHowett commented Jun 17, 2022

On third thought, perhaps it would be more correct to leave 1.14 be with the fix you had 😄

@carlos-zamora
Copy link
Member Author

I'm gonna go ahead and close this PR. Dustin and I chatted about it and it provides little benefit because...

  1. the fail fasts have been replaced with asserts
  2. any remaining issues will throw an exception when we try to read the buffer improperly, which is then caught by our UIA provider code and returned as a failed HRESULT to the screen reader.

#13244 still makes sense for main, but we can just outright avoid the risk of having this in 1.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants