From ec2951cf454c665f45533a0db3c53d5b12e27063 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 26 Apr 2023 04:57:28 +0300 Subject: [PATCH] engine: add size argument to COM_Default/ReplaceExtension calls --- engine/client/avi/avi_win.c | 2 +- engine/client/cl_gameui.c | 2 +- engine/common/con_utils.c | 6 ++---- engine/common/host.c | 2 +- engine/common/hpak.c | 26 +++++++++++++------------- engine/common/mod_bmodel.c | 2 +- engine/common/net_chan.c | 4 ++-- engine/platform/sdl/vid_sdl.c | 5 ++--- engine/server/sv_init.c | 2 +- 9 files changed, 24 insertions(+), 27 deletions(-) diff --git a/engine/client/avi/avi_win.c b/engine/client/avi/avi_win.c index ed1e5ba2..128fe62f 100644 --- a/engine/client/avi/avi_win.c +++ b/engine/client/avi/avi_win.c @@ -658,7 +658,7 @@ movie_state_t *AVI_LoadVideo( const char *filename, qboolean load_audio ) // open cinematic Q_snprintf( path, sizeof( path ), "media/%s", filename ); - COM_DefaultExtension( path, ".avi" ); + COM_DefaultExtension( path, ".avi", sizeof( path )); fullpath = FS_GetDiskPath( path, false ); if( FS_FileExists( path, false ) && !fullpath ) diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index c74932fb..1d3af7ff 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -309,7 +309,7 @@ static void GAME_EXPORT UI_DrawLogo( const char *filename, float x, float y, flo // run cinematic if not Q_snprintf( path, sizeof( path ), "media/%s", filename ); - COM_DefaultExtension( path, ".avi" ); + COM_DefaultExtension( path, ".avi", sizeof( path )); fullpath = FS_GetDiskPath( path, false ); if( FS_FileExists( path, false ) && !fullpath ) diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 71995d68..126a289d 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -101,8 +101,7 @@ int Cmd_ListMaps( search_t *t, char *lastmapname, size_t len ) if( hdrext->id == IDEXTRAHEADER ) version = hdrext->version; Q_strncpy( entfilename, t->filenames[i], sizeof( entfilename )); - COM_StripExtension( entfilename ); - COM_DefaultExtension( entfilename, ".ent" ); + COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename )); ents = (char *)FS_LoadFile( entfilename, NULL, true ); if( !ents && lumplen >= 10 ) @@ -925,8 +924,7 @@ qboolean Cmd_CheckMapsList_R( qboolean fRefresh, qboolean onlyingamedir ) lumplen = entities.filelen; Q_strncpy( entfilename, t->filenames[i], sizeof( entfilename )); - COM_StripExtension( entfilename ); - COM_DefaultExtension( entfilename, ".ent" ); + COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename )); ents = (char *)FS_LoadFile( entfilename, NULL, true ); if( !ents && lumplen >= 10 ) diff --git a/engine/common/host.c b/engine/common/host.c index d952ddea..ddf488d5 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -415,7 +415,7 @@ void Host_Exec_f( void ) } Q_strncpy( cfgpath, arg, sizeof( cfgpath )); - COM_DefaultExtension( cfgpath, ".cfg" ); // append as default + COM_DefaultExtension( cfgpath, ".cfg", sizeof( cfgpath )); // append as default f = FS_LoadFile( cfgpath, &len, false ); if( !f ) diff --git a/engine/common/hpak.c b/engine/common/hpak.c index 2553f4c5..f7d882d2 100644 --- a/engine/common/hpak.c +++ b/engine/common/hpak.c @@ -109,7 +109,7 @@ void HPAK_CreatePak( const char *filename, resource_t *pResource, byte *pData, f return; Q_strncpy( pakname, filename, sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); Con_Printf( "creating HPAK %s.\n", pakname ); @@ -257,7 +257,7 @@ void HPAK_AddLump( qboolean bUseQueue, const char *name, resource_t *pResource, } Q_strncpy( srcname, name, sizeof( srcname )); - COM_ReplaceExtension( srcname, ".hpk" ); + COM_ReplaceExtension( srcname, ".hpk", sizeof( srcname )); file_src = FS_Open( srcname, "rb", true ); @@ -269,7 +269,7 @@ void HPAK_AddLump( qboolean bUseQueue, const char *name, resource_t *pResource, } Q_strncpy( dstname, srcname, sizeof( dstname )); - COM_ReplaceExtension( dstname, ".hp2" ); + COM_ReplaceExtension( dstname, ".hp2", sizeof( dstname )); file_dst = FS_Open( dstname, "wb", true ); @@ -395,7 +395,7 @@ static qboolean HPAK_Validate( const char *filename, qboolean quiet, qboolean de return true; Q_strncpy( pakname, filename, sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); f = FS_Open( pakname, "rb", true ); if( !f ) @@ -497,7 +497,7 @@ void HPAK_CheckIntegrity( const char *filename ) return; Q_strncpy( pakname, filename, sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); HPAK_Validate( pakname, true, true ); } @@ -514,7 +514,7 @@ void HPAK_CheckSize( const char *filename ) return; Q_strncpy( pakname, filename, sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); if( FS_FileSize( pakname, false ) > ( maxsize * 1048576 )) { @@ -547,7 +547,7 @@ qboolean HPAK_ResourceForHash( const char *filename, byte *hash, resource_t *pRe } Q_strncpy( pakname, filename, sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); f = FS_Open( pakname, "rb", true ); if( !f ) return false; @@ -595,7 +595,7 @@ static qboolean HPAK_ResourceForIndex( const char *filename, int index, resource return false; Q_strncpy( pakname, filename, sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); f = FS_Open( pakname, "rb", true ); if( !f ) @@ -681,7 +681,7 @@ qboolean HPAK_GetDataPointer( const char *filename, resource_t *pResource, byte } Q_strncpy( pakname, filename, sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); f = FS_Open( pakname, "rb", true ); if( !f ) return false; @@ -764,7 +764,7 @@ void HPAK_RemoveLump( const char *name, resource_t *pResource ) HPAK_FlushHostQueue(); Q_strncpy( read_path, name, sizeof( read_path )); - COM_ReplaceExtension( read_path, ".hpk" ); + COM_ReplaceExtension( read_path, ".hpk", sizeof( read_path )); file_src = FS_Open( read_path, "rb", true ); if( !file_src ) @@ -774,7 +774,7 @@ void HPAK_RemoveLump( const char *name, resource_t *pResource ) } Q_strncpy( save_path, read_path, sizeof( save_path )); - COM_ReplaceExtension( save_path, ".hp2" ); + COM_ReplaceExtension( save_path, ".hp2", sizeof( save_path )); file_dst = FS_Open( save_path, "wb", true ); if( !file_dst ) @@ -893,7 +893,7 @@ void HPAK_List_f( void ) HPAK_FlushHostQueue(); Q_strncpy( pakname, Cmd_Argv( 1 ), sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); Con_Printf( "Contents for %s.\n", pakname ); f = FS_Open( pakname, "rb", true ); @@ -984,7 +984,7 @@ void HPAK_Extract_f( void ) HPAK_FlushHostQueue(); Q_strncpy( pakname, Cmd_Argv( 1 ), sizeof( pakname )); - COM_ReplaceExtension( pakname, ".hpk" ); + COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); Con_Printf( "Contents for %s.\n", pakname ); f = FS_Open( pakname, "rb", true ); diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index f2a1b466..8c63462c 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -1764,7 +1764,7 @@ static void Mod_LoadEntities( dbspmodel_t *bmod ) // world is check for entfile too Q_strncpy( entfilename, loadmodel->name, sizeof( entfilename )); - COM_ReplaceExtension( entfilename, ".ent" ); + COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename )); // make sure what entity patch is never than bsp ft1 = FS_FileTime( loadmodel->name, false ); diff --git a/engine/common/net_chan.c b/engine/common/net_chan.c index 9e4a06a2..aec27f75 100644 --- a/engine/common/net_chan.c +++ b/engine/common/net_chan.c @@ -973,7 +973,7 @@ int Netchan_CreateFileFragments( netchan_t *chan, const char *filename ) else chunksize = FRAGMENT_MAX_SIZE; // fallback Q_strncpy( compressedfilename, filename, sizeof( compressedfilename )); - COM_ReplaceExtension( compressedfilename, ".ztmp" ); + COM_ReplaceExtension( compressedfilename, ".ztmp", sizeof( compressedfilename )); compressedFileTime = FS_FileTime( compressedfilename, false ); fileTime = FS_FileTime( filename, false ); @@ -1559,7 +1559,7 @@ void Netchan_TransmitBits( netchan_t *chan, int length, byte *data ) char compressedfilename[MAX_OSPATH]; Q_strncpy( compressedfilename, pbuf->filename, sizeof( compressedfilename )); - COM_ReplaceExtension( compressedfilename, ".ztmp" ); + COM_ReplaceExtension( compressedfilename, ".ztmp", sizeof( compressedfilename )); file = FS_Open( compressedfilename, "rb", false ); } else file = FS_Open( pbuf->filename, "rb", false ); diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index cf0d697f..b791cc6c 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -736,9 +736,8 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) if( !iconLoaded ) { - Q_strcpy( iconpath, GI->iconpath ); - COM_StripExtension( iconpath ); - COM_DefaultExtension( iconpath, ".tga" ); + Q_strncpy( iconpath, GI->iconpath, sizeof( iconpath )); + COM_ReplaceExtension( iconpath, ".tga", sizeof( iconpath )); icon = FS_LoadImage( iconpath, NULL, 0 ); diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 12e07a61..a5391168 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -340,7 +340,7 @@ void SV_CreateGenericResources( void ) string filename; Q_strncpy( filename, sv.model_precache[1], sizeof( filename )); - COM_ReplaceExtension( filename, ".res" ); + COM_ReplaceExtension( filename, ".res", sizeof( filename )); COM_FixSlashes( filename ); SV_ReadResourceList( filename );