diff --git a/src/buffer/out/TextColor.cpp b/src/buffer/out/TextColor.cpp index af90f9ff85..cf5d35e9ef 100644 --- a/src/buffer/out/TextColor.cpp +++ b/src/buffer/out/TextColor.cpp @@ -102,8 +102,8 @@ COLORREF TextColor::GetColor(std::basic_string_view colorTable, if (brighten && _index < 8) { FAIL_FAST_IF(colorTable.size() < 16); - FAIL_FAST_IF((size_t)(_index + 8) > (size_t)(colorTable.size())); - return colorTable.at(_index + 8); + FAIL_FAST_IF(gsl::narrow_cast(_index) + 8 > colorTable.size()); + return colorTable.at(gsl::narrow_cast(_index) + 8); } else { diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index c563fc1e56..3e18662949 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -977,9 +977,9 @@ const TextBuffer::TextAndColor TextBuffer::GetTextForClipboard(const bool lineSe std::vector selectionBkAttr; // preallocate to avoid reallocs - selectionText.reserve(highlight.Width() + 2); // + 2 for \r\n if we munged it - selectionFgAttr.reserve(highlight.Width() + 2); - selectionBkAttr.reserve(highlight.Width() + 2); + selectionText.reserve(gsl::narrow(highlight.Width()) + 2); // + 2 for \r\n if we munged it + selectionFgAttr.reserve(gsl::narrow(highlight.Width()) + 2); + selectionBkAttr.reserve(gsl::narrow(highlight.Width()) + 2); // copy char data into the string buffer, skipping trailing bytes while (it) @@ -1109,7 +1109,7 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPo bool hasWrittenAnyText = false; std::optional fgColor = std::nullopt; std::optional bkColor = std::nullopt; - for (UINT row = 0; row < rows.text.size(); row++) + for (size_t row = 0; row < rows.text.size(); row++) { size_t startOffset = 0; @@ -1118,7 +1118,7 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPo htmlBuilder << "
"; } - for (UINT col = 0; col < rows.text.at(row).length(); col++) + for (size_t col = 0; col < rows.text.at(row).length(); col++) { // do not include \r nor \n as they don't have attributes // and are not HTML friendly. For line break use '
' instead. diff --git a/src/buffer/out/textBufferCellIterator.cpp b/src/buffer/out/textBufferCellIterator.cpp index 50948ab6bb..b0d09eec2e 100644 --- a/src/buffer/out/textBufferCellIterator.cpp +++ b/src/buffer/out/textBufferCellIterator.cpp @@ -212,7 +212,7 @@ void TextBufferCellIterator::_SetPos(const COORD newPos) if (newPos.X != _pos.X) { - const ptrdiff_t diff = newPos.X - _pos.X; + const ptrdiff_t diff = gsl::narrow_cast(newPos.X) - gsl::narrow_cast(_pos.X); _attrIter += diff; } diff --git a/src/renderer/dx/CustomTextLayout.cpp b/src/renderer/dx/CustomTextLayout.cpp index 230d1ba56d..f45bc75ba4 100644 --- a/src/renderer/dx/CustomTextLayout.cpp +++ b/src/renderer/dx/CustomTextLayout.cpp @@ -39,7 +39,7 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, _width{ width } { // Fetch the locale name out once now from the format - _localeName.resize(format->GetLocaleNameLength() + 1); // +1 for null + _localeName.resize(gsl::narrow_cast(format->GetLocaleNameLength()) + 1); // +1 for null THROW_IF_FAILED(format->GetLocaleName(_localeName.data(), gsl::narrow(_localeName.size()))); for (const auto& cluster : clusters) @@ -306,8 +306,8 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, // Get the placement of the all the glyphs. - _glyphAdvances.resize(std::max(static_cast(glyphStart + actualGlyphCount), _glyphAdvances.size())); - _glyphOffsets.resize(std::max(static_cast(glyphStart + actualGlyphCount), _glyphOffsets.size())); + _glyphAdvances.resize(std::max(gsl::narrow_cast(glyphStart) + gsl::narrow_cast(actualGlyphCount), _glyphAdvances.size())); + _glyphOffsets.resize(std::max(gsl::narrow_cast(glyphStart) + gsl::narrow_cast(actualGlyphCount), _glyphOffsets.size())); const auto fontSizeFormat = _format->GetFontSize(); const auto fontSize = fontSizeFormat * run.fontScale; @@ -799,7 +799,7 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, RETURN_IF_FAILED(format1->GetFontCollection(&collection)); std::wstring familyName; - familyName.resize(format1->GetFontFamilyNameLength() + 1); + familyName.resize(gsl::narrow_cast(format1->GetFontFamilyNameLength()) + 1); RETURN_IF_FAILED(format1->GetFontFamilyName(familyName.data(), gsl::narrow(familyName.size()))); const auto weight = format1->GetFontWeight(); diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 3deb97ad49..903751e8f6 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -569,7 +569,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetText(_In_ int maxLength, _Out_ BSTR* pRetVal if (currentScreenInfoRow == endScreenInfoRow) { // prevent the end from going past the last non-whitespace char in the row - endIndex = std::min(static_cast(endColumn + 1), rowRight); + endIndex = std::min(gsl::narrow_cast(endColumn) + 1, rowRight); } // if startIndex >= endIndex then _start is @@ -1457,11 +1457,11 @@ std::pair UiaTextRangeBase::_moveByCharacterForward(IUiaData // check if we're at the edge of the screen info buffer if (currentScreenInfoRow == moveState.LimitingRow && - currentColumn + 1 >= right) + gsl::narrow_cast(currentColumn) + 1 >= right) { break; } - else if (currentColumn + 1 >= right) + else if (gsl::narrow_cast(currentColumn) + 1 >= right) { // we're at the edge of a row and need to go to the next one currentColumn = moveState.FirstColumnInRow; @@ -1669,11 +1669,11 @@ UiaTextRangeBase::_moveEndpointByUnitCharacterForward(IUiaData* pData, // check if we're at the edge of the screen info buffer if (currentScreenInfoRow == moveState.LimitingRow && - currentColumn + 1 >= right) + gsl::narrow_cast(currentColumn) + 1 >= right) { break; } - else if (currentColumn + 1 >= right) + else if (gsl::narrow_cast(currentColumn) + 1 >= right) { // we're at the edge of a row and need to go to the next one currentColumn = moveState.FirstColumnInRow; diff --git a/src/types/WindowUiaProviderBase.cpp b/src/types/WindowUiaProviderBase.cpp index 7ff719081b..b98abc2918 100644 --- a/src/types/WindowUiaProviderBase.cpp +++ b/src/types/WindowUiaProviderBase.cpp @@ -182,8 +182,13 @@ IFACEMETHODIMP WindowUiaProviderBase::get_BoundingRectangle(_Out_ UiaRect* pRect pRect->left = rc.left; pRect->top = rc.top; - pRect->width = rc.right - rc.left; - pRect->height = rc.bottom - rc.top; + + LONG longWidth = 0; + RETURN_IF_FAILED(LongSub(rc.right, rc.left, &longWidth)); + pRect->width = longWidth; + LONG longHeight = 0; + RETURN_IF_FAILED(LongSub(rc.bottom, rc.top, &longHeight)); + pRect->height = longHeight; return S_OK; }