Browse Source

public: remove Q_vsprintf, replace by proper Q_vsnprintf proper calls

Fixes weird off by one error caused by glibc updates? I didn't tracked
what causes it exactly but replacing it seems to work. Anyway, we should
remove all 99999 hacks in libpublic.
pull/2/head
Alibek Omarov 2 years ago
parent
commit
096ee34f67
  1. 2
      engine/client/cl_main.c
  2. 2
      engine/common/host.c
  3. 6
      engine/server/sv_cmds.c
  4. 2
      filesystem/filesystem.c
  5. 1
      public/crtlib.h
  6. 2
      ref/gl/gl_backend.c

2
engine/client/cl_main.c

@ -2583,7 +2583,7 @@ void CL_ServerCommand( qboolean reliable, const char *fmt, ... )
return; return;
va_start( argptr, fmt ); va_start( argptr, fmt );
Q_vsprintf( string, fmt, argptr ); Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr ); va_end( argptr );
if( reliable ) if( reliable )

2
engine/common/host.c

@ -733,7 +733,7 @@ void GAME_EXPORT Host_Error( const char *error, ... )
va_list argptr; va_list argptr;
va_start( argptr, error ); va_start( argptr, error );
Q_vsprintf( hosterror1, error, argptr ); Q_vsnprintf( hosterror1, sizeof( hosterror1 ), error, argptr );
va_end( argptr ); va_end( argptr );
CL_WriteMessageHistory (); // before Q_error call CL_WriteMessageHistory (); // before Q_error call

6
engine/server/sv_cmds.c

@ -34,7 +34,7 @@ void SV_ClientPrintf( sv_client_t *cl, const char *fmt, ... )
return; return;
va_start( argptr, fmt ); va_start( argptr, fmt );
Q_vsprintf( string, fmt, argptr ); Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr ); va_end( argptr );
MSG_BeginServerCmd( &cl->netchan.message, svc_print ); MSG_BeginServerCmd( &cl->netchan.message, svc_print );
@ -56,7 +56,7 @@ void SV_BroadcastPrintf( sv_client_t *ignore, const char *fmt, ... )
int i; int i;
va_start( argptr, fmt ); va_start( argptr, fmt );
Q_vsprintf( string, fmt, argptr ); Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr ); va_end( argptr );
if( sv.state == ss_active ) if( sv.state == ss_active )
@ -97,7 +97,7 @@ void SV_BroadcastCommand( const char *fmt, ... )
return; return;
va_start( argptr, fmt ); va_start( argptr, fmt );
Q_vsprintf( string, fmt, argptr ); Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr ); va_end( argptr );
MSG_BeginServerCmd( &sv.reliable_datagram, svc_stufftext ); MSG_BeginServerCmd( &sv.reliable_datagram, svc_stufftext );

2
filesystem/filesystem.c

@ -2064,7 +2064,7 @@ int FS_VPrintf( file_t *file, const char *format, va_list ap )
while( 1 ) while( 1 )
{ {
tempbuff = (char *)Mem_Malloc( fs_mempool, buff_size ); tempbuff = (char *)Mem_Malloc( fs_mempool, buff_size );
len = Q_vsprintf( tempbuff, format, ap ); len = Q_vsnprintf( tempbuff, buff_size, format, ap );
if( len >= 0 && len < buff_size ) if( len >= 0 && len < buff_size )
break; break;

1
public/crtlib.h

@ -80,7 +80,6 @@ qboolean Q_stricmpext( const char *pattern, const char *text );
qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlen ); qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlen );
const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen ); const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen );
const char *Q_timestamp( int format ); const char *Q_timestamp( int format );
#define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args )
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args ); int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args );
int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format( 3 ); int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format( 3 );
int Q_sprintf( char *buffer, const char *format, ... ) _format( 2 ); int Q_sprintf( char *buffer, const char *format, ... ) _format( 2 );

2
ref/gl/gl_backend.c

@ -55,7 +55,7 @@ void R_Speeds_Printf( const char *msg, ... )
char text[2048]; char text[2048];
va_start( argptr, msg ); va_start( argptr, msg );
Q_vsprintf( text, msg, argptr ); Q_vsnprintf( text, sizeof( text ), msg, argptr );
va_end( argptr ); va_end( argptr );
Q_strncat( r_speeds_msg, text, sizeof( r_speeds_msg )); Q_strncat( r_speeds_msg, text, sizeof( r_speeds_msg ));

Loading…
Cancel
Save