Skip to content

Commit

Permalink
Fix potential over/underflow as noted by "TODO:" comment (#8081)
Browse files Browse the repository at this point in the history
Fixed potential errors caused by overflow or underfow in
SectionInput.cpp

## PR Checklist
* [x] CLA signed
* [x] Tests added/passed

## Detailed Description of the Pull Request / Additional comments
In selectionInput.cpp, there is both a potential overflow and potential
underflow. To address this issue, I casted the calculation up to int,
which is then checked because of integer promotion. Underflow and
underflow is therefore impossible because now if the calculation exceeds
SHORT_MAX, it will have exceeded bufferSize.BottomInclusive() or
bufferSize.Top() anyway, and be set to them.

## Validation Steps Performed
Passed Unit Testing
Manual Validation
  • Loading branch information
N authored Nov 11, 2020
1 parent 5a942bc commit 3a57378
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/host/selectionInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ bool Selection::HandleKeyboardLineSelectionEvent(const INPUT_KEY_INFO* const pIn
// shift + pgup/pgdn extends selection up or down one full screen
case VK_NEXT:
{
coordSelPoint.Y += sWindowHeight; // TODO: potential overflow
coordSelPoint.Y = base::CheckAdd(coordSelPoint.Y, sWindowHeight).ValueOrDefault(bufferSize.BottomInclusive());
if (coordSelPoint.Y > bufferSize.BottomInclusive())
{
coordSelPoint.Y = bufferSize.BottomInclusive();
Expand All @@ -399,7 +399,7 @@ bool Selection::HandleKeyboardLineSelectionEvent(const INPUT_KEY_INFO* const pIn
}
case VK_PRIOR:
{
coordSelPoint.Y -= sWindowHeight; // TODO: potential underflow
coordSelPoint.Y = base::CheckSub(coordSelPoint.Y, sWindowHeight).ValueOrDefault(bufferSize.Top());
if (coordSelPoint.Y < bufferSize.Top())
{
coordSelPoint.Y = bufferSize.Top();
Expand Down

0 comments on commit 3a57378

Please sign in to comment.