Changeset - r11184:e190c0261998
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-02-21 00:47:59
rubidium@openttd.org
(svn r15537) -Fix (r5215): don't allow special sprite characters (e.g. the ship sprite) as characters in input like filenames or text that is sent over the network.
1 file changed with 1 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/string.cpp
Show inline comments
 
@@ -95,26 +95,25 @@ char *CDECL str_fmt(const char *str, ...
 
	memcpy(p, buf, len + 1);
 
	return p;
 
}
 

	
 

	
 
void str_validate(char *str, bool allow_newlines, bool ignore)
 
{
 
	char *dst = str;
 
	WChar c;
 
	size_t len;
 

	
 
	for (len = Utf8Decode(&c, str); c != '\0'; len = Utf8Decode(&c, str)) {
 
		if (IsPrintable(c) && (c < SCC_SPRITE_START || c > SCC_SPRITE_END ||
 
			IsValidChar(c - SCC_SPRITE_START, CS_ALPHANUMERAL))) {
 
		if (IsPrintable(c) && (c < SCC_SPRITE_START || c > SCC_SPRITE_END)) {
 
			/* Copy the character back. Even if dst is current the same as str
 
			 * (i.e. no characters have been changed) this is quicker than
 
			 * moving the pointers ahead by len */
 
			do {
 
				*dst++ = *str++;
 
			} while (--len != 0);
 
		} else if (allow_newlines && c == '\n') {
 
			*dst++ = *str++;
 
		} else {
 
			if (allow_newlines && c == '\r' && str[1] == '\n') {
 
				str += len;
 
				continue;
0 comments (0 inline, 0 general)