From a305f6174891c50b6f045346e5a44f831718fda7 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Tue, 17 Apr 2012 11:26:31 -0700 Subject: [PATCH 1/3] Fix crashes caused by poor iterator usage. --- .../pfLocalizationDataMgr.cpp | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp index f1cf30d1..c488536e 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -599,8 +599,9 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std std::wstring elementName = curElement->first; LocalizationXMLFile::element& theElement = curElement->second; - LocalizationXMLFile::element::iterator curTranslation; - for (curTranslation = theElement.begin(); curTranslation != theElement.end(); curTranslation++) + LocalizationXMLFile::element::iterator curTranslation = theElement.begin(); + + while (curTranslation != theElement.end()) { // Make sure this language exists! bool languageExists = false; @@ -612,25 +613,17 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std break; } } + if (!languageExists) { fErrorString += L"ERROR: The language " + curTranslation->first + L" used by " + ageName + L"." + setName + L"."; fErrorString += elementName + L" is not supported, discarding translation\n"; - theElement.erase(curTranslation); - curTranslation--; // because this will be incremented on the next run through the loop - continue; + curTranslation = theElement.erase(curTranslation); } + else + curTranslation++; } - LocalizationXMLFile::set& theSet = fData[ageName][setName]; - if (theElement.find(defaultLanguage) == theElement.end()) - { - fErrorString += L"ERROR: Default language " + defaultLanguage + L" is missing from the translations in element "; - fErrorString += ageName + L"." + setName + L"." + elementName + L", deleting element\n"; - theSet.erase(curElement); - curElement--; - return; - } for (int i = 1; i < languageNames.size(); i++) { if (theElement.find(languageNames[i]) == theElement.end()) @@ -646,9 +639,24 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std void LocalizationDatabase::IVerifySet(const std::wstring &ageName, const std::wstring &setName) { LocalizationXMLFile::set& theSet = fData[ageName][setName]; - LocalizationXMLFile::set::iterator curElement; - for (curElement = theSet.begin(); curElement != theSet.end(); curElement++) - IVerifyElement(ageName, setName, curElement); + LocalizationXMLFile::set::iterator curElement = theSet.begin(); + std::wstring defaultLanguage = hsStringToWString(plLocalization::GetLanguageName((plLocalization::Language)0)); + + while (curElement != theSet.end()) + { + // Check that we at least have a default language translation for fallback + if (curElement->second.find(defaultLanguage) == curElement->second.end()) + { + fErrorString += L"ERROR: Default language " + defaultLanguage + L" is missing from the translations in element "; + fErrorString += ageName + L"." + setName + L"." + curElement->first + L", deleting element\n"; + curElement = theSet.erase(curElement); + } + else + { + IVerifyElement(ageName, setName, curElement); + curElement++; + } + } } //// IVerifyAge() //////////////////////////////////////////////////// From 6cf0898bc143808a7a88719d9a063f9b78fc8a39 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Wed, 18 Apr 2012 18:29:58 -0700 Subject: [PATCH 2/3] Make Localization log message more useful. --- .../FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp index c488536e..3b80df57 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -958,7 +958,7 @@ void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const s numArgs = argCount; else if (argCount != numArgs) { - std::wstring errorStr = L"WARNING: Argument number mismatch in element " + curPath; + std::wstring errorStr = L"WARNING: Argument number mismatch in element " + curPath + L" for " + curTranslation->first; char* cErrorStr = hsWStringToString(errorStr.c_str()); fLog->AddLine(cErrorStr); delete [] cErrorStr; From 155e75479becad5a70a1fadf5ebfe4773176592f Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Fri, 20 Apr 2012 18:46:05 -0700 Subject: [PATCH 3/3] Fix memory leak from copied string pointer in LocalizationDatabase. --- .../FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp index 3b80df57..f73c74d0 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -640,7 +640,9 @@ void LocalizationDatabase::IVerifySet(const std::wstring &ageName, const std::ws { LocalizationXMLFile::set& theSet = fData[ageName][setName]; LocalizationXMLFile::set::iterator curElement = theSet.begin(); - std::wstring defaultLanguage = hsStringToWString(plLocalization::GetLanguageName((plLocalization::Language)0)); + wchar_t *wDefLang = hsStringToWString(plLocalization::GetLanguageName((plLocalization::Language)0)); + std::wstring defaultLanguage = wDefLang; + delete [] wDefLang; while (curElement != theSet.end()) {