fixed possible problem with localisations if the linereader flushes its memory between reading the origin and the replacement string

This commit is contained in:
oy 2011-02-10 12:07:00 +01:00
parent 3f05289328
commit 0c119ba99b
2 changed files with 9 additions and 5 deletions

View file

@ -690,6 +690,7 @@ void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<
return;
}
char aOrigin[128];
CLineReader LineReader;
LineReader.Init(File);
char *pLine;
@ -697,7 +698,8 @@ void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<
{
if(!str_length(pLine) || pLine[0] == '#') // skip empty lines and comments
continue;
str_copy(aOrigin, pLine, sizeof(aOrigin));
char *pReplacement = LineReader.Get();
if(!pReplacement)
{
@ -708,13 +710,13 @@ void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<
if(pReplacement[0] != '=' || pReplacement[1] != '=' || pReplacement[2] != ' ')
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "malform replacement for index '%s'", pLine);
str_format(aBuf, sizeof(aBuf), "malform replacement for index '%s'", aOrigin);
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
continue;
}
char aFileName[128];
str_format(aFileName, sizeof(aFileName), "languages/%s.txt", pLine);
str_format(aFileName, sizeof(aFileName), "languages/%s.txt", aOrigin);
pLanguages->add(CLanguage(pReplacement+3, aFileName));
}
io_close(File);

View file

@ -63,6 +63,7 @@ bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, ICon
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
m_Strings.clear();
char aOrigin[512];
CLineReader LineReader;
LineReader.Init(IoHandle);
char *pLine;
@ -74,6 +75,7 @@ bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, ICon
if(pLine[0] == '#') // skip comments
continue;
str_copy(aOrigin, pLine, sizeof(aOrigin));
char *pReplacement = LineReader.Get();
if(!pReplacement)
{
@ -83,13 +85,13 @@ bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, ICon
if(pReplacement[0] != '=' || pReplacement[1] != '=' || pReplacement[2] != ' ')
{
str_format(aBuf, sizeof(aBuf), "malform replacement line for '%s'", pLine);
str_format(aBuf, sizeof(aBuf), "malform replacement line for '%s'", aOrigin);
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
continue;
}
pReplacement += 3;
AddString(pLine, pReplacement);
AddString(aOrigin, pReplacement);
}
io_close(IoHandle);