Browse Source

engine: common: replace some obvious va uses by temp buffer and Q_snprintf or equivalent code

pull/2/head
Alibek Omarov 2 years ago
parent
commit
116a605248
  1. 8
      engine/common/con_utils.c
  2. 9
      engine/common/cvar.c
  3. 10
      engine/common/host.c
  4. 6
      engine/common/mod_bmodel.c
  5. 4
      engine/common/mod_sprite.c
  6. 5
      engine/common/mod_studio.c
  7. 6
      engine/common/net_ws.c

8
engine/common/con_utils.c

@ -1041,10 +1041,14 @@ compare first argument with string @@ -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;
}

9
engine/common/cvar.c

@ -1080,7 +1080,7 @@ void Cvar_Toggle_f( void ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 );

10
engine/common/host.c

@ -346,10 +346,10 @@ void Host_ChangeGame_f( void ) @@ -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 ) @@ -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++ )
{

6
engine/common/mod_bmodel.c

@ -3019,9 +3019,13 @@ Mod_LoadBrushModel @@ -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

4
engine/common/mod_sprite.c

@ -35,6 +35,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui @@ -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 @@ -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 )
{

5
engine/common/mod_studio.c

@ -848,10 +848,13 @@ Mod_LoadStudioModel @@ -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 );

6
engine/common/net_ws.c

@ -2639,10 +2639,14 @@ void HTTP_Run( void ) @@ -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 )
{

Loading…
Cancel
Save