Skip to content
Open
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
15 changes: 14 additions & 1 deletion ball/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ static int loop(void)
/*---------------------------------------------------------------------------*/

static char *opt_data;
static char *opt_user;
static char *opt_replay;
static char *opt_level;

Expand All @@ -326,6 +327,7 @@ static char *opt_level;
" -h, --help show this usage message.\n" \
" -v, --version show version.\n" \
" -d, --data <dir> use 'dir' as game data directory.\n" \
" -u, --user <dir> use 'dir' as user data directory.\n" \
" -r, --replay <file> play the replay 'file'.\n" \
" -l, --level <file> load the level 'file'\n"

Expand Down Expand Up @@ -363,6 +365,17 @@ static void opt_parse(int argc, char **argv)
continue;
}

if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--user") == 0)
{
if (i + 1 == argc)
{
opt_error(argv[i]);
exit(EXIT_FAILURE);
}
opt_user = argv[++i];
continue;
}

if (strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--replay") == 0)
{
if (i + 1 == argc)
Expand Down Expand Up @@ -490,7 +503,7 @@ int main(int argc, char *argv[])

opt_parse(argc, argv);

config_paths(opt_data);
config_paths(opt_data, opt_user);
log_init("Neverball", "neverball.log");
make_dirs_and_migrate();

Expand Down
8 changes: 7 additions & 1 deletion putt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ static int loop(void)
/*---------------------------------------------------------------------------*/

static char *opt_data;
static char *opt_user;
static char *opt_hole;

static void opt_parse(int argc, char **argv)
Expand All @@ -252,6 +253,11 @@ static void opt_parse(int argc, char **argv)
if (++i < argc)
opt_data = argv[i];
}
else if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--user") == 0)
{
if (++i < argc)
opt_user = argv[i];
}
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--hole") == 0)
{
if (++i < argc)
Expand Down Expand Up @@ -294,7 +300,7 @@ int main(int argc, char *argv[])

opt_parse(argc, argv);

config_paths(opt_data);
config_paths(opt_data, opt_user);
log_init("Neverputt", "neverputt.log");
fs_mkdir("Screenshots");

Expand Down
11 changes: 8 additions & 3 deletions share/base_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static const char *pick_home_path(void)
#endif
}

void config_paths(const char *arg_data_path)
void config_paths(const char *arg_data_path, const char *arg_user_path)
{
const char *data, *home, *user;

Expand All @@ -94,8 +94,13 @@ void config_paths(const char *arg_data_path)

/* User directory. */

home = pick_home_path();
user = concat_string(home, "/", CONFIG_USER, NULL);
if (arg_user_path)
user = arg_user_path;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user is passed to free() down the line, which will do something unexpected if user is a passed-in option string. This should either be wrapped in a strdup() or the concat_string() result should be a separate variable that can be passed to free() safely.

else
{
home = pick_home_path();
user = concat_string(home, "/", CONFIG_USER, NULL);
}

/* Set up directory for writing, create if needed. */

Expand Down
2 changes: 1 addition & 1 deletion share/base_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

/*---------------------------------------------------------------------------*/

void config_paths(const char *);
void config_paths(const char *, const char *);

/*---------------------------------------------------------------------------*/

Expand Down