diff --git a/filesystem/VFileSystem009.cpp b/filesystem/VFileSystem009.cpp index e9a3d54a..0974832d 100644 --- a/filesystem/VFileSystem009.cpp +++ b/filesystem/VFileSystem009.cpp @@ -42,12 +42,15 @@ static inline qboolean IsIdGamedir( const char *id ) !Q_strcmp( id, "GAMEDOWNLOAD" ); } -static inline const char *IdToDir( const char *id ) +static inline const char *IdToDir( char *dir, size_t size, const char *id ) { if( !Q_strcmp( id, "GAME" )) return GI->gamefolder; else if( !Q_strcmp( id, "GAMEDOWNLOAD" )) - return va( "%s/downloaded", GI->gamefolder ); + { + Q_snprintf( dir, size, "%s/downloaded", GI->gamefolder ); + return dir; + } else if( !Q_strcmp( id, "GAMECONFIG" )) return fs_writepath->filename; // full path here so it's totally our write allowed directory else if( !Q_strcmp( id, "PLATFORM" )) @@ -145,7 +148,10 @@ public: void CreateDirHierarchy( const char *path, const char *id ) override { - FS_CreatePath( va( "%s/%s", IdToDir( id ), path )); // FS_CreatePath is aware of slashes + char dir[MAX_VA_STRING], fullpath[MAX_VA_STRING]; + + Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", IdToDir( dir, sizeof( dir ), id ), path ); + FS_CreatePath( fullpath ); // FS_CreatePath is aware of slashes } bool FileExists( const char *path ) override @@ -365,7 +371,6 @@ public: return buf; } - const char *fullpath = FS_GetDiskPath( p, false ); if( !fullpath ) return NULL; @@ -449,10 +454,12 @@ public: bool AddPackFile( const char *path, const char *id ) override { - char *p = va( "%s/%s", IdToDir( id ), path ); - CopyAndFixSlashes( p, path ); + char dir[MAX_VA_STRING], fullpath[MAX_VA_STRING]; + + Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", IdToDir( dir, sizeof( dir ), id ), path ); + CopyAndFixSlashes( fullpath, path ); - return !!FS_AddPak_Fullpath( p, NULL, FS_CUSTOM_PATH ); + return !!FS_AddPak_Fullpath( fullpath, NULL, FS_CUSTOM_PATH ); } FileHandle_t OpenFromCacheForRead( const char *path , const char *mode, const char *id ) override diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 805bcf11..e09c3f1a 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -819,7 +819,8 @@ void FS_ParseGenericGameInfo( gameinfo_t *GameInfo, const char *buf, const qbool } // make sure what gamedir is really exist - if( !FS_SysFolderExists( va( "%s/%s", fs_rootdir, GameInfo->falldir ))) + Q_snprintf( token, sizeof( token ), "%s/%s", fs_rootdir, GameInfo->falldir ); + if( !FS_SysFolderExists( token )) GameInfo->falldir[0] = '\0'; } @@ -911,16 +912,21 @@ FS_CheckForGameDir */ static qboolean FS_CheckForGameDir( const char *gamedir ) { + char buf[MAX_VA_STRING]; + // if directory contain config.cfg it's 100% gamedir - if( FS_FileExists( va( "%s/config.cfg", gamedir ), false )) + Q_snprintf( buf, sizeof( buf ), "%s/config.cfg", gamedir ); + if( FS_FileExists( buf, false )) return true; // if directory contain progs.dat it's 100% gamedir - if( FS_FileExists( va( "%s/progs.dat", gamedir ), false )) + Q_snprintf( buf, sizeof( buf ), "%s/progs.dat", gamedir ); + if( FS_FileExists( buf, false )) return true; // quake mods probably always archived but can missed config.cfg before first running - if( FS_FileExists( va( "%s/pak0.pak", gamedir ), false )) + Q_snprintf( buf, sizeof( buf ), "%s/pak0.pak", gamedir ); + if( FS_FileExists( buf, false )) return true; // NOTE; adds here some additional checks if you wished @@ -1014,6 +1020,7 @@ void FS_AddGameHierarchy( const char *dir, uint flags ) { int i; qboolean isGameDir = flags & FS_GAMEDIR_PATH; + char buf[MAX_VA_STRING]; GI->added = true; @@ -1046,15 +1053,23 @@ void FS_AddGameHierarchy( const char *dir, uint flags ) newFlags |= FS_GAMERODIR_PATH; FS_AllowDirectPaths( true ); - FS_AddGameDirectory( va( "%s/%s/", fs_rodir, dir ), newFlags ); + Q_snprintf( buf, sizeof( buf ), "%s/%s/", fs_rodir, dir ); + FS_AddGameDirectory( buf, newFlags ); FS_AllowDirectPaths( false ); } if( isGameDir ) - FS_AddGameDirectory( va( "%s/downloaded/", dir ), FS_NOWRITE_PATH | FS_CUSTOM_PATH ); - FS_AddGameDirectory( va( "%s/", dir ), flags ); + { + Q_snprintf( buf, sizeof( buf ), "%s/downloaded/", dir ); + FS_AddGameDirectory( buf, FS_NOWRITE_PATH | FS_CUSTOM_PATH ); + } + Q_snprintf( buf, sizeof( buf ), "%s/", dir ); + FS_AddGameDirectory( buf, flags ); if( isGameDir ) - FS_AddGameDirectory( va( "%s/custom/", dir ), FS_NOWRITE_PATH | FS_CUSTOM_PATH ); + { + Q_snprintf( buf, sizeof( buf ), "%s/custom/", dir ); + FS_AddGameDirectory( buf, FS_NOWRITE_PATH | FS_CUSTOM_PATH ); + } } /* @@ -1072,8 +1087,12 @@ void FS_Rescan( void ) #if XASH_IOS { - FS_AddPak_Fullpath( va( "%sextras.pak", SDL_GetBasePath() ), NULL, extrasFlags ); - FS_AddPak_Fullpath( va( "%sextras_%s.pak", SDL_GetBasePath(), GI->gamefolder ), NULL, extrasFlags ); + char buf[MAX_VA_STRING]; + + Q_snprintf( buf, sizeof( buf ), "%sextras.pak", SDL_GetBasePath() ); + FS_AddPak_Fullpath( buf, NULL, extrasFlags ); + Q_snprintf( buf, sizeof( buf ), "%sextras_%s.pak", SDL_GetBasePath(), GI->gamefolder ); + FS_AddPak_Fullpath( buf, NULL, extrasFlags ); } #else str = getenv( "XASH3D_EXTRAS_PAK1" ); @@ -1293,6 +1312,7 @@ qboolean FS_InitStdio( qboolean caseinsensitive, const char *rootdir, const char qboolean hasBaseDir = false; qboolean hasGameDir = false; int i; + char buf[MAX_VA_STRING]; FS_InitMemory(); #if !XASH_WIN32 @@ -1358,7 +1378,10 @@ qboolean FS_InitStdio( qboolean caseinsensitive, const char *rootdir, const char // build list of game directories here if( COM_CheckStringEmpty( fs_rodir )) - FS_AddGameDirectory( va( "%s/", fs_rodir ), FS_STATIC_PATH|FS_NOWRITE_PATH ); + { + Q_snprintf( buf, sizeof( buf ), "%s/", fs_rodir ); + FS_AddGameDirectory( buf, FS_STATIC_PATH|FS_NOWRITE_PATH ); + } FS_AddGameDirectory( "./", FS_STATIC_PATH ); for( i = 0; i < dirs.numstrings; i++ ) diff --git a/filesystem/wad.c b/filesystem/wad.c index a456e49f..da0912b5 100644 --- a/filesystem/wad.c +++ b/filesystem/wad.c @@ -503,6 +503,7 @@ static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char string wadfolder, temp; int j, i; const char *slash, *backslash, *colon, *separator; + char buf[MAX_VA_STRING]; // quick reject by filetype if( type == TYP_NONE ) @@ -550,8 +551,9 @@ static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char if( j == list->numstrings ) { // build path: wadname/lumpname.ext - Q_snprintf( temp2, sizeof(temp2), "%s/%s", wadfolder, temp ); - COM_DefaultExtension( temp2, va(".%s", W_ExtFromType( search->wad->lumps[i].type ))); + Q_snprintf( temp2, sizeof( temp2 ), "%s/%s", wadfolder, temp ); + Q_snprintf( buf, sizeof( buf ), ".%s", W_ExtFromType( search->wad->lumps[i].type )); + COM_DefaultExtension( temp2, buf ); stringlistappend( list, temp2 ); } }