Skip to content

Commit

Permalink
Unix: copy path into a static variable to work on in Sys_Basename and…
Browse files Browse the repository at this point in the history
… Sys_Dirname. This prevents overwriting argv[0]. (#1183)
  • Loading branch information
Daggolin authored Nov 22, 2023
1 parent 247fe8b commit 2ed26b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions shared/sys/sys_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ char *Sys_DefaultAppPath(void);
#endif

char *Sys_DefaultHomePath(void);
const char *Sys_Dirname( char *path );
const char *Sys_Basename( char *path );
const char *Sys_Dirname( const char *path );
const char *Sys_Basename( const char *path );

bool Sys_PathCmp( const char *path1, const char *path2 );

Expand Down
12 changes: 8 additions & 4 deletions shared/sys/sys_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,23 @@ qboolean Sys_LowPhysicalMemory( void )
Sys_Basename
==================
*/
const char *Sys_Basename( char *path )
const char *Sys_Basename( const char *path )
{
return basename( path );
static char buf[ MAX_OSPATH ];
Q_strncpyz( buf, path, sizeof(buf) );
return basename( buf );
}

/*
==================
Sys_Dirname
==================
*/
const char *Sys_Dirname( char *path )
const char *Sys_Dirname( const char *path )
{
return dirname( path );
static char buf[ MAX_OSPATH ];
Q_strncpyz( buf, path, sizeof(buf) );
return dirname( buf );
}

/*
Expand Down
4 changes: 2 additions & 2 deletions shared/sys/sys_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static UINT timerResolution = 0;
Sys_Basename
==============
*/
const char *Sys_Basename( char *path )
const char *Sys_Basename( const char *path )
{
static char base[ MAX_OSPATH ] = { 0 };
int length;
Expand Down Expand Up @@ -68,7 +68,7 @@ const char *Sys_Basename( char *path )
Sys_Dirname
==============
*/
const char *Sys_Dirname( char *path )
const char *Sys_Dirname( const char *path )
{
static char dir[ MAX_OSPATH ] = { 0 };
int length;
Expand Down

0 comments on commit 2ed26b3

Please sign in to comment.