From 8c7db8499fd193c859755905043ae9e37d739782 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 26 Apr 2023 04:04:48 +0300 Subject: [PATCH] engine: add size argument to COM_FileBase calls --- engine/client/cl_parse.c | 2 +- engine/client/cl_remap.c | 2 +- engine/client/in_touch.c | 2 +- engine/common/con_utils.c | 34 +++++++++++++++++----------------- engine/common/crashhandler.c | 6 ++++-- engine/common/host.c | 2 +- engine/common/hpak.c | 4 ++-- engine/common/mod_bmodel.c | 6 +++--- engine/common/mod_studio.c | 2 +- engine/server/sv_cmds.c | 4 ++-- engine/server/sv_init.c | 2 +- 11 files changed, 34 insertions(+), 32 deletions(-) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 8b6dbd3f..bc507838 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -2007,7 +2007,7 @@ void CL_ParseExec( sizebuf_t *msg ) { Cbuf_AddText( "exec mapdefault.cfg\n" ); - COM_FileBase( clgame.mapname, mapname ); + COM_FileBase( clgame.mapname, mapname, sizeof( mapname )); if ( COM_CheckString( mapname ) ) Cbuf_AddTextf( "exec %s.cfg\n", mapname ); diff --git a/engine/client/cl_remap.c b/engine/client/cl_remap.c index 3a9c74c8..07beb67e 100644 --- a/engine/client/cl_remap.c +++ b/engine/client/cl_remap.c @@ -157,7 +157,7 @@ void CL_UpdateStudioTexture( cl_entity_t *entity, mstudiotexture_t *ptexture, in // build name of original texture Q_strncpy( mdlname, entity->model->name, sizeof( mdlname )); - COM_FileBase( ptexture->name, name ); + COM_FileBase( ptexture->name, name, sizeof( name )); COM_StripExtension( mdlname ); Q_snprintf( texname, sizeof( texname ), "#%s/%s.mdl", mdlname, name ); diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index 198c443b..490b49a1 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -340,7 +340,7 @@ static void Touch_ExportConfig_f( void ) if( Q_strstr( name, "touch_presets/" )) { - COM_FileBase( name, profilebase ); + COM_FileBase( name, profilebase, sizeof( profilebase )); Q_snprintf( profilename, sizeof( profilebase ), "touch_profiles/%s (copy).cfg", profilebase ); } else Q_strncpy( profilename, name, sizeof( profilename )); diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 87725c93..71995d68 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -146,7 +146,7 @@ int Cmd_ListMaps( search_t *t, char *lastmapname, size_t len ) } if( f ) FS_Close(f); - COM_FileBase( t->filenames[i], mapname ); + COM_FileBase( t->filenames[i], mapname, sizeof( mapname )); switch( ver ) { @@ -194,7 +194,7 @@ qboolean Cmd_GetMapList( const char *s, char *completedname, int length ) t = FS_Search( va( "maps/%s*.bsp", s ), true, con_gamemaps->value ); if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -231,7 +231,7 @@ qboolean Cmd_GetDemoList( const char *s, char *completedname, int length ) t = FS_Search( va( "%s*.dem", s ), true, true ); if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -241,7 +241,7 @@ qboolean Cmd_GetDemoList( const char *s, char *completedname, int length ) if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "dem" )) continue; - COM_FileBase( t->filenames[i], matchbuf ); + COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); numdems++; } @@ -277,7 +277,7 @@ qboolean Cmd_GetMovieList( const char *s, char *completedname, int length ) t = FS_Search( va( "media/%s*.avi", s ), true, false ); if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -287,7 +287,7 @@ qboolean Cmd_GetMovieList( const char *s, char *completedname, int length ) if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "avi" )) continue; - COM_FileBase( t->filenames[i], matchbuf ); + COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); nummovies++; } @@ -324,7 +324,7 @@ qboolean Cmd_GetMusicList( const char *s, char *completedname, int length ) t = FS_Search( va( "media/%s*.*", s ), true, false ); if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -336,7 +336,7 @@ qboolean Cmd_GetMusicList( const char *s, char *completedname, int length ) if( Q_stricmp( ext, "wav" ) && Q_stricmp( ext, "mp3" )) continue; - COM_FileBase( t->filenames[i], matchbuf ); + COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); numtracks++; } @@ -372,7 +372,7 @@ qboolean Cmd_GetSavesList( const char *s, char *completedname, int length ) t = FS_Search( va( DEFAULT_SAVE_DIRECTORY "%s*.sav", s ), true, true ); // lookup only in gamedir if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -382,7 +382,7 @@ qboolean Cmd_GetSavesList( const char *s, char *completedname, int length ) if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "sav" )) continue; - COM_FileBase( t->filenames[i], matchbuf ); + COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); numsaves++; } @@ -419,7 +419,7 @@ qboolean Cmd_GetConfigList( const char *s, char *completedname, int length ) t = FS_Search( va( "%s*.cfg", s ), true, false ); if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -429,7 +429,7 @@ qboolean Cmd_GetConfigList( const char *s, char *completedname, int length ) if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "cfg" )) continue; - COM_FileBase( t->filenames[i], matchbuf ); + COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); numconfigs++; } @@ -519,7 +519,7 @@ qboolean Cmd_GetItemsList( const char *s, char *completedname, int length ) t = FS_Search( va( "%s/%s*.txt", clgame.itemspath, s ), true, false ); if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -529,7 +529,7 @@ qboolean Cmd_GetItemsList( const char *s, char *completedname, int length ) if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "txt" )) continue; - COM_FileBase( t->filenames[i], matchbuf ); + COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); numitems++; } @@ -711,7 +711,7 @@ qboolean Cmd_GetCustomList( const char *s, char *completedname, int length ) t = FS_Search( va( "%s*.hpk", s ), true, false ); if( !t ) return false; - COM_FileBase( t->filenames[0], matchbuf ); + COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( t->numfilenames == 1 ) return true; @@ -721,7 +721,7 @@ qboolean Cmd_GetCustomList( const char *s, char *completedname, int length ) if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "hpk" )) continue; - COM_FileBase( t->filenames[i], matchbuf ); + COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); numitems++; } @@ -901,7 +901,7 @@ qboolean Cmd_CheckMapsList_R( qboolean fRefresh, qboolean onlyingamedir ) continue; f = FS_Open( t->filenames[i], "rb", onlyingamedir ); - COM_FileBase( t->filenames[i], mapname ); + COM_FileBase( t->filenames[i], mapname, sizeof( mapname )); if( f ) { diff --git a/engine/common/crashhandler.c b/engine/common/crashhandler.c index 3f12abaa..cc94c5a3 100644 --- a/engine/common/crashhandler.c +++ b/engine/common/crashhandler.c @@ -193,8 +193,10 @@ static void Sys_StackTrace( PEXCEPTION_POINTERS pInfo ) static void Sys_GetProcessName( char *processName, size_t bufferSize ) { - GetModuleBaseName( GetCurrentProcess(), NULL, processName, bufferSize - 1 ); - COM_FileBase( processName, processName ); + char fullpath[MAX_PATH]; + + GetModuleBaseName( GetCurrentProcess(), NULL, fullpath, sizeof( fullpath ) - 1 ); + COM_FileBase( fullpath, processName, bufferSize ); } static void Sys_GetMinidumpFileName( const char *processName, char *mdmpFileName, size_t bufferSize ) diff --git a/engine/common/host.c b/engine/common/host.c index 46b88de5..d952ddea 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -509,7 +509,7 @@ qboolean Host_RegisterDecal( const char *name, int *count ) if( !COM_CheckString( name )) return 0; - COM_FileBase( name, shortname ); + COM_FileBase( name, shortname, sizeof( shortname )); for( i = 1; i < MAX_DECALS && host.draw_decals[i][0]; i++ ) { diff --git a/engine/common/hpak.c b/engine/common/hpak.c index 0886470f..2553f4c5 100644 --- a/engine/common/hpak.c +++ b/engine/common/hpak.c @@ -938,7 +938,7 @@ void HPAK_List_f( void ) for( nCurrent = 0; nCurrent < directory.count; nCurrent++ ) { entry = &directory.entries[nCurrent]; - COM_FileBase( entry->resource.szFileName, lumpname ); + COM_FileBase( entry->resource.szFileName, lumpname, sizeof( lumpname )); type = HPAK_TypeFromIndex( entry->resource.type ); size = Q_memprint( entry->resource.nDownloadSize ); @@ -1033,7 +1033,7 @@ void HPAK_Extract_f( void ) if( nIndex != -1 && nIndex != nCurrent ) continue; - COM_FileBase( entry->resource.szFileName, lumpname ); + COM_FileBase( entry->resource.szFileName, lumpname, sizeof( lumpname ) ); type = HPAK_TypeFromIndex( entry->resource.type ); size = Q_memprint( entry->resource.nDownloadSize ); diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index cb9c087c..f2a1b466 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -1483,7 +1483,7 @@ static qboolean Mod_LoadColoredLighting( dbspmodel_t *bmod ) fs_offset_t litdatasize; byte *in; - COM_FileBase( loadmodel->name, modelname ); + COM_FileBase( loadmodel->name, modelname, sizeof( modelname )); Q_snprintf( path, sizeof( path ), "maps/%s.lit", modelname ); // make sure what deluxemap is actual @@ -1538,7 +1538,7 @@ static void Mod_LoadDeluxemap( dbspmodel_t *bmod ) if( !FBitSet( host.features, ENGINE_LOAD_DELUXEDATA )) return; - COM_FileBase( loadmodel->name, modelname ); + COM_FileBase( loadmodel->name, modelname, sizeof( modelname )); Q_snprintf( path, sizeof( path ), "maps/%s.dlit", modelname ); // make sure what deluxemap is actual @@ -1833,7 +1833,7 @@ static void Mod_LoadEntities( dbspmodel_t *bmod ) for( pszWadFile = strtok( wadstring, ";" ); pszWadFile != NULL; pszWadFile = strtok( NULL, ";" )) { COM_FixSlashes( pszWadFile ); - COM_FileBase( pszWadFile, token ); + COM_FileBase( pszWadFile, token, sizeof( token )); // make sure what wad is really exist if( FS_FileExists( va( "%s.wad", token ), false )) diff --git a/engine/common/mod_studio.c b/engine/common/mod_studio.c index 77a0832c..4886fd33 100644 --- a/engine/common/mod_studio.c +++ b/engine/common/mod_studio.c @@ -429,7 +429,7 @@ void *R_StudioGetAnim( studiohdr_t *m_pStudioHeader, model_t *m_pSubModel, mstud { string filepath, modelname, modelpath; - COM_FileBase( m_pSubModel->name, modelname ); + COM_FileBase( m_pSubModel->name, modelname, sizeof( modelname )); COM_ExtractFilePath( m_pSubModel->name, modelpath ); // NOTE: here we build real sub-animation filename because stupid user may rename model without recompile diff --git a/engine/server/sv_cmds.c b/engine/server/sv_cmds.c index 90c6a9d6..99c1c661 100644 --- a/engine/server/sv_cmds.c +++ b/engine/server/sv_cmds.c @@ -337,12 +337,12 @@ void SV_NextMap_f( void ) if( Q_stricmp( ext, "bsp" )) continue; - COM_FileBase( t->filenames[i], nextmap ); + COM_FileBase( t->filenames[i], nextmap, sizeof( nextmap )); if( Q_stricmp( sv_hostmap->string, nextmap )) continue; next = ( i + 1 ) % t->numfilenames; - COM_FileBase( t->filenames[next], nextmap ); + COM_FileBase( t->filenames[next], nextmap, sizeof( nextmap )); Cvar_DirectSet( sv_hostmap, nextmap ); // found current point, check for valid diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index b18565c9..12e07a61 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -973,7 +973,7 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba if( svs.maxclients == 1 ) Cvar_SetValue( "sv_clienttrace", 1 ); // make sure what server name doesn't contain path and extension - COM_FileBase( mapname, sv.name ); + COM_FileBase( mapname, sv.name, sizeof( sv.name )); // precache and static commands can be issued during map initialization Host_SetServerState( ss_loading );