Skip to content

Commit

Permalink
Fix segfault when XDG_CONFIG_HOME env is not defined
Browse files Browse the repository at this point in the history
Also fix environment corruption by strcat'ing to string returned by getenv
  • Loading branch information
AMDmi3 committed Jul 23, 2013
1 parent 92ff59a commit c466593
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ bool sys_init()

SDL_WM_SetCaption("Espada",NULL);

sys_configpath = strcat(getenv("XDG_CONFIG_HOME"),"/espada.ini");
static char configpath_buffer[4096];
if (getenv("XDG_CONFIG_HOME") != NULL)
snprintf(configpath_buffer, sizeof(configpath_buffer), "%s/espada.ini", getenv("XDG_CONFIG_HOME"));
else
snprintf(configpath_buffer, sizeof(configpath_buffer), "%s/.config/espada.ini", getenv("HOME"));
sys_configpath = configpath_buffer;

return true;
}
Expand Down

0 comments on commit c466593

Please sign in to comment.