C26446, Use .at instead of array indices

This commit is contained in:
Michael Niksa 2019-08-29 11:05:32 -07:00
parent 1989eb9d00
commit 65dec36cb1
9 changed files with 48 additions and 48 deletions

View file

@ -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:

View file

@ -81,9 +81,9 @@ COLORREF TextColor::GetColor(std::basic_string_view<COLORREF> 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<COLORREF> 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);
}
}
}

View file

@ -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 << "<BR>";
}
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 '<BR>' 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;
}
};

View file

@ -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<float>(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,
// - <none> - 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;

View file

@ -48,7 +48,7 @@ std::deque<std::unique_ptr<IInputEvent>> IInputEvent::Create(const std::deque<IN
std::deque<std::unique_ptr<IInputEvent>> outEvents;
for (size_t i = 0; i < records.size(); ++i)
{
std::unique_ptr<IInputEvent> event = IInputEvent::Create(records[i]);
std::unique_ptr<IInputEvent> event = IInputEvent::Create(records.at(i));
outEvents.push_back(std::move(event));
}
return outEvents;

View file

@ -388,14 +388,14 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_
// fill the safe array
for (LONG i = 0; i < static_cast<LONG>(ranges.size()); ++i)
{
hr = SafeArrayPutElement(*ppRetVal, &i, reinterpret_cast<void*>(ranges[i]));
hr = SafeArrayPutElement(*ppRetVal, &i, reinterpret_cast<void*>(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();
}

View file

@ -487,7 +487,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetBoundingRectangles(_Outptr_result_maybenull_
HRESULT hr;
for (LONG i = 0; i < static_cast<LONG>(coords.size()); ++i)
{
hr = SafeArrayPutElement(*ppRetVal, &i, &coords[i]);
hr = SafeArrayPutElement(*ppRetVal, &i, &coords.at(i));
if (FAILED(hr))
{
SafeArrayDestroy(*ppRetVal);

View file

@ -284,7 +284,7 @@ std::deque<std::unique_ptr<KeyEvent>> 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<unsigned char>(convertedChars[0]);
unsigned char const uch = static_cast<unsigned char>(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)

View file

@ -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<BYTE>(std::stoul(rStr, nullptr, 16));
BYTE g = static_cast<BYTE>(std::stoul(gStr, nullptr, 16));
@ -490,8 +490,8 @@ GUID Utils::CreateV5Uuid(const GUID& namespaceGuid, const gsl::span<const gsl::b
std::array<uint8_t, 20> buffer;
THROW_IF_NTSTATUS_FAILED(BCryptFinishHash(hash.get(), buffer.data(), gsl::narrow<ULONG>(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