- Fixed: If you called the FString assignment operator that accepts a

const char * with a string inside its buffer, it released the buffer
  before copying the string.
- Added a new FString constructor that creates the string from a lump.
- Fixed: G_DoReborn() calls G_InitNew() with mapname set to level.mapname.
  G_InitNew() then copies it onto level.mapname, which is undefined
  behavior (although it does work as we want it to).
- Modified FMemLump to store its data using FString. That class provides
  a convenient method of storing reference counted data, so now FMemLump
  doesn't need to muck about sneakily using const_casts and possibly
  tricking its users into thinking that an old one is still valid after
  being assigned to a new one.
- Fixed: The IMGZ, PNG, PCX, and JPEG loaders assumed the files were
  large enough for their headers without actually checking.



SVN r463 (trunk)
This commit is contained in:
Randy Heit 2007-01-25 04:02:06 +00:00
commit af13d6d686
13 changed files with 92 additions and 64 deletions

View file

@ -172,17 +172,34 @@ FString &FString::operator = (const FString &other)
}
FString &FString::operator = (const char *copyStr)
{
Data()->Release();
if (copyStr == NULL || *copyStr == '\0')
if (copyStr != Chars)
{
NullString.RefCount++;
Chars = &NullString.Nothing[0];
}
else
{
size_t len = strlen (copyStr);
AllocBuffer (len);
StrCopy (Chars, copyStr, len);
if (copyStr == NULL || *copyStr == '\0')
{
NullString.RefCount++;
Chars = &NullString.Nothing[0];
}
else
{
// In case copyStr is inside us, we can't release it until
// we've finished the copy.
FStringData *old = Data();
if (copyStr < Chars || copyStr >= Chars + old->Len)
{
// We know the string isn't in our buffer, so release it now
// to reduce the potential for needless memory fragmentation.
old->Release();
old = NULL;
}
size_t len = strlen (copyStr);
AllocBuffer (len);
StrCopy (Chars, copyStr, len);
if (old != NULL)
{
old->Release();
}
}
}
return *this;
}