Changeset - r23595:fc5e0f836f5d
[Not reviewed]
master
0 1 0
Michael Lutz - 6 years ago 2019-04-02 19:20:19
michi@icosahedron.de
Fix: Don't crash if reading a GS string file from disk produces an error.

The raw_strings vector may not include NULLs as no consumer can deal with it.
1 file changed with 13 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/game/game_text.cpp
Show inline comments
 
@@ -83,13 +83,12 @@ LanguageStrings::~LanguageStrings()
 
LanguageStrings *ReadRawLanguageStrings(const char *file)
 
{
 
	LanguageStrings *ret = NULL;
 
	FILE *fh = NULL;
 
	try {
 
		size_t to_read;
 
		fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read);
 
		if (fh == NULL) {
 
			return NULL;
 
		}
 
		FILE *fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read);
 
		if (fh == NULL) return NULL;
 

	
 
		FileCloser fhClose(fh);
 

	
 
		const char *langname = strrchr(file, PATHSEPCHAR);
 
		if (langname == NULL) {
 
@@ -99,10 +98,7 @@ LanguageStrings *ReadRawLanguageStrings(
 
		}
 

	
 
		/* Check for invalid empty filename */
 
		if (*langname == '.' || *langname == 0) {
 
			fclose(fh);
 
			return NULL;
 
		}
 
		if (*langname == '.' || *langname == 0) return NULL;
 

	
 
		ret = new LanguageStrings(langname, strchr(langname, '.'));
 

	
 
@@ -124,10 +120,8 @@ LanguageStrings *ReadRawLanguageStrings(
 
			}
 
		}
 

	
 
		fclose(fh);
 
		return ret;
 
	} catch (...) {
 
		if (fh != NULL) fclose(fh);
 
		delete ret;
 
		return NULL;
 
	}
 
@@ -246,7 +240,10 @@ public:
 
	{
 
		if (strcmp(filename, exclude) == 0) return true;
 

	
 
		gs->raw_strings.push_back(ReadRawLanguageStrings(filename));
 
		auto ls = ReadRawLanguageStrings(filename);
 
		if (ls == NULL) return false;
 

	
 
		gs->raw_strings.push_back(std::move(ls));
 
		return true;
 
	}
 
};
 
@@ -267,9 +264,12 @@ GameStrings *LoadTranslations()
 
	strecpy(e, "lang" PATHSEP "english.txt", lastof(filename));
 
	if (!FioCheckFileExists(filename, GAME_DIR)) return NULL;
 

	
 
	auto ls = ReadRawLanguageStrings(filename);
 
	if (ls == NULL) return NULL;
 

	
 
	GameStrings *gs = new GameStrings();
 
	try {
 
		gs->raw_strings.push_back(ReadRawLanguageStrings(filename));
 
		gs->raw_strings.push_back(std::move(ls));
 

	
 
		/* Scan for other language files */
 
		LanguageScanner scanner(gs, filename);
0 comments (0 inline, 0 general)