Skip to content

Commit

Permalink
Cut down on some implicit strlens
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jul 15, 2023
1 parent b1fdbb9 commit 98ee9a7
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 83 deletions.
2 changes: 1 addition & 1 deletion input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
**/
Expand Down
8 changes: 5 additions & 3 deletions menu/cbs/menu_cbs_get_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)
{
Expand Down
48 changes: 25 additions & 23 deletions menu/cbs/menu_cbs_left.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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))
)
Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
64 changes: 33 additions & 31 deletions menu/cbs/menu_cbs_right.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -1319,23 +1309,35 @@ 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);
return 0;
}
}

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;
Expand Down
6 changes: 4 additions & 2 deletions menu/cbs/menu_cbs_sublabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down
24 changes: 16 additions & 8 deletions menu/menu_cbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 98ee9a7

Please sign in to comment.