diff options
author | ludwig <ludwig@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2007-10-08 10:26:28 +0000 |
---|---|---|
committer | ludwig <ludwig@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2007-10-08 10:26:28 +0000 |
commit | 03cb6f5776e1fd3929484b27e944b93068d0ae16 (patch) | |
tree | 88bedb08d0da280ef8a716e50f84ce2efa31ea3f /code/sys | |
parent | aeaae017e0ca84f74fb3877744d1cf575f83773c (diff) | |
download | ioquake3-aero-03cb6f5776e1fd3929484b27e944b93068d0ae16.tar.gz ioquake3-aero-03cb6f5776e1fd3929484b27e944b93068d0ae16.zip |
fix incorrect use of strncpy
this function should really be removed or rewritten from scratch
git-svn-id: svn://svn.icculus.org/quake3/trunk@1191 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/sys')
-rw-r--r-- | code/sys/sys_main.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/code/sys/sys_main.c b/code/sys/sys_main.c index f12f83b..0402e1d 100644 --- a/code/sys/sys_main.c +++ b/code/sys/sys_main.c @@ -246,18 +246,17 @@ Sys_ANSIColorify Transform Q3 colour codes to ANSI escape sequences ================= */ -static void Sys_ANSIColorify( const char *msg, char *buffer, int bufferSize ) +//XXX: function should behave like others that colorize strings +static void Sys_ANSIColorify( const char *msg, char *buffer, unsigned bufferSize ) { - int msgLength, pos; + int msgLength; int i, j; char *escapeCode; - char tempBuffer[ 7 ]; if( !msg || !buffer ) return; msgLength = strlen( msg ); - pos = 0; i = 0; buffer[ 0 ] = '\0'; @@ -265,8 +264,11 @@ static void Sys_ANSIColorify( const char *msg, char *buffer, int bufferSize ) { if( msg[ i ] == '\n' ) { - Com_sprintf( tempBuffer, 7, "%c[0m\n", 0x1B ); - strncat( buffer, tempBuffer, bufferSize ); + unsigned len = 4; + if(bufferSize <= len) goto out; + strcpy( buffer, "\x1b[m\n"); + buffer += len; + bufferSize -= len; i++; } else if( msg[ i ] == Q_COLOR_ESCAPE ) @@ -276,6 +278,7 @@ static void Sys_ANSIColorify( const char *msg, char *buffer, int bufferSize ) if( i < msgLength ) { escapeCode = NULL; + // XXX: no need for that loop for( j = 0; j < CON_colorTableSize; j++ ) { if( msg[ i ] == CON_colorTable[ j ].Q3color ) @@ -287,8 +290,11 @@ static void Sys_ANSIColorify( const char *msg, char *buffer, int bufferSize ) if( escapeCode ) { - Com_sprintf( tempBuffer, 7, "%c[%sm", 0x1B, escapeCode ); - strncat( buffer, tempBuffer, bufferSize ); + unsigned len = 3 + strlen(escapeCode); + if(bufferSize <= len) goto out; + Com_sprintf( buffer, len+1, "\x1b[%sm", escapeCode ); + buffer += len; + bufferSize -= len; } i++; @@ -296,10 +302,14 @@ static void Sys_ANSIColorify( const char *msg, char *buffer, int bufferSize ) } else { - Com_sprintf( tempBuffer, 7, "%c", msg[ i++ ] ); - strncat( buffer, tempBuffer, bufferSize ); + if(bufferSize <= 1) goto out; + *buffer++ = msg[ i++ ]; + *buffer = 0; + --bufferSize; } } +out: + return; } /* |