mirror of
https://github.com/libretro/RetroArch
synced 2025-02-15 18:39:55 +00:00
(core_info.c) Reduce stack size usage
This commit is contained in:
parent
3860d95c8f
commit
a2317bf1e1
99
core_info.c
99
core_info.c
@ -189,19 +189,21 @@ static bool core_info_list_iterate(
|
||||
char *s, size_t len,
|
||||
struct string_list *contents, size_t i)
|
||||
{
|
||||
char info_path_base[PATH_MAX_LENGTH];
|
||||
size_t info_path_base_size = PATH_MAX_LENGTH * sizeof(char);
|
||||
char *info_path_base = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA))
|
||||
char *substr = NULL;
|
||||
char *substr = NULL;
|
||||
#endif
|
||||
settings_t *settings = config_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (!contents || !contents->elems[i].data)
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
info_path_base[0] = '\0';
|
||||
|
||||
fill_pathname_base_noext(info_path_base, contents->elems[i].data,
|
||||
sizeof(info_path_base));
|
||||
fill_pathname_base_noext(info_path_base,
|
||||
contents->elems[i].data,
|
||||
info_path_base_size);
|
||||
|
||||
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(HW_WUP))
|
||||
substr = strrchr(info_path_base, '_');
|
||||
@ -211,14 +213,20 @@ static bool core_info_list_iterate(
|
||||
|
||||
strlcat(info_path_base,
|
||||
file_path_str(FILE_PATH_CORE_INFO_EXTENSION),
|
||||
sizeof(info_path_base));
|
||||
info_path_base_size);
|
||||
|
||||
fill_pathname_join(s,
|
||||
(!string_is_empty(settings->paths.path_libretro_info)) ?
|
||||
settings->paths.path_libretro_info : settings->paths.directory_libretro,
|
||||
settings->paths.path_libretro_info :
|
||||
settings->paths.directory_libretro,
|
||||
info_path_base, len);
|
||||
|
||||
free(info_path_base);
|
||||
return true;
|
||||
|
||||
error:
|
||||
free(info_path_base);
|
||||
return false;
|
||||
}
|
||||
|
||||
static core_info_list_t *core_info_list_new(const char *path)
|
||||
@ -245,12 +253,13 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
|
||||
for (i = 0; i < contents->size; i++)
|
||||
{
|
||||
char info_path[PATH_MAX_LENGTH];
|
||||
size_t info_path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||
char *info_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
|
||||
info_path[0] = '\0';
|
||||
info_path[0] = '\0';
|
||||
|
||||
if (
|
||||
core_info_list_iterate(info_path, sizeof(info_path),
|
||||
core_info_list_iterate(info_path, info_path_size,
|
||||
contents, i)
|
||||
&& path_is_valid(info_path))
|
||||
{
|
||||
@ -259,30 +268,36 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
unsigned count = 0;
|
||||
config_file_t *conf = config_file_new(info_path);
|
||||
|
||||
free(info_path);
|
||||
|
||||
if (!conf)
|
||||
continue;
|
||||
|
||||
if (config_get_string(conf, "display_name", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "display_name", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].display_name = strdup(tmp);
|
||||
free(tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
if (config_get_string(conf, "corename", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "corename", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].core_name = strdup(tmp);
|
||||
free(tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "systemname", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "systemname", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].systemname = strdup(tmp);
|
||||
free(tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "manufacturer", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "manufacturer", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].system_manufacturer = strdup(tmp);
|
||||
free(tmp);
|
||||
@ -293,7 +308,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
|
||||
core_info[i].firmware_count = count;
|
||||
|
||||
if (config_get_string(conf, "supported_extensions", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "supported_extensions", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].supported_extensions = strdup(tmp);
|
||||
core_info[i].supported_extensions_list =
|
||||
@ -303,7 +319,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "authors", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "authors", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].authors = strdup(tmp);
|
||||
core_info[i].authors_list =
|
||||
@ -313,7 +330,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "permissions", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "permissions", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].permissions = strdup(tmp);
|
||||
core_info[i].permissions_list =
|
||||
@ -323,7 +341,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "license", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "license", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].licenses = strdup(tmp);
|
||||
core_info[i].licenses_list =
|
||||
@ -333,7 +352,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "categories", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "categories", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].categories = strdup(tmp);
|
||||
core_info[i].categories_list =
|
||||
@ -343,7 +363,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "database", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "database", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].databases = strdup(tmp);
|
||||
core_info[i].databases_list =
|
||||
@ -353,7 +374,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "notes", &tmp) && !string_is_empty(tmp))
|
||||
if (config_get_string(conf, "notes", &tmp)
|
||||
&& !string_is_empty(tmp))
|
||||
{
|
||||
core_info[i].notes = strdup(tmp);
|
||||
core_info[i].note_list = string_split(core_info[i].notes, "|");
|
||||
@ -372,6 +394,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
|
||||
core_info[i].config_data = conf;
|
||||
}
|
||||
else
|
||||
free(info_path);
|
||||
|
||||
if (!string_is_empty(contents->elems[i].data))
|
||||
core_info[i].path = strdup(contents->elems[i].data);
|
||||
@ -493,17 +517,18 @@ static bool core_info_list_update_missing_firmware_internal(
|
||||
const char *systemdir)
|
||||
{
|
||||
size_t i;
|
||||
char path[PATH_MAX_LENGTH];
|
||||
core_info_t *info = NULL;
|
||||
core_info_t *info = NULL;
|
||||
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||
char *path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
|
||||
if (!core_info_list || !core)
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
path[0] = '\0';
|
||||
info = core_info_find_internal(core_info_list, core);
|
||||
|
||||
if (!info)
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
rarch_ctl(RARCH_CTL_UNSET_MISSING_BIOS, NULL);
|
||||
for (i = 0; i < info->firmware_count; i++)
|
||||
@ -512,7 +537,7 @@ static bool core_info_list_update_missing_firmware_internal(
|
||||
continue;
|
||||
|
||||
fill_pathname_join(path, systemdir,
|
||||
info->firmware[i].path, sizeof(path));
|
||||
info->firmware[i].path, path_size);
|
||||
info->firmware[i].missing = !path_file_exists(path);
|
||||
if (info->firmware[i].missing && !info->firmware[i].optional)
|
||||
{
|
||||
@ -521,7 +546,12 @@ static bool core_info_list_update_missing_firmware_internal(
|
||||
}
|
||||
}
|
||||
|
||||
free(path);
|
||||
return true;
|
||||
|
||||
error:
|
||||
free(path);
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -732,24 +762,34 @@ void core_info_get_name(const char *path, char *s, size_t len)
|
||||
|
||||
for (i = 0; i < contents->size; i++)
|
||||
{
|
||||
char info_path[PATH_MAX_LENGTH];
|
||||
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||
char *info_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
config_file_t *conf = NULL;
|
||||
char *new_core_name = NULL;
|
||||
|
||||
info_path[0] = '\0';
|
||||
|
||||
if (!string_is_equal(contents->elems[i].data, path))
|
||||
{
|
||||
free(info_path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!core_info_list_iterate(info_path,
|
||||
sizeof(info_path), contents, i)
|
||||
path_size, contents, i)
|
||||
&& path_is_valid(info_path))
|
||||
{
|
||||
free(info_path);
|
||||
continue;
|
||||
}
|
||||
|
||||
conf = config_file_new(info_path);
|
||||
|
||||
if (!conf)
|
||||
{
|
||||
free(info_path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "corename",
|
||||
&new_core_name))
|
||||
@ -759,6 +799,7 @@ void core_info_get_name(const char *path, char *s, size_t len)
|
||||
}
|
||||
|
||||
config_file_free(conf);
|
||||
free(info_path);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user