diff --git a/src/buffer/out/TextAttribute.cpp b/src/buffer/out/TextAttribute.cpp index 4fc9e0aa23..36d28b1605 100644 --- a/src/buffer/out/TextAttribute.cpp +++ b/src/buffer/out/TextAttribute.cpp @@ -102,12 +102,12 @@ void TextAttribute::SetLegacyAttributes(const WORD attrs, { if (setForeground) { - const BYTE fgIndex = (BYTE)(attrs & FG_ATTRS); + const BYTE fgIndex = gsl::narrow_cast(attrs & FG_ATTRS); _foreground = TextColor(fgIndex); } if (setBackground) { - const BYTE bgIndex = (BYTE)(attrs & BG_ATTRS) >> 4; + const BYTE bgIndex = gsl::narrow_cast(attrs & BG_ATTRS) >> 4; _background = TextColor(bgIndex); } if (setMeta) diff --git a/src/buffer/out/cursor.cpp b/src/buffer/out/cursor.cpp index 6cb6959789..946d0ecfe7 100644 --- a/src/buffer/out/cursor.cpp +++ b/src/buffer/out/cursor.cpp @@ -207,7 +207,7 @@ void Cursor::SetPosition(const COORD cPosition) void Cursor::SetXPosition(const int NewX) { _RedrawCursor(); - _cPosition.X = (SHORT)NewX; + _cPosition.X = gsl::narrow(NewX); _RedrawCursor(); ResetDelayEOLWrap(); } @@ -215,7 +215,7 @@ void Cursor::SetXPosition(const int NewX) void Cursor::SetYPosition(const int NewY) { _RedrawCursor(); - _cPosition.Y = (SHORT)NewY; + _cPosition.Y = gsl::narrow(NewY); _RedrawCursor(); ResetDelayEOLWrap(); } @@ -223,7 +223,7 @@ void Cursor::SetYPosition(const int NewY) void Cursor::IncrementXPosition(const int DeltaX) { _RedrawCursor(); - _cPosition.X += (SHORT)DeltaX; + _cPosition.X += gsl::narrow(DeltaX); _RedrawCursor(); ResetDelayEOLWrap(); } @@ -231,7 +231,7 @@ void Cursor::IncrementXPosition(const int DeltaX) void Cursor::IncrementYPosition(const int DeltaY) { _RedrawCursor(); - _cPosition.Y += (SHORT)DeltaY; + _cPosition.Y += gsl::narrow(DeltaY); _RedrawCursor(); ResetDelayEOLWrap(); } @@ -239,7 +239,7 @@ void Cursor::IncrementYPosition(const int DeltaY) void Cursor::DecrementXPosition(const int DeltaX) { _RedrawCursor(); - _cPosition.X -= (SHORT)DeltaX; + _cPosition.X -= gsl::narrow(DeltaX); _RedrawCursor(); ResetDelayEOLWrap(); } @@ -247,7 +247,7 @@ void Cursor::DecrementXPosition(const int DeltaX) void Cursor::DecrementYPosition(const int DeltaY) { _RedrawCursor(); - _cPosition.Y -= (SHORT)DeltaY; + _cPosition.Y -= gsl::narrow(DeltaY); _RedrawCursor(); ResetDelayEOLWrap(); } @@ -342,7 +342,7 @@ const COLORREF Cursor::GetColor() const void Cursor::SetColor(const unsigned int color) { - _color = (COLORREF)color; + _color = static_cast(color); } void Cursor::SetType(const CursorType type) diff --git a/src/renderer/dx/CustomTextRenderer.cpp b/src/renderer/dx/CustomTextRenderer.cpp index e459e97d1d..1c7edfff29 100644 --- a/src/renderer/dx/CustomTextRenderer.cpp +++ b/src/renderer/dx/CustomTextRenderer.cpp @@ -63,7 +63,7 @@ using namespace Microsoft::Console::Render; DrawingContext* drawingContext = static_cast(clientDrawingContext); // Matrix structures are defined identically - drawingContext->renderTarget->GetTransform((D2D1_MATRIX_3X2_F*)transform); + drawingContext->renderTarget->GetTransform(reinterpret_cast(transform)); return S_OK; } #pragma endregion diff --git a/src/renderer/dx/DxRenderer.cpp b/src/renderer/dx/DxRenderer.cpp index 76a31b7be6..49c4794662 100644 --- a/src/renderer/dx/DxRenderer.cpp +++ b/src/renderer/dx/DxRenderer.cpp @@ -377,8 +377,8 @@ void DxEngine::_ReleaseDeviceResources() noexcept return _dwriteFactory->CreateTextLayout(string, static_cast(stringLength), _dwriteTextFormat.Get(), - (float)_displaySizePixels.cx, - _glyphCell.cy != 0 ? _glyphCell.cy : (float)_displaySizePixels.cy, + gsl::narrow(_displaySizePixels.cx), + _glyphCell.cy != 0 ? _glyphCell.cy : gsl::narrow( _displaySizePixels.cy), ppTextLayout); } @@ -1089,7 +1089,7 @@ enum class CursorPaintType { // Enforce min/max cursor height ULONG ulHeight = std::clamp(options.ulCursorHeightPercent, s_ulMinCursorHeightPercent, s_ulMaxCursorHeightPercent); - ulHeight = (ULONG)((_glyphCell.cy * ulHeight) / 100); + ulHeight = gsl::narrow((_glyphCell.cy * ulHeight) / 100); rect.top = rect.bottom - ulHeight; break; } @@ -1300,10 +1300,10 @@ float DxEngine::GetScaling() const noexcept [[nodiscard]] SMALL_RECT DxEngine::GetDirtyRectInChars() noexcept { SMALL_RECT r; - r.Top = (SHORT)(floor(_invalidRect.top / _glyphCell.cy)); - r.Left = (SHORT)(floor(_invalidRect.left / _glyphCell.cx)); - r.Bottom = (SHORT)(floor(_invalidRect.bottom / _glyphCell.cy)); - r.Right = (SHORT)(floor(_invalidRect.right / _glyphCell.cx)); + r.Top = gsl::narrow(floor(_invalidRect.top / _glyphCell.cy)); + r.Left = gsl::narrow(floor(_invalidRect.left / _glyphCell.cx)); + r.Bottom = gsl::narrow(floor(_invalidRect.bottom / _glyphCell.cy)); + r.Right = gsl::narrow(floor(_invalidRect.right / _glyphCell.cx)); // Exclusive to inclusive r.Bottom--; @@ -1321,7 +1321,7 @@ float DxEngine::GetScaling() const noexcept // - Nearest integer short x and y values for each cell. [[nodiscard]] COORD DxEngine::_GetFontSize() const noexcept { - return { (SHORT)(_glyphCell.cx), (SHORT)(_glyphCell.cy) }; + return { gsl::narrow(_glyphCell.cx), gsl::narrow(_glyphCell.cy) }; } // Routine Description: @@ -1371,7 +1371,7 @@ float DxEngine::GetScaling() const noexcept // - S_OK [[nodiscard]] HRESULT DxEngine::_DoUpdateTitle(_In_ const std::wstring& /*newTitle*/) noexcept { - return PostMessageW(_hwndTarget, CM_UPDATE_TITLE, 0, (LPARAM) nullptr) ? S_OK : E_FAIL; + return PostMessageW(_hwndTarget, CM_UPDATE_TITLE, 0, 0) ? S_OK : E_FAIL; } // Routine Description: