Fixed: TicSpecial could run out of space when writing data

- Fixed: TicSpecial::CheckSpace() never thought it ran out of space due to
  unsigned math.
- Fixed: TicSpecial::GetMoreSpace() assumed only relatively small amounts
  of data would be written at a time so made no effort to ensure it
  actually got enough space. This assumption could be violated by writing
  a very long string, which can happen when replicating a string cvar.
This commit is contained in:
Randy Heit 2015-01-01 17:57:09 -06:00
parent 26cf383ead
commit 86986446a5
1 changed files with 5 additions and 5 deletions

View File

@ -185,7 +185,7 @@ static struct TicSpecial
size_t used[BACKUPTICS];
BYTE *streamptr;
size_t streamoffs;
int specialsize;
size_t specialsize;
int lastmaketic;
bool okay;
@ -224,11 +224,11 @@ static struct TicSpecial
}
// Make more room for special commands.
void GetMoreSpace ()
void GetMoreSpace (size_t needed)
{
int i;
specialsize <<= 1;
specialsize = MAX(specialsize * 2, needed + 30);
DPrintf ("Expanding special size to %d\n", specialsize);
@ -240,8 +240,8 @@ static struct TicSpecial
void CheckSpace (size_t needed)
{
if (streamoffs >= specialsize - needed)
GetMoreSpace ();
if (streamoffs + needed >= specialsize)
GetMoreSpace (streamoffs + needed);
streamoffs += needed;
}