CResource: Make BuildDependencyTree() return a unique_ptr

Makes the functions more memory safe in terms of freeing memory in
exceptional paths .
This commit is contained in:
Lioncash
2020-06-11 18:25:35 -04:00
parent eb8ca98a8a
commit ce315280c3
24 changed files with 82 additions and 93 deletions

View File

@@ -254,19 +254,17 @@ void CStringTable::Serialize(IArchive& Arc)
}
/** Build the dependency tree for this resource */
CDependencyTree* CStringTable::BuildDependencyTree() const
std::unique_ptr<CDependencyTree> CStringTable::BuildDependencyTree() const
{
// STRGs can reference FONTs with the &font=; formatting tag and TXTRs with the &image=; tag
CDependencyTree* pTree = new CDependencyTree();
auto pTree = std::make_unique<CDependencyTree>();
EIDLength IDLength = CAssetID::GameIDLength( Game() );
for (uint LanguageIdx = 0; LanguageIdx < mLanguages.size(); LanguageIdx++)
for (const SLanguageData& language : mLanguages)
{
const SLanguageData& kLanguage = mLanguages[LanguageIdx];
for (uint StringIdx = 0; StringIdx < kLanguage.Strings.size(); StringIdx++)
for (const auto& stringData : language.Strings)
{
const TString& kString = kLanguage.Strings[StringIdx].String;
const TString& kString = stringData.String;
for (int TagIdx = kString.IndexOf('&'); TagIdx != -1; TagIdx = kString.IndexOf('&', TagIdx + 1))
{
@@ -320,7 +318,7 @@ CDependencyTree* CStringTable::BuildDependencyTree() const
else if (ImageType == "B")
TexturesStart = 2;
else if (ImageType.IsHexString(false, IDLength * 2))
else if (ImageType.IsHexString(false, static_cast<int>(IDLength) * 2))
TexturesStart = 0;
else

View File

@@ -89,7 +89,7 @@ public:
void Serialize(IArchive& Arc) override;
/** Build the dependency tree for this resource */
CDependencyTree* BuildDependencyTree() const override;
std::unique_ptr<CDependencyTree> BuildDependencyTree() const override;
/** Static - Strip all formatting tags for a given string */
static TString StripFormatting(const TString& kInString);