Skip to content

Commit

Permalink
Fix length calculation of GetConsoleCommandHistoryLengthA (#11897)
Browse files Browse the repository at this point in the history
This is a primitive bug fix for GetConsoleCommandHistoryLengthA.

## PR Checklist
* [x] I work here
* [x] Tests added/passed
  • Loading branch information
lhecker authored Dec 7, 2021
1 parent 35b633e commit ca20bbd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/host/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,16 +693,16 @@ HRESULT GetConsoleCommandHistoryLengthImplHelper(const std::wstring_view exeName
const auto command = pCommandHistory->GetNth(i);
size_t cchCommand = command.size();

// This is the proposed length of the whole string.
size_t cchProposed;
RETURN_IF_FAILED(SizeTAdd(cchCommand, cchNull, &cchProposed));

// If we're counting how much multibyte space will be needed, trial convert the command string before we add.
if (!countInUnicode)
{
cchCommand = GetALengthFromW(codepage, command);
}

// This is the proposed length of the whole string.
size_t cchProposed;
RETURN_IF_FAILED(SizeTAdd(cchCommand, cchNull, &cchProposed));

// Accumulate the result
RETURN_IF_FAILED(SizeTAdd(cchNeeded, cchProposed, &cchNeeded));
}
Expand Down

0 comments on commit ca20bbd

Please sign in to comment.