From 496e28aa7accf76f732e7e6cd25b47f571b45825 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 31 May 2008 01:30:53 +0000 Subject: [PATCH] - Fixed: DSBarInfo::updateState() sprung leaks and didn't allocate enough space for the fullStateName string. SVN r1003 (trunk) --- docs/rh-log.txt | 2 ++ src/g_shared/sbarinfo_display.cpp | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index cfb9dea18..3d955b9e2 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,6 @@ May 30, 2008 +- Fixed: DSBarInfo::updateState() sprung leaks and didn't allocate enough + space for the fullStateName string. - Disabled DUMB's mono destination mixers. It's not like I'm ever going to target an original SoundBlaster, so they're a waste of space to have around. This trims resample.obj down to ~60k now. diff --git a/src/g_shared/sbarinfo_display.cpp b/src/g_shared/sbarinfo_display.cpp index ef71cf64a..268d502ae 100644 --- a/src/g_shared/sbarinfo_display.cpp +++ b/src/g_shared/sbarinfo_display.cpp @@ -1359,7 +1359,10 @@ void DSBarInfo::DrawFace(FString &defaultFace, int accuracy, bool xdth, bool ani { int angle = updateState(xdth, animatedgodmode); int level = 0; - for(level = 0;CPlayer->health < (accuracy-level-1)*(CPlayer->mo->GetMaxHealth()/accuracy);level++); + while (CPlayer->health < (accuracy-level-1)*(CPlayer->mo->GetMaxHealth()/accuracy)) + { + level++; + } if(currentState != NULL) { FPlayerSkin *skin = &skins[CPlayer->morphTics ? CPlayer->MorphedPlayerClass : CPlayer->userinfo.skin]; @@ -1420,7 +1423,7 @@ int DSBarInfo::updateState(bool xdth, bool animatedgodmode) } } bool setOuch = false; - const char* stateName = new char[5]; + const char *stateName; if ((mugshotHealth != -1 && CPlayer->health - mugshotHealth > 20) || ouchActive) { setOuch = true; @@ -1428,8 +1431,8 @@ int DSBarInfo::updateState(bool xdth, bool animatedgodmode) } else stateName = "pain"; - char* fullStateName = new char[sizeof(stateName)+sizeof((const char*) CPlayer->LastDamageType) + 1]; - sprintf(fullStateName, "%s.%s", stateName, (const char*) CPlayer->LastDamageType); + FString fullStateName; + fullStateName << stateName << '.' << CPlayer->LastDamageType; if(FindMugShotState(fullStateName) != NULL) SetMugShotState(fullStateName); else @@ -1446,7 +1449,7 @@ int DSBarInfo::updateState(bool xdth, bool animatedgodmode) else { bool setOuch = false; - const char* stateName = new char[5]; + const char *stateName; if ((mugshotHealth != -1 && CPlayer->health - mugshotHealth > 20) || ouchActive) { setOuch = true; @@ -1454,8 +1457,8 @@ int DSBarInfo::updateState(bool xdth, bool animatedgodmode) } else stateName = "pain"; - char* fullStateName = new char[sizeof(stateName)+sizeof((const char*) CPlayer->LastDamageType) + 1]; - sprintf(fullStateName, "%s.%s", stateName, (const char*) CPlayer->LastDamageType); + FString fullStateName; + fullStateName << stateName << '.' << CPlayer->LastDamageType; if(FindMugShotState(fullStateName) != NULL) SetMugShotState(fullStateName); else @@ -1487,14 +1490,13 @@ int DSBarInfo::updateState(bool xdth, bool animatedgodmode) } else { - const char* stateName = new char[7]; + const char *stateName; if(!xdth || !(CPlayer->cheats & CF_EXTREMELYDEAD)) stateName = "death"; else stateName = "xdeath"; - //new string the size of stateName and the damage type put together - char* fullStateName = new char[sizeof(stateName)+sizeof((const char*) CPlayer->LastDamageType) + 1]; - sprintf(fullStateName, "%s.%s", stateName, (const char*) CPlayer->LastDamageType); + FString fullStateName; + fullStateName << stateName << '.' << CPlayer->LastDamageType; if(FindMugShotState(fullStateName) != NULL) SetMugShotState(fullStateName); else