Skip to content

Commit 6e89242

Browse files
javierdlgaphistra
andauthored
Multiple fixes to address DD CodeQL requirements (#18451)
After taking in 1.22, our CodeQL process caught a few locations where we weren't following the right guidance: - Performing integer comparisons of different sizes which could lead to an infinite loop if the larger integer goes out of range of the smaller integer - Not checking HResult of a called method Co-authored-by: aphistra <[email protected]>
1 parent a86c90a commit 6e89242

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

src/buffer/out/Row.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ OutputCellIterator ROW::WriteCells(OutputCellIterator it, const til::CoordType c
431431
THROW_HR_IF(E_INVALIDARG, limitRight.value_or(0) >= size());
432432

433433
// If we're given a right-side column limit, use it. Otherwise, the write limit is the final column index available in the char row.
434-
const auto finalColumnInRow = limitRight.value_or(size() - 1);
434+
const auto finalColumnInRow = gsl::narrow_cast<uint16_t>(limitRight.value_or(size() - 1));
435435

436436
auto currentColor = it->TextAttr();
437437
uint16_t colorUses = 0;

src/renderer/gdi/paint.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ try
574574
}
575575

576576
const auto cpt = gsl::narrow_cast<DWORD>(points.size());
577-
return PolyBezier(_hdcMemoryContext, points.data(), cpt);
577+
RETURN_HR_IF(E_FAIL, !PolyBezier(_hdcMemoryContext, points.data(), cpt));
578+
return S_OK;
578579
};
579580

580581
if (lines.test(GridLines::Left))

src/terminal/adapter/SixelParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ void SixelParser::_updateTextColors()
610610
// the text output as well.
611611
if (_conformanceLevel <= 3 && _maxColors > 2 && _colorTableChanged) [[unlikely]]
612612
{
613-
for (IndexType tableIndex = 0; tableIndex < _maxColors; tableIndex++)
613+
for (IndexType tableIndex = 0; _maxColors <= 16 && tableIndex < _maxColors; tableIndex++)
614614
{
615615
_dispatcher.SetColorTableEntry(tableIndex, _colorFromIndex(tableIndex));
616616
}

src/terminal/adapter/charsets.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft::Console::VirtualTerminal
1919
public:
2020
constexpr CharSet(const std::initializer_list<std::pair<wchar_t, wchar_t>> replacements)
2121
{
22-
for (auto i = L'\0'; i < _translationTable.size(); i++)
22+
for (auto i = L'\0'; i < gsl::narrow_cast<wchar_t>(_translationTable.size()); i++)
2323
_translationTable.at(i) = BaseChar + i;
2424
for (auto replacement : replacements)
2525
_translationTable.at(replacement.first - BaseChar) = replacement.second;

0 commit comments

Comments
 (0)