diff --git a/database_info.c b/database_info.c index b5fe450856..45a874a52d 100644 --- a/database_info.c +++ b/database_info.c @@ -217,7 +217,8 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur, if (!string_is_empty(val_string)) db_info->franchise = strdup(val_string); } - else if (string_ends_with(str, "_rating")) + else if (string_ends_with_size(str, "_rating", + strlen(str), STRLEN_CONST("_rating"))) { if (string_is_equal(str, "bbfc_rating")) { diff --git a/libretro-common/include/string/stdstring.h b/libretro-common/include/string/stdstring.h index 55dc9e509a..4f8e897529 100644 --- a/libretro-common/include/string/stdstring.h +++ b/libretro-common/include/string/stdstring.h @@ -56,21 +56,22 @@ static INLINE bool string_starts_with(const char *str, const char *prefix) return (str && prefix) ? !strncmp(prefix, str, strlen(prefix)) : false; } -static INLINE bool string_ends_with(const char *str, const char *suffix) +static INLINE bool string_ends_with_size(const char *str, const char *suffix, + size_t str_len, size_t suffix_len) { - size_t str_len; - size_t suffix_len; - - if (!str || !suffix) - return false; - - str_len = strlen(str); - suffix_len = strlen(suffix); - return (str_len < suffix_len) ? false : !memcmp(suffix, str + (str_len - suffix_len), suffix_len); } +static INLINE bool string_ends_with(const char *str, const char *suffix) +{ + if (!str || !suffix) + return false; + return string_ends_with_size(str, suffix, strlen(str), strlen(suffix)); +} + + + #define STRLEN_CONST(x) ((sizeof((x))-1)) #define string_is_not_equal(a, b) !string_is_equal((a), (b)) diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 3b66cded7f..1eb6876a9a 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -1901,8 +1901,10 @@ int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs, if (!cbs) return -1; - if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) && - string_ends_with(label, "joypad_index") + if ( string_starts_with_size( + label, "input_player", STRLEN_CONST("input_player")) && + string_ends_with_size(label, "joypad_index", strlen(label), + STRLEN_CONST("joypad_index")) ) { BIND_ACTION_GET_VALUE(cbs, menu_action_setting_disp_set_label); diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 724b31b1ff..aa7c3f0cd1 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -843,7 +843,8 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs, } if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) && - string_ends_with(label, "_joypad_index")) + string_ends_with_size(label, "_joypad_index", strlen(label), + STRLEN_CONST("_joypad_index"))) { unsigned i; for (i = 0; i < MAX_USERS; i++) @@ -916,7 +917,10 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_NO_ITEMS: case MENU_ENUM_LABEL_NO_PLAYLIST_ENTRIES_AVAILABLE: if ( - string_ends_with(menu_label, "_tab") + 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_MAIN_MENU)) || string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU)) ) @@ -931,7 +935,9 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_START_VIDEO_PROCESSOR: case MENU_ENUM_LABEL_TAKE_SCREENSHOT: if ( - string_ends_with(menu_label, "_tab") + 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)) ) { @@ -1062,7 +1068,8 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs, case MENU_SETTING_GROUP: case MENU_SETTINGS_CORE_INFO_NONE: if ( - string_ends_with(menu_label, "_tab") + 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)) ) { @@ -1098,7 +1105,8 @@ int menu_cbs_init_bind_left(menu_file_list_cbs_t *cbs, if (type == MENU_SETTING_NO_ITEM) { if ( - string_ends_with(menu_label, "_tab") + 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_MAIN_MENU)) || string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU)) ) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 6f88b915ad..b0916588b4 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2138,7 +2138,9 @@ static int action_ok_playlist_entry_collection(const char *path, * then copy the path without modification * > If this is a standard core, ensure * it has a corresponding core info entry */ - if (string_ends_with(entry->core_path, "builtin")) + if (string_ends_with_size(entry->core_path, "builtin", + strlen(entry->core_path), + STRLEN_CONST("builtin"))) { strlcpy(core_path, entry->core_path, sizeof(core_path)); core_is_builtin = true; @@ -5136,7 +5138,9 @@ static void netplay_refresh_rooms_cb(retro_task_t *task, data->data = new_data; data->data[data->len] = '\0'; - if (!string_ends_with(data->data, "registry.lpl")) + if (!string_ends_with_size(data->data, "registry.lpl", + strlen(data->data), + STRLEN_CONST("registry.lpl"))) { if (string_is_empty(data->data)) netplay_room_count = 0; @@ -6662,7 +6666,9 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs, return 0; } - if (string_ends_with(str, "input_binds_list")) + if (string_ends_with_size(str, "input_binds_list", + strlen(str), + STRLEN_CONST("input_binds_list"))) { unsigned i; diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index 6580410251..e232686966 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -919,7 +919,8 @@ 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(menu_label, "_tab") + 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)) ) { @@ -960,7 +961,8 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs, } if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) && - string_ends_with(label, "_joypad_index")) + string_ends_with_size(label, "_joypad_index", strlen(label), + STRLEN_CONST("_joypad_index"))) { unsigned i; for (i = 0; i < MAX_USERS; i++) @@ -1033,7 +1035,10 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_NO_ITEMS: case MENU_ENUM_LABEL_NO_PLAYLIST_ENTRIES_AVAILABLE: if ( - string_ends_with(menu_label, "_tab") + 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_MAIN_MENU)) || string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU)) ) @@ -1048,7 +1053,9 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_START_VIDEO_PROCESSOR: case MENU_ENUM_LABEL_TAKE_SCREENSHOT: if ( - string_ends_with(menu_label, "_tab") + 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)) ) { @@ -1104,7 +1111,9 @@ int menu_cbs_init_bind_right(menu_file_list_cbs_t *cbs, if (type == MENU_SETTING_NO_ITEM) { if ( - string_ends_with(menu_label, "_tab") + 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_MAIN_MENU)) || string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU)) ) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 39d54024a9..782b4dbe92 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -9611,7 +9611,8 @@ static void materialui_list_insert( node->icon_texture_index = MUI_TEXTURE_PLAYLIST; node->has_icon = true; } - else if (string_ends_with(label, "_input_binds_list")) + else if (string_ends_with_size(label, "_input_binds_list", + strlen(label), STRLEN_CONST("_input_binds_list"))) { unsigned i; diff --git a/menu/drivers/ozone/ozone_sidebar.c b/menu/drivers/ozone/ozone_sidebar.c index 104ba27718..b3295aff84 100644 --- a/menu/drivers/ozone/ozone_sidebar.c +++ b/menu/drivers/ozone/ozone_sidebar.c @@ -850,7 +850,8 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone) if (!path) continue; - if (!string_ends_with(path, ".lpl")) + if (!string_ends_with_size(path, ".lpl", + strlen(path), STRLEN_CONST(".lpl"))) continue; { @@ -968,7 +969,8 @@ void ozone_context_destroy_horizontal_list(ozone_handle_t *ozone) file_list_get_at_offset(ozone->horizontal_list, i, &path, NULL, NULL, NULL); - if (!path || !string_ends_with(path, ".lpl")) + if (!path || !string_ends_with_size(path, ".lpl", + strlen(path), STRLEN_CONST(".lpl"))) continue; video_driver_texture_unload(&node->icon); diff --git a/menu/drivers/stripes.c b/menu/drivers/stripes.c index 7dc778a14a..4eeb451473 100644 --- a/menu/drivers/stripes.c +++ b/menu/drivers/stripes.c @@ -1837,7 +1837,8 @@ static void stripes_context_destroy_horizontal_list(stripes_handle_t *stripes) file_list_get_at_offset(stripes->horizontal_list, i, &path, NULL, NULL, NULL); - if (!path || !string_ends_with(path, ".lpl")) + if (!path || !string_ends_with_size(path, ".lpl", + strlen(path), STRLEN_CONST(".lpl"))) continue; video_driver_texture_unload(&node->icon); @@ -1935,7 +1936,8 @@ static void stripes_context_reset_horizontal_list( file_list_get_at_offset(stripes->horizontal_list, i, &path, NULL, NULL, NULL); - if (!path || !string_ends_with(path, ".lpl")) + if (!path || !string_ends_with_size(path, ".lpl", + strlen(path), STRLEN_CONST(".lpl"))) continue; { diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 62ca98c12a..5d05fe6343 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2032,7 +2032,8 @@ static void xmb_context_destroy_horizontal_list(xmb_handle_t *xmb) file_list_get_at_offset(xmb->horizontal_list, i, &path, NULL, NULL, NULL); - if (!path || !string_ends_with(path, ".lpl")) + if (!path || !string_ends_with_size(path, ".lpl", + strlen(path), STRLEN_CONST(".lpl"))) continue; video_driver_texture_unload(&node->icon); @@ -2131,7 +2132,8 @@ static void xmb_context_reset_horizontal_list( if (!path) continue; - if (!string_ends_with(path, ".lpl")) + if (!string_ends_with_size(path, ".lpl", + strlen(path), STRLEN_CONST(".lpl"))) continue; { diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 593bd05c44..dac62740e7 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1134,7 +1134,8 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, if ( string_is_equal(path_playlist, "history") || string_is_equal(path_playlist, "favorites") || - string_ends_with(path_playlist, "_history")) + string_ends_with_size(path_playlist, "_history", + strlen(path_playlist), STRLEN_CONST("_history"))) { char system_name[15]; system_name[0] = '\0'; @@ -1989,7 +1990,8 @@ static void menu_displaylist_set_new_playlist( /* Get proper playlist capacity */ if (!string_is_empty(playlist_file_name)) { - if (string_ends_with(path, "_history.lpl")) + if (string_ends_with_size(path, "_history.lpl", + strlen(path), STRLEN_CONST("_history.lpl"))) playlist_size = content_history_size; else if (string_is_equal(playlist_file_name, file_path_str(FILE_PATH_CONTENT_FAVORITES))) if (content_favorites_size >= 0) @@ -2464,7 +2466,8 @@ static int menu_displaylist_parse_horizontal_content_actions( remove_entry_enabled = string_is_equal(system, "history") || string_is_equal(system, "favorites") || - string_ends_with(system, "_history"); + string_ends_with_size(system, "_history", + strlen(system), STRLEN_CONST("_history") ); /* An annoyance: if the user navigates to the information menu, * then to the database entry, the thumbnail system will be changed. @@ -2565,7 +2568,8 @@ static int menu_displaylist_parse_horizontal_content_actions( menu_driver_get_thumbnail_system(system, sizeof(system)); if (!string_is_empty(system)) - download_enabled = !string_ends_with(system, "_history"); + download_enabled = !string_ends_with_size( + system, "_history", strlen(system), STRLEN_CONST("_history")); } if (settings->bools.network_on_demand_thumbnails) @@ -2815,7 +2819,8 @@ static unsigned menu_displaylist_parse_playlists( /* Ignore history/favourites */ if ( - string_ends_with(path, "_history.lpl") + string_ends_with_size(path, "_history.lpl", + strlen(path), STRLEN_CONST("_history.lpl")) || string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES))) continue; @@ -3084,7 +3089,8 @@ static unsigned menu_displaylist_parse_playlist_manager_list( * > content_history + favorites are handled separately * > music/video/image_history are ignored */ if ( - string_ends_with(path, "_history.lpl") + string_ends_with_size(path, "_history.lpl", + strlen(path), STRLEN_CONST("_history.lpl")) || string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES))) continue; @@ -3162,7 +3168,9 @@ static bool menu_displaylist_parse_playlist_manager_settings( return false; /* Check whether this is a content history playlist */ - is_content_history = string_ends_with(playlist_path, "_history.lpl"); + is_content_history = string_ends_with_size( + playlist_path, "_history.lpl", strlen(playlist_path), + STRLEN_CONST("_history.lpl")); /* Default core association * > This is only shown for collection playlists diff --git a/menu/menu_networking.c b/menu/menu_networking.c index 4d8d56d527..c71ea4e8c8 100644 --- a/menu/menu_networking.c +++ b/menu/menu_networking.c @@ -152,8 +152,11 @@ void cb_net_generic_subdir(retro_task_t *task, subdir_path[data->len] = '\0'; finish: - if (!err && !string_ends_with(subdir_path, - file_path_str(FILE_PATH_INDEX_DIRS_URL))) + if (!err && !string_ends_with_size(subdir_path, + file_path_str(FILE_PATH_INDEX_DIRS_URL), + strlen(subdir_path), + strlen(file_path_str(FILE_PATH_INDEX_DIRS_URL)) + )) { char parent_dir[PATH_MAX_LENGTH]; @@ -221,7 +224,11 @@ finish: } if (!err && - !string_ends_with(state->path, file_path_str(FILE_PATH_INDEX_DIRS_URL))) + !string_ends_with_size(state->path, + file_path_str(FILE_PATH_INDEX_DIRS_URL), + strlen(state->path), + strlen(file_path_str(FILE_PATH_INDEX_DIRS_URL)) + )) { char *parent_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *parent_dir_encoded = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); diff --git a/playlist.c b/playlist.c index c355b8333d..c55a547000 100644 --- a/playlist.c +++ b/playlist.c @@ -2755,7 +2755,8 @@ void playlist_get_db_name(playlist_t *playlist, size_t idx, * (i.e. ignore history/favourites) */ if ( !string_is_empty(conf_path_basename) - && !string_ends_with(playlist->conf_path, "_history.lpl") + && !string_ends_with_size(playlist->conf_path, "_history.lpl", + strlen(playlist->conf_path), STRLEN_CONST("_history.lpl")) && !string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_FAVORITES)) ) diff --git a/retroarch.c b/retroarch.c index 9a479d5985..7432555731 100644 --- a/retroarch.c +++ b/retroarch.c @@ -19332,7 +19332,8 @@ static bool libretro_get_system_info( dylib_t lib; #endif - if (string_ends_with(path, "builtin")) + if (string_ends_with_size(path, + "builtin", strlen(path), STRLEN_CONST("builtin"))) return false; dummy_info.library_name = NULL; @@ -34856,7 +34857,8 @@ static void retroarch_parse_input_and_config( { int path_stats; - if (string_ends_with(optarg, "builtin")) + if (string_ends_with_size(optarg, "builtin", + strlen(optarg), STRLEN_CONST("builtin"))) { RARCH_LOG("--libretro argument \"%s\" is a built-in core. Ignoring.\n", optarg); diff --git a/tasks/task_http.c b/tasks/task_http.c index 0902dcd1b0..7a80a460d0 100644 --- a/tasks/task_http.c +++ b/tasks/task_http.c @@ -353,7 +353,8 @@ void* task_push_http_transfer_file(const char* url, bool mute, strlcpy(tmp, msg_hash_to_str(MSG_DOWNLOADING), sizeof(tmp)); strlcat(tmp, " ", sizeof(tmp)); - if (string_ends_with(s, ".index")) + if (string_ends_with_size(s, ".index", + strlen(s), STRLEN_CONST(".index"))) strlcat(tmp, msg_hash_to_str(MSG_INDEX_FILE), sizeof(tmp)); else strlcat(tmp, s, sizeof(tmp)); diff --git a/tasks/task_netplay_find_content.c b/tasks/task_netplay_find_content.c index 143230207f..ce41167ecc 100644 --- a/tasks/task_netplay_find_content.c +++ b/tasks/task_netplay_find_content.c @@ -266,7 +266,9 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) const char *lpl_path = state->lpl_list->elems[i].data; /* skip files without .lpl file extension */ - if (!string_ends_with(lpl_path, ".lpl")) + if (!string_ends_with_size(lpl_path, ".lpl", + strlen(lpl_path), + STRLEN_CONST(".lpl"))) continue; RARCH_LOG("[Lobby]: Searching playlist: %s\n", lpl_path); @@ -340,7 +342,9 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) const char *lpl_path = state->lpl_list->elems[j].data; /* skip files without .lpl file extension */ - if (!string_ends_with(lpl_path, ".lpl")) + if (!string_ends_with_size(lpl_path, ".lpl", + strlen(lpl_path), + STRLEN_CONST(".lpl"))) continue; RARCH_LOG("[Lobby]: Searching content %d/%d (%s) in playlist: %s\n", i + 1, game_list->size, game_list->elems[i].data, lpl_path); diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index 46ca81d9c4..1b11eceac9 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -492,7 +492,10 @@ bool task_push_pl_thumbnail_download( /* Only parse supported playlist types */ if ( - string_ends_with(playlist_path, "_history.lpl") + string_ends_with_size(playlist_path, "_history.lpl", + strlen(playlist_path), + STRLEN_CONST("_history.lpl") + ) || string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES)) || string_is_equal(system, "history") @@ -796,7 +799,10 @@ bool task_push_pl_entry_thumbnail_download( goto error; /* Only parse supported playlist types */ - if (string_ends_with(system, "_history")) + if (string_ends_with_size(system, "_history", + strlen(system), + STRLEN_CONST("_history") + )) goto error; /* Copy playlist path