Skip to content

Commit f370a91

Browse files
committed
Use gsl::narrow for narrowing casts, and document the inclusiveness of the scroll rects and the reason for using SHORT_MAX as a right boundary.
1 parent a917d0f commit f370a91

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/host/getset.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,8 @@ void DoSrvPrivateAllowCursorBlinking(SCREEN_INFORMATION& screenInfo, const bool
13561356
if (screenInfo.IsCursorInMargins(oldCursorPosition))
13571357
{
13581358
// Cursor is at the top of the viewport
1359-
// Rectangle to cut out of the existing buffer
1359+
// Rectangle to cut out of the existing buffer. This is inclusive.
1360+
// It will be clipped to the buffer boundaries so SHORT_MAX gives us the full buffer width.
13601361
SMALL_RECT srScroll;
13611362
srScroll.Left = 0;
13621363
srScroll.Right = SHORT_MAX;
@@ -2030,7 +2031,8 @@ void DoSrvPrivateModifyLinesImpl(const unsigned int count, const bool insert)
20302031
const auto cursorPosition = textBuffer.GetCursor().GetPosition();
20312032
if (screenInfo.IsCursorInMargins(cursorPosition))
20322033
{
2033-
// Rectangle to cut out of the existing buffer
2034+
// Rectangle to cut out of the existing buffer. This is inclusive.
2035+
// It will be clipped to the buffer boundaries so SHORT_MAX gives us the full buffer width.
20342036
SMALL_RECT srScroll;
20352037
srScroll.Left = 0;
20362038
srScroll.Right = SHORT_MAX;

src/host/ut_host/ScreenBufferTests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,7 +3073,7 @@ void _FillLine(COORD position, T fillContent, TextAttribute fillAttr)
30733073
template<class T>
30743074
void _FillLine(int line, T fillContent, TextAttribute fillAttr)
30753075
{
3076-
_FillLine({ 0, SHORT(line) }, fillContent, fillAttr);
3076+
_FillLine({ 0, gsl::narrow<SHORT>(line) }, fillContent, fillAttr);
30773077
}
30783078

30793079
template<class T>
@@ -3107,7 +3107,7 @@ bool _ValidateLineContains(COORD position, T expectedContent, TextAttribute expe
31073107
template<class T>
31083108
bool _ValidateLineContains(int line, T expectedContent, TextAttribute expectedAttr)
31093109
{
3110-
return _ValidateLineContains({ 0, SHORT(line) }, expectedContent, expectedAttr);
3110+
return _ValidateLineContains({ 0, gsl::narrow<SHORT>(line) }, expectedContent, expectedAttr);
31113111
}
31123112

31133113
template<class T>
@@ -3255,8 +3255,8 @@ void ScreenBufferTests::ScrollOperations()
32553255
}
32563256

32573257
Log::Comment(L"Scrolled area should have moved up/down by given magnitude.");
3258-
viewportChar += wchar_t(deletedLines); // Characters dropped when deleting
3259-
viewportLine += SHORT(insertedLines); // Lines skipped when inserting
3258+
viewportChar += gsl::narrow<wchar_t>(deletedLines); // Characters dropped when deleting
3259+
viewportLine += gsl::narrow<SHORT>(insertedLines); // Lines skipped when inserting
32603260
while (viewportLine < viewportEnd - deletedLines)
32613261
{
32623262
VERIFY_IS_TRUE(_ValidateLineContains(viewportLine++, viewportChar++, viewportAttr));

src/terminal/adapter/adaptDispatch.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ bool AdaptDispatch::_InsertDeleteHelper(_In_ unsigned int const uiCount, const b
515515
RETURN_IF_FALSE(_conApi->GetConsoleScreenBufferInfoEx(&csbiex));
516516

517517
const auto cursor = csbiex.dwCursorPosition;
518-
// Rectangle to cut out of the existing buffer
518+
// Rectangle to cut out of the existing buffer. This is inclusive.
519+
// It will be clipped to the buffer boundaries so SHORT_MAX gives us the full buffer width.
519520
SMALL_RECT srScroll;
520521
srScroll.Left = cursor.X;
521522
srScroll.Right = SHORT_MAX;
@@ -955,11 +956,13 @@ bool AdaptDispatch::_ScrollMovement(const ScrollDirection sdDirection, _In_ unsi
955956

956957
if (fSuccess)
957958
{
959+
// Rectangle to cut out of the existing buffer. This is inclusive.
960+
// It will be clipped to the buffer boundaries so SHORT_MAX gives us the full buffer width.
958961
SMALL_RECT srScreen;
959962
srScreen.Left = 0;
960963
srScreen.Right = SHORT_MAX;
961964
srScreen.Top = csbiex.srWindow.Top;
962-
srScreen.Bottom = csbiex.srWindow.Bottom - 1;
965+
srScreen.Bottom = csbiex.srWindow.Bottom - 1; // srWindow is exclusive, hence the - 1
963966

964967
// Paste coordinate for cut text above
965968
COORD coordDestination;

0 commit comments

Comments
 (0)