Changeset - r16667:057c627d0a47
[Not reviewed]
master
0 3 0
rubidium - 13 years ago 2010-12-05 22:23:50
rubidium@openttd.org
(svn r21408) -Codechange: limit president name by amount of characters, not bytes
3 files changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -468,16 +468,16 @@ restart:;
 

	
 
		/* Reserve space for extra unicode character. We need to do this to be able
 
		 * to detect too long president name. */
 
		char buffer[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
 
		char buffer[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
 
		SetDParam(0, c->index);
 
		GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
 
		if (strlen(buffer) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) continue;
 
		if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
 

	
 
		Company *cc;
 
		FOR_ALL_COMPANIES(cc) {
 
			if (c != cc) {
 
				/* Reserve extra space so even overlength president names can be compared. */
 
				char buffer2[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
 
				char buffer2[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
 
				SetDParam(0, cc->index);
 
				GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2));
 
				if (strcmp(buffer2, buffer) == 0) goto restart;
 
@@ -1094,7 +1094,7 @@ CommandCost CmdRenamePresident(TileIndex
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
 
		if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
src/company_gui.cpp
Show inline comments
 
@@ -1946,7 +1946,7 @@ struct CompanyWindow : Window
 
			case CW_WIDGET_PRESIDENT_NAME:
 
				this->query_widget = CW_WIDGET_PRESIDENT_NAME;
 
				SetDParam(0, this->window_number);
 
				ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
 
				ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_CHARS, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
 
				break;
 

	
 
			case CW_WIDGET_COMPANY_NAME:
src/company_type.h
Show inline comments
 
@@ -37,7 +37,7 @@ enum Owner {
 
};
 
DECLARE_POSTFIX_INCREMENT(Owner)
 

	
 
static const uint MAX_LENGTH_PRESIDENT_NAME_BYTES  =  31; ///< The maximum length of a president name in bytes including '\0'
 
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS  =  31; ///< The maximum length of a president name in characters including '\0'
 
static const uint MAX_LENGTH_PRESIDENT_NAME_PIXELS =  94; ///< The maximum length of a president name in pixels
 
static const uint MAX_LENGTH_COMPANY_NAME_BYTES    =  31; ///< The maximum length of a company name in bytes including '\0'
 
static const uint MAX_LENGTH_COMPANY_NAME_PIXELS   = 150; ///< The maximum length of a company name in pixels
0 comments (0 inline, 0 general)