Bug: capitalize function is not color safe
Danger: Medium - Incorrect capitalization, in addition to possible buffer overruns
Found by: Dace
Fixed by: FearItself@AVP
---
db.c, capitalize
Replace the entire function with:
/*
* Returns an initial-capped string.
* Rewritten by FearItself@AvP
*/
char *capitalize( const char *str )
{
static char buf[MAX_STRING_LENGTH];
char *dest = buf;
enum { Normal, Color } state = Normal;
bool bFirst = TRUE;
char c;
while( (c = *str++) )
{
if( state == Normal )
{
if( c == '&' || c == '^' || c == '}' )
{
state = Color;
}
else if( isalpha(c) )
{
c = bFirst ? toupper(c) : tolower(c);
bFirst = FALSE;
}
}
else
{
state = Normal;
}
*dest++ = c;
}
*dest = c;
return buf;
}
As Fear explained it, the stock colorize function pays no attention to the use of color tags and will incorrectly capitalize the first letter it comes to, even if that's part of a color tag.