From 116a605248a08e97e97213a97a6046364e5d0fe6 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:08:36 +0300 Subject: [PATCH] engine: common: replace some obvious va uses by temp buffer and Q_snprintf or equivalent code --- engine/common/con_utils.c | 8 ++++++-- engine/common/cvar.c | 9 +++++---- engine/common/host.c | 10 ++++++---- engine/common/mod_bmodel.c | 6 +++++- engine/common/mod_sprite.c | 4 +++- engine/common/mod_studio.c | 5 ++++- engine/common/net_ws.c | 6 +++++- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 3aed173f..9ebd9be3 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -1041,10 +1041,14 @@ compare first argument with string */ static qboolean Cmd_CheckName( const char *name ) { - if( !Q_stricmp( Cmd_Argv( 0 ), name )) + char *p = Cmd_Argv( 0 ); + + if( !Q_stricmp( p, name )) return true; - if( !Q_stricmp( Cmd_Argv( 0 ), va( "\\%s", name ))) + + if( p[0] == '\\' && !Q_stricmp( &p[1], name )) return true; + return false; } diff --git a/engine/common/cvar.c b/engine/common/cvar.c index a38cc2f4..316119e3 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -1080,7 +1080,7 @@ void Cvar_Toggle_f( void ) v = !Cvar_VariableInteger( Cmd_Argv( 1 )); - Cvar_Set( Cmd_Argv( 1 ), va( "%i", v )); + Cvar_Set( Cmd_Argv( 1 ), v ? "1" : "0" ); } /* @@ -1162,7 +1162,6 @@ void Cvar_List_f( void ) { convar_t *var; const char *match = NULL; - char *value; int count = 0; size_t matchlen = 0; @@ -1174,6 +1173,8 @@ void Cvar_List_f( void ) for( var = cvar_vars; var; var = var->next ) { + char value[MAX_VA_STRING]; + if( var->name[0] == '@' ) continue; // never shows system cvars @@ -1181,8 +1182,8 @@ void Cvar_List_f( void ) continue; if( Q_colorstr( var->string )) - value = va( "\"%s\"", var->string ); - else value = va( "\"^2%s^7\"", var->string ); + Q_snprintf( value, sizeof( value ), "\"%s\"", var->string ); + else Q_snprintf( value, sizeof( value ), "\"^2%s^7\"", var->string ); if( FBitSet( var->flags, FCVAR_EXTENDED|FCVAR_ALLOCATED )) Con_Printf( " %-*s %s ^3%s^7\n", 32, var->name, value, var->desc ); diff --git a/engine/common/host.c b/engine/common/host.c index 73b367df..d472d9f5 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -346,10 +346,10 @@ void Host_ChangeGame_f( void ) } else { - const char *arg1 = va( "%s", Cmd_Argv( 1 )); - const char *arg2 = va( "change game to '%s'", FI->games[i]->title ); + char finalmsg[MAX_VA_STRING]; - Host_NewInstance( arg1, arg2 ); + Q_snprintf( finalmsg, sizeof( finalmsg ), "change game to '%s'", FI->games[i]->title ); + Host_NewInstance( Cmd_Argv( 1 ), finalmsg ); } } @@ -384,9 +384,11 @@ void Host_Exec_f( void ) "pyro.cfg", "spy.cfg", "engineer.cfg", "civilian.cfg" }; int i; + char temp[MAX_VA_STRING]; qboolean allow = false; - unprivilegedWhitelist[0] = va( "%s.cfg", clgame.mapname ); + Q_snprintf( temp, sizeof( temp ), "%s.cfg", clgame.mapname ); + unprivilegedWhitelist[0] = temp; for( i = 0; i < ARRAYSIZE( unprivilegedWhitelist ); i++ ) { diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 8d2c0be3..fd3236b7 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -3019,9 +3019,13 @@ Mod_LoadBrushModel */ void Mod_LoadBrushModel( model_t *mod, const void *buffer, qboolean *loaded ) { + char poolname[MAX_VA_STRING]; + + Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name ); + if( loaded ) *loaded = false; - loadmodel->mempool = Mem_AllocPool( va( "^2%s^7", loadmodel->name )); + loadmodel->mempool = Mem_AllocPool( poolname ); loadmodel->type = mod_brush; // loading all the lumps into heap diff --git a/engine/common/mod_sprite.c b/engine/common/mod_sprite.c index 5cc31827..f76774ae 100644 --- a/engine/common/mod_sprite.c +++ b/engine/common/mod_sprite.c @@ -35,6 +35,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui dsprite_hl_t *pinhl; dsprite_t *pin; msprite_t *psprite; + char poolname[MAX_VA_STRING]; int i, size; if( loaded ) *loaded = false; @@ -54,7 +55,8 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui return; } - mod->mempool = Mem_AllocPool( va( "^2%s^7", mod->name )); + Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name ); + mod->mempool = Mem_AllocPool( poolname ); if( i == SPRITE_VERSION_Q1 || i == SPRITE_VERSION_32 ) { diff --git a/engine/common/mod_studio.c b/engine/common/mod_studio.c index 504ff415..77a0832c 100644 --- a/engine/common/mod_studio.c +++ b/engine/common/mod_studio.c @@ -848,10 +848,13 @@ Mod_LoadStudioModel */ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ) { + char poolname[MAX_VA_STRING]; studiohdr_t *phdr; + Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name ); + if( loaded ) *loaded = false; - loadmodel->mempool = Mem_AllocPool( va( "^2%s^7", loadmodel->name )); + loadmodel->mempool = Mem_AllocPool( poolname ); loadmodel->type = mod_studio; phdr = R_StudioLoadHeader( mod, buffer ); diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index 5a93cd38..b2ea7d38 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -2639,10 +2639,14 @@ void HTTP_Run( void ) if( curfile->state < HTTP_NS_RESOLVED ) { + char hostport[MAX_VA_STRING]; + if( fResolving ) continue; - res = NET_StringToSockaddr( va( "%s:%d", curfile->server->host, curfile->server->port ), &addr, true, AF_INET ); + Q_snprintf( hostport, sizeof( hostport ), "%s:%d", curfile->server->host, curfile->server->port ); + + res = NET_StringToSockaddr( hostport, &addr, true, AF_INET ); if( res == 2 ) {