(GX) fix potential null-pointer exceptions

This commit is contained in:
Toad King 2012-08-22 16:05:03 -04:00
parent a88e9e024f
commit 059cfd3c24
2 changed files with 14 additions and 4 deletions

View File

@ -314,9 +314,14 @@ int rarch_main(int argc, char **argv);
static void get_environment_settings(void)
{
getcwd(default_paths.core_dir, MAXPATHLEN);
*(strrchr(default_paths.core_dir, '/')) = 0;
char *last_slash = strrchr(default_paths.core_dir, '/');
if (last_slash)
*last_slash = 0;
char *device_end = strchr(default_paths.core_dir, '/');
snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "%.*s/retroarch", device_end - default_paths.core_dir, default_paths.core_dir);
if (device_end)
snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "%.*s/retroarch", device_end - default_paths.core_dir, default_paths.core_dir);
else
snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "/retroarch");
snprintf(default_paths.config_file, sizeof(default_paths.config_file), "%s/retroarch.cfg", default_paths.port_dir);
snprintf(default_paths.system_dir, sizeof(default_paths.system_dir), "%s/system", default_paths.port_dir);
snprintf(default_paths.savestate_dir, sizeof(default_paths.savestate_dir), "%s/savestates", default_paths.port_dir);

View File

@ -115,9 +115,14 @@ static void init_settings(void)
static void get_environment_settings(void)
{
getcwd(default_paths.core_dir, MAXPATHLEN);
*(strrchr(default_paths.core_dir, '/')) = 0;
char *last_slash = strrchr(default_paths.core_dir, '/');
if (last_slash)
*last_slash = 0;
char *device_end = strchr(default_paths.core_dir, '/');
snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "%.*s/retroarch", device_end - default_paths.core_dir, default_paths.core_dir);
if (device_end)
snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "%.*s/retroarch", device_end - default_paths.core_dir, default_paths.core_dir);
else
snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "/retroarch");
snprintf(default_paths.config_file, sizeof(default_paths.config_file), "%s/retroarch.cfg", default_paths.port_dir);
snprintf(default_paths.system_dir, sizeof(default_paths.system_dir), "%s/system", default_paths.port_dir);
snprintf(default_paths.savestate_dir, sizeof(default_paths.savestate_dir), "%s/savestates", default_paths.port_dir);