- Had a look at sbarinfo.cpp and noticed a few places where it allocated

character arrays and never freed them. Those have been replaced with
  uses of FString. (One of these was even an instance of a member variable
  being set to point at a stack variable.)


SVN r622 (trunk)
This commit is contained in:
Randy Heit 2007-12-22 23:19:08 +00:00
parent 4131ec141d
commit e419cc246f
3 changed files with 19 additions and 17 deletions

View file

@ -1,3 +1,9 @@
December 22, 2007
- Had a look at sbarinfo.cpp and noticed a few places where it allocated
character arrays and never freed them. Those have been replaced with
uses of FString. (One of these was even an instance of a member variable
being set to point at a stack variable.)
December 22, 2007 (Changes by Graf Zahl)
- Added Karate Chris's teamdamage in MAPINFO submission.
- Added Blzut3's second SBARINFO update.

View file

@ -737,20 +737,18 @@ int SBarInfo::newImage(const char* patchname)
return i;
}
}
char * name = new char[9];
memset(name, '\0', 9);
memcpy(name, patchname, 8);
this->Images.Push(name);
return this->Images.Size() - 1;
return this->Images.Push(patchname);
}
//converts a string into a tranlation.
EColorRange SBarInfo::GetTranslation(char* translation)
{
EColorRange returnVal = CR_UNTRANSLATED;
char* namedTranslation = new char[strlen(translation)+3]; //we must send in "[translation]"
sprintf(namedTranslation, "[%s]", translation);
if((returnVal = V_ParseFontColor((const BYTE*&) namedTranslation, CR_UNTRANSLATED, CR_UNTRANSLATED)) == CR_UNDEFINED)
FString namedTranslation; //we must send in "[translation]"
const BYTE *trans_ptr;
namedTranslation.Format("[%s]", translation);
trans_ptr = (const BYTE *)(&namedTranslation[0]);
if((returnVal = V_ParseFontColor(trans_ptr, CR_UNTRANSLATED, CR_UNTRANSLATED)) == CR_UNDEFINED)
{
SC_ScriptError("Missing definition for color %s.", translation);
}
@ -783,9 +781,7 @@ void SBarInfoCommand::setString(const char* source, int strnum, int maxlength, b
return;
}
}
this->string[strnum] = new char[strlen(source) + 1];
memset(this->string[strnum], '\0', strlen(source) + 1);
memcpy(this->string[strnum], source, strlen(source));
string[strnum] = source;
}
SBarInfoCommand::SBarInfoCommand() //sets the default values for more predicable behavior
@ -958,7 +954,7 @@ public:
oldHealth = 0;
}
mugshotHealth = -1;
lastPrefix = new char[4];
lastPrefix = "";
weaponGrin = false;
chainWiggle = 0;
}
@ -1054,7 +1050,7 @@ public:
}
private:
//code from doom_sbar.cpp but it should do fine.
void SetFace (FPlayerSkin *skin, char* defPrefix)
void SetFace (FPlayerSkin *skin, const char* defPrefix)
{
oldSkin = skin;
const char *nameptrs[ST_NUMFACES];
@ -1297,7 +1293,7 @@ private:
bool xdth = false;
if(cmd.special2 != 0)
xdth = true;
SetFace(oldSkin, cmd.string[0]);
SetFace(oldSkin, cmd.string[0].GetChars());
DrawFace(cmd.special, xdth, cmd.x, cmd.y);
break;
}
@ -1752,7 +1748,7 @@ private:
FImageCollection Faces;
FPlayerSkin *oldSkin;
FFont *drawingFont;
char* lastPrefix;
FString lastPrefix;
bool weaponGrin;
int faceTimer;
int faceIndex;

View file

@ -23,7 +23,7 @@ struct SBarInfoCommand
int y;
int value;
int sprite;
char* string[2];
FString string[2];
FFont *font;
EColorRange translation;
SBarInfoBlock subBlock; //for type SBarInfo_CMD_GAMEMODE
@ -33,7 +33,7 @@ struct SBarInfoCommand
struct SBarInfo
{
TArray<const char*> Images;
TArray<FString> Images;
SBarInfoBlock huds[6];
bool automapbar;
bool interpolateHealth;