Skip to content

Commit

Permalink
let's not let pops take us below zero
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzdelightsme committed Jul 15, 2019
1 parent 0e478e5 commit 0af275b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ bool Terminal::PushGraphicsRendition(const ::Microsoft::Console::VirtualTerminal
else
{
// Save everything.
if ((_numSgrPushes < _countof(_storedSgrAttributes)) && (_numSgrPushes >= 0))
if (_numSgrPushes < _countof(_storedSgrAttributes))
{
_storedSgrAttributes[_numSgrPushes] = _buffer->GetCurrentAttributes();
}
Expand All @@ -275,11 +275,14 @@ bool Terminal::PushGraphicsRendition(const ::Microsoft::Console::VirtualTerminal

bool Terminal::PopGraphicsRendition()
{
_numSgrPushes--;

if ((_numSgrPushes < _countof(_storedSgrAttributes)) && (_numSgrPushes >= 0))
if (_numSgrPushes > 0)
{
_buffer->SetCurrentAttributes(_storedSgrAttributes[_numSgrPushes]);
_numSgrPushes--;

if (_numSgrPushes < _countof(_storedSgrAttributes))
{
_buffer->SetCurrentAttributes(_storedSgrAttributes[_numSgrPushes]);
}
}

return true;
Expand Down

0 comments on commit 0af275b

Please sign in to comment.