mirror of
https://github.com/libretro/RetroArch
synced 2025-03-26 02:37:23 +00:00
(core_info) core_info_get_file_id - return length of written
string and use it to avoid strlcat
This commit is contained in:
parent
700b13654c
commit
bd461a5f8e
79
core_info.c
79
core_info.c
@ -1555,19 +1555,17 @@ static bool core_info_path_is_standalone_exempt(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool core_info_get_file_id(const char *core_filename,
|
static size_t core_info_get_file_id(const char *core_filename,
|
||||||
char *core_file_id, size_t len)
|
char *s, size_t len)
|
||||||
{
|
{
|
||||||
|
size_t _len;
|
||||||
char *last_underscore = NULL;
|
char *last_underscore = NULL;
|
||||||
|
|
||||||
if (string_is_empty(core_filename))
|
if (string_is_empty(core_filename))
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
/* Core file 'id' is filename without extension
|
/* Core file 'id' is filename without extension
|
||||||
* or platform-specific suffix */
|
* or platform-specific suffix */
|
||||||
|
|
||||||
/* > Remove extension */
|
/* > Remove extension */
|
||||||
fill_pathname(core_file_id, core_filename, "", len);
|
_len = fill_pathname(s, core_filename, "", len);
|
||||||
#if defined(IOS) || defined(OSX)
|
#if defined(IOS) || defined(OSX)
|
||||||
/* iOS framework names, to quote Apple:
|
/* iOS framework names, to quote Apple:
|
||||||
* "must contain only alphanumerics, dots, hyphens and must not end with a dot."
|
* "must contain only alphanumerics, dots, hyphens and must not end with a dot."
|
||||||
@ -1575,42 +1573,39 @@ static bool core_info_get_file_id(const char *core_filename,
|
|||||||
* Since core names include underscore, which is not allowed, but not dot,
|
* Since core names include underscore, which is not allowed, but not dot,
|
||||||
* which is, we change underscore to dot. Here, we need to change it back.
|
* which is, we change underscore to dot. Here, we need to change it back.
|
||||||
*/
|
*/
|
||||||
string_replace_all_chars(core_file_id, '.', '_');
|
string_replace_all_chars(s, '.', '_');
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* > Remove suffix */
|
/* > Remove suffix */
|
||||||
last_underscore = (char*)strrchr(core_file_id, '_');
|
last_underscore = (char*)strrchr(s, '_');
|
||||||
|
|
||||||
if ( !string_is_empty(last_underscore)
|
if ( !string_is_empty(last_underscore)
|
||||||
&& !string_is_equal(last_underscore, "_libretro"))
|
&& !string_is_equal(last_underscore, "_libretro"))
|
||||||
|
{
|
||||||
*last_underscore = '\0';
|
*last_underscore = '\0';
|
||||||
|
_len = strlen(s); /* TODO/FIXME - make this unnecessary later on */
|
||||||
return !string_is_empty(core_file_id);
|
}
|
||||||
|
return _len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static core_info_t *core_info_find_internal(
|
static core_info_t *core_info_find_internal(core_info_list_t *list,
|
||||||
core_info_list_t *list,
|
|
||||||
const char *core_path)
|
const char *core_path)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
uint32_t hash;
|
|
||||||
char core_file_id[256];
|
char core_file_id[256];
|
||||||
|
|
||||||
if ( !list
|
if (list && !string_is_empty(core_path))
|
||||||
|| string_is_empty(core_path)
|
|
||||||
|| !core_info_get_file_id(path_basename_nocompression(core_path),
|
|
||||||
core_file_id, sizeof(core_file_id)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
hash = core_info_hash_string(core_file_id);
|
|
||||||
|
|
||||||
for (i = 0; i < list->count; i++)
|
|
||||||
{
|
{
|
||||||
core_info_t *info = &list->list[i];
|
if ((core_info_get_file_id(path_basename_nocompression(core_path),
|
||||||
|
core_file_id, sizeof(core_file_id))) > 0)
|
||||||
if ( (info->core_file_id.hash == hash)
|
{
|
||||||
&& string_is_equal(info->core_file_id.str, core_file_id))
|
size_t i;
|
||||||
return info;
|
uint32_t hash = core_info_hash_string(core_file_id);
|
||||||
|
for (i = 0; i < list->count; i++)
|
||||||
|
{
|
||||||
|
core_info_t *info = &list->list[i];
|
||||||
|
if ((info->core_file_id.hash == hash)
|
||||||
|
&& string_is_equal(info->core_file_id.str, core_file_id))
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -2038,15 +2033,15 @@ static core_info_list_t *core_info_list_new(const char *path,
|
|||||||
|
|
||||||
for (i = 0; i < path_list->core_list->size; i++)
|
for (i = 0; i < path_list->core_list->size; i++)
|
||||||
{
|
{
|
||||||
|
char core_file_id[256];
|
||||||
|
config_file_t *conf = NULL;
|
||||||
core_info_t *info = &core_info[i];
|
core_info_t *info = &core_info[i];
|
||||||
core_file_path_t *core_file = &path_list->core_list->list[i];
|
core_file_path_t *core_file = &path_list->core_list->list[i];
|
||||||
const char *base_path = core_file->path;
|
const char *base_path = core_file->path;
|
||||||
const char *core_filename = core_file->filename;
|
const char *core_filename = core_file->filename;
|
||||||
config_file_t *conf = NULL;
|
size_t _len = core_info_get_file_id(core_filename, core_file_id,
|
||||||
char core_file_id[256];
|
sizeof(core_file_id));
|
||||||
|
if (_len == 0)
|
||||||
if (!core_info_get_file_id(core_filename, core_file_id,
|
|
||||||
sizeof(core_file_id)))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* If info cache is available, search for
|
/* If info cache is available, search for
|
||||||
@ -2103,7 +2098,7 @@ static core_info_list_t *core_info_list_new(const char *path,
|
|||||||
info->core_file_id.str = strdup(core_file_id);
|
info->core_file_id.str = strdup(core_file_id);
|
||||||
info->core_file_id.hash = core_info_hash_string(core_file_id);
|
info->core_file_id.hash = core_info_hash_string(core_file_id);
|
||||||
|
|
||||||
strlcat(core_file_id, ".info", sizeof(core_file_id));
|
strlcpy(core_file_id + _len, ".info", sizeof(core_file_id) - _len);
|
||||||
|
|
||||||
/* Parse core info file */
|
/* Parse core info file */
|
||||||
if ((conf = core_info_get_config_file(core_file_id, info_dir)))
|
if ((conf = core_info_get_config_file(core_file_id, info_dir)))
|
||||||
@ -2524,17 +2519,15 @@ bool core_info_core_file_id_is_equal(const char *core_path_a,
|
|||||||
{
|
{
|
||||||
char core_file_id_a[256];
|
char core_file_id_a[256];
|
||||||
char core_file_id_b[256];
|
char core_file_id_b[256];
|
||||||
|
|
||||||
if ( string_is_empty(core_path_a)
|
if ( string_is_empty(core_path_a)
|
||||||
|| string_is_empty(core_path_b)
|
|| string_is_empty(core_path_b)
|
||||||
|| !core_info_get_file_id(
|
|| (core_info_get_file_id(
|
||||||
path_basename_nocompression(core_path_a),
|
path_basename_nocompression(core_path_a),
|
||||||
core_file_id_a, sizeof(core_file_id_a))
|
core_file_id_a, sizeof(core_file_id_a) == 0))
|
||||||
|| !core_info_get_file_id(
|
|| (core_info_get_file_id(
|
||||||
path_basename_nocompression(core_path_b),
|
path_basename_nocompression(core_path_b),
|
||||||
core_file_id_b, sizeof(core_file_id_b)))
|
core_file_id_b, sizeof(core_file_id_b)) == 0))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return string_is_equal(core_file_id_a, core_file_id_b);
|
return string_is_equal(core_file_id_a, core_file_id_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user