Browse Source

Fix crashes caused by poor iterator usage.

Joseph Davies 13 years ago
parent
commit
a305f61748
  1. 40
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp

40
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp

@ -599,8 +599,9 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std
std::wstring elementName = curElement->first; std::wstring elementName = curElement->first;
LocalizationXMLFile::element& theElement = curElement->second; LocalizationXMLFile::element& theElement = curElement->second;
LocalizationXMLFile::element::iterator curTranslation; LocalizationXMLFile::element::iterator curTranslation = theElement.begin();
for (curTranslation = theElement.begin(); curTranslation != theElement.end(); curTranslation++)
while (curTranslation != theElement.end())
{ {
// Make sure this language exists! // Make sure this language exists!
bool languageExists = false; bool languageExists = false;
@ -612,25 +613,17 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std
break; break;
} }
} }
if (!languageExists) if (!languageExists)
{ {
fErrorString += L"ERROR: The language " + curTranslation->first + L" used by " + ageName + L"." + setName + L"."; fErrorString += L"ERROR: The language " + curTranslation->first + L" used by " + ageName + L"." + setName + L".";
fErrorString += elementName + L" is not supported, discarding translation\n"; fErrorString += elementName + L" is not supported, discarding translation\n";
theElement.erase(curTranslation); curTranslation = theElement.erase(curTranslation);
curTranslation--; // because this will be incremented on the next run through the loop
continue;
} }
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++) for (int i = 1; i < languageNames.size(); i++)
{ {
if (theElement.find(languageNames[i]) == theElement.end()) 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) void LocalizationDatabase::IVerifySet(const std::wstring &ageName, const std::wstring &setName)
{ {
LocalizationXMLFile::set& theSet = fData[ageName][setName]; LocalizationXMLFile::set& theSet = fData[ageName][setName];
LocalizationXMLFile::set::iterator curElement; LocalizationXMLFile::set::iterator curElement = theSet.begin();
for (curElement = theSet.begin(); curElement != theSet.end(); curElement++) 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); IVerifyElement(ageName, setName, curElement);
curElement++;
}
}
} }
//// IVerifyAge() //////////////////////////////////////////////////// //// IVerifyAge() ////////////////////////////////////////////////////

Loading…
Cancel
Save