-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Replace UIA CompareInBounds with til::point comparators #14551
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as noted
Ok. This is "great". Here's what happened:
if (!bufferSize.IsInBounds(_start, true) || !bufferSize.IsInBounds(_end, true))
{
THROW_HR(E_FAIL);
}
THROW_HR_IF(E_FAIL, !bufferSize.IsInBounds(_start) || !bufferSize.IsInBounds(_end));
|
We could still do the other |
@@ -293,7 +276,7 @@ void UiaTextRangeBase::_expandToEnclosingUnit(TextUnit unit) | |||
// If we're past document end, | |||
// set us to ONE BEFORE the document end. | |||
// This allows us to expand properly. | |||
if (bufferSize.CompareInBounds(_start, documentEnd, true) >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: The final boolean parameter in CompareInBounds
is ignored in Release mode builds anyways, so from a perspective of "could this potentially crash?" it doesn't matter if the old code used to have true
, false
, or no boolean argument at all.
_start = std::min(_start, documentEnd); | ||
_end = std::min(_end, documentEnd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure that the _start/_end range is properly degenerate here we'd have to use something like this right?
_end = std::min(_end, documentEnd);
_start = std::min(_start, _end);
Otherwise _start > _end
is possible. I mean technically this function doesn't even touch these two members at this point, but this made me wonder if we should change IsDegenerate()
from _start == _end
to _start >= _end
just in case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm conflicted. On one hand, IsDegenerate()
would be fixed, but on the other hand, we clearly messed up if _start > _end
at any point. These two lines help alleviate that by clamping down to documentEnd
. Maybe adding an assert(_start <= _end)
in IsDegenerate()
would be good to detect if we ever run into that? idk, if that would be useful though. idk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what to do either, but I personally would make the change to IsDegenerate()
regardless. Simply because bugs will exist in our code regardless of how hard we try, so we might as well build our code around that assumption. But I could also be completely wrong about it here, since I'm not completely familiar with how IsDegenerate()
is used and whether such a change would make any tangible safety improvements at all in the first place.
assert()
s are IMO a great idea in either case, and the more we use them the better, because it's like test driven programming, but at runtime and it's more productive (arguably). 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way cleaner! Thanks!
Hello @carlos-zamora! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
This PR replaces the uses of
Viewport::CompareInBounds()
in the UIA code withtil::point
comparators. Additionally, it simplifies the logic further by usingstd::max
andstd::min
.In doing so, we are no longer hitting the
assert
inCompareInBounds()
.Closes #14542