1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00

Cut down on some implicit strlens

This commit is contained in:
libretroadmin 2023-07-15 09:10:16 +02:00
parent b1fdbb9a37
commit 98ee9a753c
9 changed files with 111 additions and 83 deletions

View File

@ -2898,7 +2898,7 @@ static void input_poll_overlay(
* input_config_translate_str_to_rk:
* @str : String to translate to key ID.
*
* Translates tring representation to key identifier.
* Translates string representation to key identifier.
*
* Returns: key identifier.
**/

View File

@ -2266,14 +2266,16 @@ static int menu_cbs_init_bind_get_string_representation_compare_type(
}
int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx)
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx)
{
if (!cbs)
return -1;
if ( string_starts_with_size(
label, "input_player", STRLEN_CONST("input_player")) &&
string_ends_with_size(label, "joypad_index", strlen(label),
label, "input_player", STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "joypad_index", lbl_len,
STRLEN_CONST("joypad_index"))
)
{

View File

@ -999,24 +999,11 @@ static int bind_left_generic(unsigned type, const char *label,
}
static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
const char *label, const char *menu_label)
const char *label, size_t lbl_len, const char *menu_label, size_t menu_lbl_len)
{
if (cbs->setting)
{
const char *parent_group = cbs->setting->parent_group;
if (string_is_equal(parent_group,
msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
&& (cbs->setting->type == ST_GROUP))
{
BIND_ACTION_LEFT(cbs, action_left_mainmenu);
return 0;
}
}
if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "_joypad_index", strlen(label),
&& string_ends_with_size(label, "_joypad_index", lbl_len,
STRLEN_CONST("_joypad_index")))
{
unsigned i;
@ -1096,7 +1083,7 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_EXPLORE_INITIALISING_LIST:
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
menu_lbl_len,
STRLEN_CONST("_tab")
)
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
@ -1168,7 +1155,7 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
}
static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs,
unsigned type, const char *menu_label)
unsigned type, const char *menu_label, size_t menu_lbl_len)
{
#ifdef HAVE_CHEATS
if (type >= MENU_SETTINGS_CHEAT_BEGIN
@ -1256,7 +1243,7 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs,
case MENU_SETTINGS_CORE_INFO_NONE:
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))
menu_lbl_len, STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
@ -1304,8 +1291,10 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs,
}
int menu_cbs_init_bind_left(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx,
const char *menu_label)
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx,
const char *menu_label, size_t menu_lbl_len)
{
if (!cbs)
return -1;
@ -1316,7 +1305,7 @@ int menu_cbs_init_bind_left(menu_file_list_cbs_t *cbs,
{
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))
menu_lbl_len, STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
@ -1326,10 +1315,23 @@ int menu_cbs_init_bind_left(menu_file_list_cbs_t *cbs,
}
}
if (menu_cbs_init_bind_left_compare_label(cbs, label, menu_label) == 0)
if (cbs->setting)
{
const char *parent_group = cbs->setting->parent_group;
if (string_is_equal(parent_group,
msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
&& (cbs->setting->type == ST_GROUP))
{
BIND_ACTION_LEFT(cbs, action_left_mainmenu);
return 0;
}
}
if (menu_cbs_init_bind_left_compare_label(cbs, label, lbl_len, menu_label, menu_lbl_len) == 0)
return 0;
if (menu_cbs_init_bind_left_compare_type(cbs, type, menu_label) == 0)
if (menu_cbs_init_bind_left_compare_type(cbs, type, menu_label, menu_lbl_len) == 0)
return 0;
return -1;

View File

@ -9240,8 +9240,10 @@ static int menu_cbs_init_bind_ok_compare_type(menu_file_list_cbs_t *cbs,
}
int menu_cbs_init_bind_ok(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx,
const char *menu_label)
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx,
const char *menu_label, size_t menu_lbl_len)
{
if (!cbs)
return -1;

View File

@ -1003,7 +1003,7 @@ static int bind_right_generic(unsigned type, const char *label,
}
static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs,
unsigned type, const char *menu_label)
unsigned type, const char *menu_lbl, size_t menu_lbl_len)
{
#ifdef HAVE_CHEATS
if ( (type >= MENU_SETTINGS_CHEAT_BEGIN)
@ -1091,9 +1091,9 @@ static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs,
case MENU_SETTING_GROUP:
case MENU_SETTINGS_CORE_INFO_NONE:
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
string_ends_with_size(menu_lbl, "_tab",
menu_lbl_len, STRLEN_CONST("_tab"))
|| string_is_equal(menu_lbl, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
BIND_ACTION_RIGHT(cbs, action_right_mainmenu);
@ -1140,23 +1140,11 @@ static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs,
}
static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
const char *label, const char *menu_label)
const char *label, size_t lbl_len, const char *menu_lbl, size_t menu_lbl_len)
{
if (cbs->setting)
{
const char *parent_group = cbs->setting->parent_group;
if (string_is_equal(parent_group, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
&& (cbs->setting->type == ST_GROUP))
{
BIND_ACTION_RIGHT(cbs, action_right_scroll);
return 0;
}
}
if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "_joypad_index", strlen(label),
&& string_ends_with_size(label, "_joypad_index", lbl_len,
STRLEN_CONST("_joypad_index")))
{
unsigned i;
@ -1175,7 +1163,7 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
}
}
if (string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)))
if (string_is_equal(menu_lbl, msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)))
{
BIND_ACTION_RIGHT(cbs, action_right_mainmenu);
return 0;
@ -1237,12 +1225,12 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_NO_CORES_AVAILABLE:
case MENU_ENUM_LABEL_EXPLORE_INITIALISING_LIST:
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
string_ends_with_size(menu_lbl, "_tab",
menu_lbl_len,
STRLEN_CONST("_tab")
)
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
|| string_is_equal(menu_lbl, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_lbl, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
BIND_ACTION_RIGHT(cbs, action_right_mainmenu);
@ -1308,8 +1296,10 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
}
int menu_cbs_init_bind_right(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx,
const char *menu_label)
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx,
const char *menu_lbl, size_t menu_lbl_len)
{
if (!cbs)
return -1;
@ -1319,11 +1309,11 @@ int menu_cbs_init_bind_right(menu_file_list_cbs_t *cbs,
if (type == MENU_SETTING_NO_ITEM)
{
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
string_ends_with_size(menu_lbl, "_tab",
menu_lbl_len,
STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
|| string_is_equal(menu_lbl, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_lbl, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
BIND_ACTION_RIGHT(cbs, action_right_mainmenu);
@ -1331,11 +1321,23 @@ int menu_cbs_init_bind_right(menu_file_list_cbs_t *cbs,
}
}
if (menu_cbs_init_bind_right_compare_label(cbs, label, menu_label
if (cbs->setting)
{
const char *parent_group = cbs->setting->parent_group;
if (string_is_equal(parent_group, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
&& (cbs->setting->type == ST_GROUP))
{
BIND_ACTION_RIGHT(cbs, action_right_scroll);
return 0;
}
}
if (menu_cbs_init_bind_right_compare_label(cbs, label, lbl_len, menu_lbl, menu_lbl_len
) == 0)
return 0;
if (menu_cbs_init_bind_right_compare_type(cbs, type, menu_label ) == 0)
if (menu_cbs_init_bind_right_compare_type(cbs, type, menu_lbl, menu_lbl_len) == 0)
return 0;
return -1;

View File

@ -2055,7 +2055,9 @@ static int action_bind_sublabel_generic(
}
int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx)
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx)
{
unsigned i;
typedef struct info_range_list
@ -5357,7 +5359,7 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
if ( string_starts_with_size(label, "input_player",
STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "_analog_dpad_mode",
strlen(label), STRLEN_CONST("_analog_dpad_mode")))
lbl_len, STRLEN_CONST("_analog_dpad_mode")))
{
unsigned i;
char key_input_adc_type[64];

View File

@ -269,21 +269,27 @@ unsigned libretro_device_get_size(unsigned *devices, size_t devices_size, unsign
/* End of function callbacks */
int menu_cbs_init_bind_left(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx,
const char *menu_label);
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx,
const char *menu_label, size_t menu_lbl_len);
int menu_cbs_init_bind_right(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx,
const char *menu_label);
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx,
const char *menu_label, size_t menu_lbl_len);
int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
const char *path, const char *label, size_t lbl_len,
unsigned type, size_t idx);
int menu_cbs_init_bind_label(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
const char *path, const char *label, size_t lbl_len,
unsigned type, size_t idx);
int menu_cbs_init_bind_info(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
@ -295,8 +301,10 @@ int menu_cbs_init_bind_cancel(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
int menu_cbs_init_bind_ok(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx,
const char *menu_label);
const char *path,
const char *label, size_t lbl_len,
unsigned type, size_t idx,
const char *menu_label, size_t menu_lbl_len);
int menu_cbs_init_bind_deferred_push(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);

View File

@ -2469,10 +2469,13 @@ static void menu_cbs_init(
const menu_ctx_driver_t *menu_driver_ctx,
file_list_t *list,
menu_file_list_cbs_t *cbs,
const char *path, const char *label,
const char *path,
const char *label,
size_t lbl_len,
unsigned type, size_t idx)
{
const char *menu_label = NULL;
size_t menu_lbl_len;
const char *menu_lbl = NULL;
file_list_t *menu_list = MENU_LIST_GET(menu_st->entries.list, 0);
#ifdef DEBUG_LOG
menu_file_list_cbs_t *menu_cbs = (menu_file_list_cbs_t*)
@ -2481,11 +2484,13 @@ static void menu_cbs_init(
#endif
if (menu_list && menu_list->size)
menu_label = menu_list->list[menu_list->size - 1].label;
menu_lbl = menu_list->list[menu_list->size - 1].label;
if (!label || !menu_label)
if (!label || !menu_lbl)
return;
menu_lbl_len = strlen(menu_lbl);
#ifdef DEBUG_LOG
RARCH_LOG("\n");
@ -2495,7 +2500,7 @@ static void menu_cbs_init(
/* It will try to find a corresponding callback function inside
* menu_cbs_ok.c, then map this callback to the entry. */
menu_cbs_init_bind_ok(cbs, path, label, type, idx, menu_label);
menu_cbs_init_bind_ok(cbs, path, label, lbl_len, type, idx, menu_lbl, menu_lbl_len);
/* It will try to find a corresponding callback function inside
* menu_cbs_cancel.c, then map this callback to the entry. */
@ -2519,11 +2524,11 @@ static void menu_cbs_init(
/* It will try to find a corresponding callback function inside
* menu_cbs_left.c, then map this callback to the entry. */
menu_cbs_init_bind_left(cbs, path, label, type, idx, menu_label);
menu_cbs_init_bind_left(cbs, path, label, lbl_len, type, idx, menu_lbl, menu_lbl_len);
/* It will try to find a corresponding callback function inside
* menu_cbs_right.c, then map this callback to the entry. */
menu_cbs_init_bind_right(cbs, path, label, type, idx, menu_label);
menu_cbs_init_bind_right(cbs, path, label, lbl_len, type, idx, menu_lbl, menu_lbl_len);
/* It will try to find a corresponding callback function inside
* menu_cbs_deferred_push.c, then map this callback to the entry. */
@ -2531,7 +2536,7 @@ static void menu_cbs_init(
/* It will try to find a corresponding callback function inside
* menu_cbs_get_string_representation.c, then map this callback to the entry. */
menu_cbs_init_bind_get_string_representation(cbs, path, label, type, idx);
menu_cbs_init_bind_get_string_representation(cbs, path, label, lbl_len, type, idx);
/* It will try to find a corresponding callback function inside
* menu_cbs_title.c, then map this callback to the entry. */
@ -2543,7 +2548,7 @@ static void menu_cbs_init(
/* It will try to find a corresponding callback function inside
* menu_cbs_sublabel.c, then map this callback to the entry. */
menu_cbs_init_bind_sublabel(cbs, path, label, type, idx);
menu_cbs_init_bind_sublabel(cbs, path, label, lbl_len, type, idx);
if (menu_driver_ctx && menu_driver_ctx->bind_init)
menu_driver_ctx->bind_init(
@ -4168,7 +4173,7 @@ bool menu_entries_append(
{
menu_ctx_list_t list_info;
size_t i;
size_t idx;
size_t idx, lbl_len;
const char *menu_path = NULL;
menu_file_list_cbs_t *cbs = NULL;
struct menu_state *menu_st = &menu_driver_state;
@ -4248,9 +4253,11 @@ bool menu_entries_append(
cbs->setting = menu_setting_find_enum(enum_idx);
}
lbl_len = strlen(label);
menu_cbs_init(menu_st,
menu_st->driver_ctx,
list, cbs, path, label, type, idx);
list, cbs, path, label, lbl_len, type, idx);
return true;
}
@ -4260,6 +4267,7 @@ void menu_entries_prepend(file_list_t *list,
enum msg_hash_enums enum_idx,
unsigned type, size_t directory_ptr, size_t entry_idx)
{
size_t lbl_len;
menu_ctx_list_t list_info;
size_t i;
size_t idx = 0;
@ -4331,9 +4339,11 @@ void menu_entries_prepend(file_list_t *list,
list->list[idx].actiondata = cbs;
lbl_len = strlen(label);
menu_cbs_init(menu_st,
menu_st->driver_ctx,
list, cbs, path, label, type, idx);
list, cbs, path, label, lbl_len, type, idx);
}
void menu_entries_flush_stack(const char *needle, unsigned final_type)

View File

@ -54,7 +54,7 @@ static inline void add_sublabel_and_whats_this(
cbs.enum_idx = setting->enum_idx;
menu_cbs_init_bind_sublabel(&cbs, 0, 0, setting->type, setting->size);
menu_cbs_init_bind_sublabel(&cbs, NULL, NULL, 0, setting->type, setting->size);
cbs.action_sublabel(0, 0, 0, 0, 0, tmp, sizeof(tmp));