Skip to content

Commit

Permalink
Defensive coding practices sponsored by MtnDustin
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Mar 14, 2023
1 parent 470b02c commit 1924a7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/host/readDataCooked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ void COOKED_READ_DATA::SavePendingInput(const size_t index, const bool multiline
{
// ProcessAliases() is supposed to end each line with \r\n. If it doesn't we might as well fail-fast.
const auto firstLineEnd = input.find(UNICODE_LINEFEED) + 1;
input = input.substr(0, firstLineEnd);
input = input.substr(0, std::min(input.size(), firstLineEnd));
}
}
}
Expand All @@ -1050,7 +1050,7 @@ void COOKED_READ_DATA::SavePendingInput(const size_t index, const bool multiline
const auto inputSizeAfter = input.size();
const auto amountConsumed = inputSizeBefore - inputSizeAfter;
input = { _backupLimit, _bytesRead / sizeof(wchar_t) };
input = input.substr(amountConsumed);
input = input.substr(std::min(input.size(), amountConsumed));
GetInputReadHandleData()->SaveMultilinePendingInput(input);
}
else if (!input.empty())
Expand Down
4 changes: 2 additions & 2 deletions src/host/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ try
if (readHandleState.IsMultilineInput())
{
const auto firstLineEnd = input.find(UNICODE_LINEFEED) + 1;
input = input.substr(0, firstLineEnd);
input = input.substr(0, std::min(input.size(), firstLineEnd));
}

const auto inputSizeBefore = input.size();
Expand All @@ -308,7 +308,7 @@ try
{
const auto inputSizeAfter = input.size();
const auto amountConsumed = inputSizeBefore - inputSizeAfter;
input = pending.substr(amountConsumed);
input = pending.substr(std::min(pending.size(), amountConsumed));
}

if (input.empty())
Expand Down

0 comments on commit 1924a7e

Please sign in to comment.