Changeset - r20774:3d68049ebbf2
[Not reviewed]
master
0 2 0
frosch - 11 years ago 2013-10-06 12:13:20
frosch@openttd.org
(svn r25818) -Fix [FS#5750]: [GS] Language file scanner considered filenames starting with '.' as valid translations, resulting in languages with empty name, which causes trouble.
2 files changed with 15 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/game/game_text.cpp
Show inline comments
 
@@ -60,18 +60,11 @@ void NORETURN CDECL strgen_fatal(const c
 
/**
 
 * Create a new container for language strings.
 
 * @param language The language name.
 
 * @param end If not NULL, terminate \a language at this position.
 
 */
 
LanguageStrings::LanguageStrings(const char *language)
 
LanguageStrings::LanguageStrings(const char *language, const char *end)
 
{
 
	const char *p = strrchr(language, PATHSEPCHAR);
 
	if (p == NULL) {
 
		p = language;
 
	} else {
 
		p++;
 
	}
 

	
 
	const char *e = strchr(p, '.');
 
	this->language = e == NULL ? strdup(p) : strndup(p, e - p);
 
	this->language = end == NULL ? strdup(language) : strndup(language, end - language);
 
}
 

	
 
/** Free everything. */
 
@@ -95,7 +88,17 @@ LanguageStrings *ReadRawLanguageStrings(
 
			return NULL;
 
		}
 

	
 
		ret = new LanguageStrings(file);
 
		const char *langname = strrchr(file, PATHSEPCHAR);
 
		if (langname == NULL) {
 
			langname = file;
 
		} else {
 
			langname++;
 
		}
 

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

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

	
 
		char buffer[2048];
 
		while (to_read != 0 && fgets(buffer, sizeof(buffer), fh) != NULL) {
src/game/game_text.hpp
Show inline comments
 
@@ -26,7 +26,7 @@ struct LanguageStrings {
 
	const char *language; ///< Name of the language (base filename).
 
	StringList lines;     ///< The lines of the file to pass into the parser/encoder.
 

	
 
	LanguageStrings(const char *language);
 
	LanguageStrings(const char *language, const char *end = NULL);
 
	~LanguageStrings();
 
};
 

	
0 comments (0 inline, 0 general)