diff --git a/engine/common/net_buffer.c b/engine/common/net_buffer.c index 7e79695a..6526c386 100644 --- a/engine/common/net_buffer.c +++ b/engine/common/net_buffer.c @@ -395,15 +395,11 @@ qboolean MSG_WriteBytes( sizebuf_t *sb, const void *pBuf, int nBytes ) qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr ) { - if( pStr ) - { - do - { - MSG_WriteChar( sb, (signed char)*pStr ); - pStr++; - } while( *( pStr - 1 )); - } - else MSG_WriteChar( sb, 0 ); + int len = Q_strlen( pStr ); + + if( len ) + MSG_WriteBytes( sb, pStr, len + 1 ); + else MSG_WriteByte( sb, 0 ); return !sb->bOverflow; } @@ -411,13 +407,22 @@ qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr ) qboolean MSG_WriteStringf( sizebuf_t *sb, const char *format, ... ) { va_list va; + int len; char buf[MAX_VA_STRING]; va_start( va, format ); - Q_vsnprintf( buf, sizeof( buf ), format, va ); + len = Q_vsnprintf( buf, sizeof( buf ), format, va ); va_end( va ); - return MSG_WriteString( sb, buf ); + if( len < 0 ) + { + Host_Error( "%s: snprintf overflow!\n", __func__ ); + return false; + } + + MSG_WriteBytes( sb, buf, len + 1 ); + + return !sb->bOverflow; } int MSG_ReadOneBit( sizebuf_t *sb ) @@ -629,9 +634,7 @@ float MSG_ReadFloat( sizebuf_t *sb ) { float ret; - Assert( sizeof( ret ) == 4 ); - - MSG_ReadBits( sb, &ret, 32 ); + MSG_ReadBits( sb, &ret, sizeof( ret ) << 3 ); return ret; }