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;
}
};