Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add D_DoomPrefDir() instead of D_DoomExeDir() to iwad_dirs #2115

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/d_iwad.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,38 @@ char *D_DoomExeDir(void)
return base;
}

// [FG] get the path to the default configuration dir to use

char *D_DoomPrefDir(void)
{
static char *dir;

if (dir == NULL)
{
#if !defined(_WIN32) || defined(_WIN32_WCE)
// Configuration settings are stored in an OS-appropriate path
// determined by SDL. On typical Unix systems, this might be
// ~/.local/share/chocolate-doom. On Windows, we behave like
// Vanilla Doom and save in the current directory.

char *result = SDL_GetPrefPath("", PROJECT_SHORTNAME);
if (result != NULL)
{
dir = M_DirName(result);
SDL_free(result);
}
else
#endif /* #ifndef _WIN32 */
{
dir = D_DoomExeDir();
}

M_MakeDirectory(dir);
}

return dir;
}

// This is Windows-specific code that automatically finds the location
// of installed IWAD files. The registry is inspected to find special
// keys installed by the Windows installers for various CD versions
Expand Down Expand Up @@ -547,7 +579,9 @@ void BuildIWADDirList(void)

// Next check the directory where the executable is located. This might
// be different from the current directory.
array_push(iwad_dirs, D_DoomExeDir());
// D_DoomPrefDir() returns the executable directory on Windows,
// and a user-writable config directory everywhere else.
array_push(iwad_dirs, D_DoomPrefDir());

// Add DOOMWADDIR if it is in the environment
env = M_getenv("DOOMWADDIR");
Expand Down
1 change: 1 addition & 0 deletions src/d_iwad.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct
} iwad_t;

char *D_DoomExeDir(void); // killough 2/16/98: path to executable's dir
char *D_DoomPrefDir(void); // [FG] default configuration dir
char *D_FindWADByName(const char *filename);
char *D_TryFindWADByName(const char *filename);
char *D_FindLMPByName(const char *filename);
Expand Down
32 changes: 0 additions & 32 deletions src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,38 +622,6 @@ char *D_DoomExeName(void)
return name;
}

// [FG] get the path to the default configuration dir to use

char *D_DoomPrefDir(void)
{
static char *dir;

if (dir == NULL)
{
#if !defined(_WIN32) || defined(_WIN32_WCE)
// Configuration settings are stored in an OS-appropriate path
// determined by SDL. On typical Unix systems, this might be
// ~/.local/share/chocolate-doom. On Windows, we behave like
// Vanilla Doom and save in the current directory.

char *result = SDL_GetPrefPath("", PROJECT_SHORTNAME);
if (result != NULL)
{
dir = M_DirName(result);
SDL_free(result);
}
else
#endif /* #ifndef _WIN32 */
{
dir = D_DoomExeDir();
}

M_MakeDirectory(dir);
}

return dir;
}

// Calculate the path to the directory for autoloaded WADs/DEHs.
// Creates the directory as necessary.

Expand Down
1 change: 0 additions & 1 deletion src/d_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void D_AddFile(const char *file);
char *D_DoomExeName(void); // killough 10/98: executable's name
extern char *basesavegame; // killough 2/16/98: savegame path
extern char *screenshotdir; // [FG] screenshot path
char *D_DoomPrefDir(void); // [FG] default configuration dir
void D_SetSavegameDirectory(void);

extern const char *gamedescription;
Expand Down
1 change: 1 addition & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "am_map.h"
#include "config.h"
#include "d_main.h"
#include "d_iwad.h"
#include "doomdef.h"
#include "doomstat.h"
#include "doomtype.h"
Expand Down
2 changes: 1 addition & 1 deletion src/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <stdlib.h>
#include <string.h>

#include "d_main.h"
#include "d_iwad.h"
#include "d_think.h"
#include "doomdef.h"
#include "doomstat.h"
Expand Down Expand Up @@ -676,7 +676,7 @@
directory = maptex+1;
}

offset = LONG(*directory);

Check warning on line 679 in src/r_data.c

View workflow job for this annotation

GitHub Actions / Clang-Tidy

src/r_data.c:679:16 [clang-analyzer-core.NullDereference]

Dereference of null pointer (loaded from variable 'directory')

if (offset > maxoff)
I_Error("R_InitTextures: bad texture directory");
Expand Down