From 65dec36cb1eebbb700eb220b7c1a36ceedea03d8 Mon Sep 17 00:00:00 2001 From: Michael Niksa Date: Thu, 29 Aug 2019 11:05:32 -0700 Subject: [PATCH] C26446, Use .at instead of array indices --- src/buffer/out/AttrRow.cpp | 6 ++--- src/buffer/out/TextColor.cpp | 8 +++--- src/buffer/out/textBuffer.cpp | 24 ++++++++--------- src/renderer/dx/CustomTextLayout.cpp | 36 ++++++++++++------------- src/types/IInputEvent.cpp | 2 +- src/types/ScreenInfoUiaProviderBase.cpp | 4 +-- src/types/UiaTextRangeBase.cpp | 2 +- src/types/convert.cpp | 2 +- src/types/utils.cpp | 12 ++++----- 9 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/buffer/out/AttrRow.cpp b/src/buffer/out/AttrRow.cpp index e9efd8f603..37d77a02f0 100644 --- a/src/buffer/out/AttrRow.cpp +++ b/src/buffer/out/AttrRow.cpp @@ -46,7 +46,7 @@ void ATTR_ROW::Resize(const size_t newWidth) { // Get the attribute that covers the final column of old width. const auto runPos = FindAttrIndex(_cchRowWidth - 1, nullptr); - auto& run = _list[runPos]; + auto& run = _list.at(runPos); // Extend its length by the additional columns we're adding. run.SetLength(run.GetLength() + newWidth - _cchRowWidth); @@ -60,7 +60,7 @@ void ATTR_ROW::Resize(const size_t newWidth) // Get the attribute that covers the final column of the new width size_t CountOfAttr = 0; const auto runPos = FindAttrIndex(newWidth - 1, &CountOfAttr); - auto& run = _list[runPos]; + auto& run = _list.at(runPos); // CountOfAttr was given to us as "how many columns left from this point forward are covered by the returned run" // So if the original run was B5 covering a 5 size OldWidth and we have a NewWidth of 3 @@ -108,7 +108,7 @@ TextAttribute ATTR_ROW::GetAttrByColumn(const size_t column, { THROW_HR_IF(E_INVALIDARG, column >= _cchRowWidth); const auto runPos = FindAttrIndex(column, pApplies); - return _list[runPos].GetAttributes(); + return _list.at(runPos).GetAttributes(); } // Routine Description: diff --git a/src/buffer/out/TextColor.cpp b/src/buffer/out/TextColor.cpp index 76778a8230..af90f9ff85 100644 --- a/src/buffer/out/TextColor.cpp +++ b/src/buffer/out/TextColor.cpp @@ -81,9 +81,9 @@ COLORREF TextColor::GetColor(std::basic_string_view colorTable, // If we find a match, return instead the bright version of this color for (size_t i = 0; i < 8; i++) { - if (colorTable[i] == defaultColor) + if (colorTable.at(i) == defaultColor) { - return colorTable[i + 8]; + return colorTable.at(i + 8); } } } @@ -103,11 +103,11 @@ COLORREF TextColor::GetColor(std::basic_string_view colorTable, { FAIL_FAST_IF(colorTable.size() < 16); FAIL_FAST_IF((size_t)(_index + 8) > (size_t)(colorTable.size())); - return colorTable[_index + 8]; + return colorTable.at(_index + 8); } else { - return colorTable[_index]; + return colorTable.at(_index); } } } diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index 831c672a58..09cae28d62 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -78,7 +78,7 @@ const ROW& TextBuffer::GetRowByOffset(const size_t index) const // Rows are stored circularly, so the index you ask for is offset by the start position and mod the total of rows. const size_t offsetIndex = (_firstRow + index) % totalRows; - return _storage[offsetIndex]; + return _storage.at(offsetIndex); } // Routine Description: @@ -812,7 +812,7 @@ void TextBuffer::Reset() // rotate rows until the top row is at index 0 try { - const ROW& newTopRow = _storage[TopRowIndex]; + const ROW& newTopRow = _storage.at(TopRowIndex); while (&newTopRow != &_storage.front()) { _storage.push_back(std::move(_storage.front())); @@ -923,7 +923,7 @@ ROW& TextBuffer::_GetPrevRowNoWrap(const ROW& Row) } THROW_HR_IF(E_FAIL, Row.GetId() == _firstRow); - return _storage[prevRowIndex]; + return _storage.at(prevRowIndex); } // Method Description: @@ -1118,25 +1118,25 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPo htmlBuilder << "
"; } - for (UINT col = 0; col < rows.text[row].length(); col++) + for (UINT 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. bool isLastCharInRow = - col == rows.text[row].length() - 1 || - rows.text[row][col + 1] == '\r' || - rows.text[row][col + 1] == '\n'; + col == rows.text.at(row).length() - 1 || + rows.text.at(row).at(col + 1) == '\r' || + rows.text.at(row).at(col + 1) == '\n'; bool colorChanged = false; - if (!fgColor.has_value() || rows.FgAttr[row][col] != fgColor.value()) + if (!fgColor.has_value() || rows.FgAttr.at(row).at(col) != fgColor.value()) { - fgColor = rows.FgAttr[row][col]; + fgColor = rows.FgAttr.at(row).at(col); colorChanged = true; } - if (!bkColor.has_value() || rows.BkAttr[row][col] != bkColor.value()) + if (!bkColor.has_value() || rows.BkAttr.at(row).at(col) != bkColor.value()) { - bkColor = rows.BkAttr[row][col]; + bkColor = rows.BkAttr.at(row).at(col); colorChanged = true; } @@ -1145,7 +1145,7 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPo { // note: this should be escaped (for '<', '>', and '&'), // however MS Word doesn't appear to support HTML entities - htmlBuilder << ConvertToA(CP_UTF8, std::wstring_view(rows.text[row].data() + startOffset, col - startOffset + includeCurrent)); + htmlBuilder << ConvertToA(CP_UTF8, std::wstring_view(rows.text.at(row).data() + startOffset, col - startOffset + includeCurrent)); startOffset = col; } }; diff --git a/src/renderer/dx/CustomTextLayout.cpp b/src/renderer/dx/CustomTextLayout.cpp index 94cf4c8e47..73b1401027 100644 --- a/src/renderer/dx/CustomTextLayout.cpp +++ b/src/renderer/dx/CustomTextLayout.cpp @@ -268,7 +268,7 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, do { hr = _analyzer->GetGlyphs( - &_text[textStart], + &_text.at(textStart), textLength, run.fontFace.Get(), run.isSideways, // isSideways, @@ -280,10 +280,10 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, nullptr, // featureLengths 0, // featureCount maxGlyphCount, // maxGlyphCount - &_glyphClusters[textStart], - &textProps[0], - &_glyphIndices[glyphStart], - &glyphProps[0], + &_glyphClusters.at(textStart), + &textProps.at(0), + &_glyphIndices.at(glyphStart), + &glyphProps.at(0), &actualGlyphCount); tries++; @@ -313,12 +313,12 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, const auto fontSize = fontSizeFormat * run.fontScale; hr = _analyzer->GetGlyphPlacements( - &_text[textStart], - &_glyphClusters[textStart], - &textProps[0], + &_text.at(textStart), + &_glyphClusters.at(textStart), + &textProps.at(0), textLength, - &_glyphIndices[glyphStart], - &glyphProps[0], + &_glyphIndices.at(glyphStart), + &glyphProps.at(0), actualGlyphCount, run.fontFace.Get(), fontSize, @@ -329,8 +329,8 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, NULL, // features NULL, // featureRangeLengths 0, // featureRanges - &_glyphAdvances[glyphStart], - &_glyphOffsets[glyphStart]); + &_glyphAdvances.at(glyphStart), + &_glyphOffsets.at(glyphStart)); RETURN_IF_FAILED(hr); @@ -391,13 +391,13 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, for (auto i = run.glyphStart; i < (run.glyphStart + run.glyphCount); i++) { // Advance is how wide in pixels the glyph is - auto& advance = _glyphAdvances[i]; + auto& advance = _glyphAdvances.at(i); // Offsets is how far to move the origin (in pixels) from where it is - auto& offset = _glyphOffsets[i]; + auto& offset = _glyphOffsets.at(i); // Get how many columns we expected the glyph to have and mutiply into pixels. - const auto columns = _textClusterColumns[i]; + const auto columns = _textClusterColumns.at(i); const auto advanceExpected = static_cast(columns * _width); // If what we expect is bigger than what we have... pad it out. @@ -419,7 +419,7 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, // We need to retrieve the design information for this specific glyph so we can figure out the appropriate // height proportional to the width that we desire. INT32 advanceInDesignUnits; - RETURN_IF_FAILED(run.fontFace->GetDesignGlyphAdvances(1, &_glyphIndices[i], &advanceInDesignUnits)); + RETURN_IF_FAILED(run.fontFace->GetDesignGlyphAdvances(1, &_glyphIndices.at(i), &advanceInDesignUnits)); // When things are drawn, we want the font size (as specified in the base font in the original format) // to be scaled by some factor. @@ -940,7 +940,7 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, // - - Updates internal state void CustomTextLayout::_SetCurrentRun(const UINT32 textPosition) { - if (_runIndex < _runs.size() && _runs[_runIndex].ContainsTextPosition(textPosition)) + if (_runIndex < _runs.size() && _runs.at(_runIndex).ContainsTextPosition(textPosition)) { return; } @@ -974,7 +974,7 @@ void CustomTextLayout::_SplitCurrentRun(const UINT32 splitPosition) } // Copy the old run to the end. - LinkedRun& frontHalf = _runs[_runIndex]; + LinkedRun& frontHalf = _runs.at(_runIndex); LinkedRun& backHalf = _runs.back(); backHalf = frontHalf; diff --git a/src/types/IInputEvent.cpp b/src/types/IInputEvent.cpp index f7a3a925a2..5df614a6ca 100644 --- a/src/types/IInputEvent.cpp +++ b/src/types/IInputEvent.cpp @@ -48,7 +48,7 @@ std::deque> IInputEvent::Create(const std::deque> outEvents; for (size_t i = 0; i < records.size(); ++i) { - std::unique_ptr event = IInputEvent::Create(records[i]); + std::unique_ptr event = IInputEvent::Create(records.at(i)); outEvents.push_back(std::move(event)); } return outEvents; diff --git a/src/types/ScreenInfoUiaProviderBase.cpp b/src/types/ScreenInfoUiaProviderBase.cpp index aff23dde5c..8b04360110 100644 --- a/src/types/ScreenInfoUiaProviderBase.cpp +++ b/src/types/ScreenInfoUiaProviderBase.cpp @@ -388,14 +388,14 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_ // fill the safe array for (LONG i = 0; i < static_cast(ranges.size()); ++i) { - hr = SafeArrayPutElement(*ppRetVal, &i, reinterpret_cast(ranges[i])); + hr = SafeArrayPutElement(*ppRetVal, &i, reinterpret_cast(ranges.at(i))); if (FAILED(hr)) { SafeArrayDestroy(*ppRetVal); *ppRetVal = nullptr; while (!ranges.empty()) { - UiaTextRangeBase* pRange = ranges[0]; + UiaTextRangeBase* pRange = ranges.at(0); ranges.pop_front(); pRange->Release(); } diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 47e7d502f3..f4932f70de 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -487,7 +487,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetBoundingRectangles(_Outptr_result_maybenull_ HRESULT hr; for (LONG i = 0; i < static_cast(coords.size()); ++i) { - hr = SafeArrayPutElement(*ppRetVal, &i, &coords[i]); + hr = SafeArrayPutElement(*ppRetVal, &i, &coords.at(i)); if (FAILED(hr)) { SafeArrayDestroy(*ppRetVal); diff --git a/src/types/convert.cpp b/src/types/convert.cpp index 7ca12962c9..966e9f4a5b 100644 --- a/src/types/convert.cpp +++ b/src/types/convert.cpp @@ -284,7 +284,7 @@ std::deque> SynthesizeNumpadEvents(const wchar_t wch, // But it is absolutely valid as 0xFF or 255 unsigned as the correct CP437 character. // We need to treat it as unsigned because we're going to pretend it was a keypad entry // and you don't enter negative numbers on the keypad. - unsigned char const uch = static_cast(convertedChars[0]); + unsigned char const uch = static_cast(convertedChars.at(0)); // unsigned char values are in the range [0, 255] so we need to be // able to store up to 4 chars from the conversion (including the end of string char) diff --git a/src/types/utils.cpp b/src/types/utils.cpp index 8554c00a19..8806748a46 100644 --- a/src/types/utils.cpp +++ b/src/types/utils.cpp @@ -92,11 +92,11 @@ std::string Utils::ColorToHexString(const COLORREF color) COLORREF Utils::ColorFromHexString(const std::string str) { THROW_HR_IF(E_INVALIDARG, str.size() < 7 || str.size() >= 8); - THROW_HR_IF(E_INVALIDARG, str[0] != '#'); + THROW_HR_IF(E_INVALIDARG, str.at(0) != '#'); - std::string rStr{ &str[1], 2 }; - std::string gStr{ &str[3], 2 }; - std::string bStr{ &str[5], 2 }; + std::string rStr{ &str.at(1), 2 }; + std::string gStr{ &str.at(3), 2 }; + std::string bStr{ &str.at(5), 2 }; BYTE r = static_cast(std::stoul(rStr, nullptr, 16)); BYTE g = static_cast(std::stoul(gStr, nullptr, 16)); @@ -490,8 +490,8 @@ GUID Utils::CreateV5Uuid(const GUID& namespaceGuid, const gsl::span buffer; THROW_IF_NTSTATUS_FAILED(BCryptFinishHash(hash.get(), buffer.data(), gsl::narrow(buffer.size()), 0)); - buffer[6] = (buffer[6] & 0x0F) | 0x50; // set the uuid version to 5 - buffer[8] = (buffer[8] & 0x3F) | 0x80; // set the variant to 2 (RFC4122) + buffer.at(6) = (buffer.at(6) & 0x0F) | 0x50; // set the uuid version to 5 + buffer.at(8) = (buffer.at(8) & 0x3F) | 0x80; // set the variant to 2 (RFC4122) // We're using memcpy here pursuant to N4713 6.7.2/3 [basic.types], // "...the underlying bytes making up the object can be copied into an array