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

View file

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