diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 69b5ac3e18..133ec9e167 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -521,7 +521,8 @@ static void rcheevos_async_task_callback( case CHEEVOS_ASYNC_AWARD_ACHIEVEMENT: /* ignore already unlocked */ - if (string_starts_with(buffer, "User already has ")) + if (string_starts_with_size(buffer, "User already has ", + STRLEN_CONST("User already has "))) break; /* fallthrough to default */ diff --git a/configuration.c b/configuration.c index 58064f6904..7460c18efa 100644 --- a/configuration.c +++ b/configuration.c @@ -2533,7 +2533,7 @@ static bool check_menu_driver_compatibility(settings_t *settings) return true; /* TODO/FIXME - maintenance hazard */ - if (string_starts_with(video_driver, "d3d")) + if (string_starts_with_size(video_driver, "d3d", STRLEN_CONST("d3d"))) if ( string_is_equal(video_driver, "d3d9") || string_is_equal(video_driver, "d3d10") || @@ -2541,7 +2541,7 @@ static bool check_menu_driver_compatibility(settings_t *settings) string_is_equal(video_driver, "d3d12") ) return true; - if (string_starts_with(video_driver, "gl")) + if (string_starts_with_size(video_driver, "gl", STRLEN_CONST("gl"))) if ( string_is_equal(video_driver, "gl") || string_is_equal(video_driver, "gl1") || diff --git a/gfx/drivers_shader/glslang.cpp b/gfx/drivers_shader/glslang.cpp index 9e28003724..03d5cd3798 100644 --- a/gfx/drivers_shader/glslang.cpp +++ b/gfx/drivers_shader/glslang.cpp @@ -172,11 +172,11 @@ SlangProcess::SlangProcess() const char *value_str = strtok(0, delims); int value = (int)strtoul(value_str, nullptr, 0); - if (string_starts_with(token, "Max")) + if (string_starts_with_size(token, "Max", STRLEN_CONST("Max"))) { - if (string_starts_with(token, "MaxCompute")) + if (string_starts_with_size(token, "MaxCompute", STRLEN_CONST("MaxCompute"))) { - if (string_starts_with(token, "MaxComputeWork")) + if (string_starts_with_size(token, "MaxComputeWork", STRLEN_CONST("MaxComputeWork"))) { if (string_is_equal(token, "MaxComputeWorkGroupCountX")) Resources.maxComputeWorkGroupCountX = value; @@ -202,7 +202,7 @@ SlangProcess::SlangProcess() else if (string_is_equal(token, "MaxComputeAtomicCounterBuffers")) Resources.maxComputeAtomicCounterBuffers = value; } - else if (string_starts_with(token, "MaxVertex")) + else if (string_starts_with_size(token, "MaxVertex", STRLEN_CONST("MaxVertex"))) { if (string_is_equal(token, "MaxVertexAttribs")) Resources.maxVertexAttribs = value; @@ -223,9 +223,9 @@ SlangProcess::SlangProcess() else if (string_is_equal(token, "MaxVertexAtomicCounterBuffers")) Resources.maxVertexAtomicCounterBuffers = value; } - else if (string_starts_with(token, "MaxTess")) + else if (string_starts_with_size(token, "MaxTess", STRLEN_CONST("MaxTess"))) { - if (string_starts_with(token, "MaxTessEvaluation")) + if (string_starts_with_size(token, "MaxTessEvaluation", STRLEN_CONST("MaxTessEvaluation"))) { if (string_is_equal(token, "MaxTessEvaluationInputComponents")) Resources.maxTessEvaluationInputComponents = value; @@ -242,7 +242,7 @@ SlangProcess::SlangProcess() else if (string_is_equal(token, "MaxTessEvaluationImageUniforms")) Resources.maxTessEvaluationImageUniforms = value; } - else if (string_starts_with(token, "MaxTessControl")) + else if (string_starts_with_size(token, "MaxTessControl", STRLEN_CONST("MaxTessControl"))) { if (string_is_equal(token, "MaxTessControlInputComponents")) Resources.maxTessControlInputComponents = value; @@ -266,7 +266,7 @@ SlangProcess::SlangProcess() else if (string_is_equal(token, "MaxTessGenLevel")) Resources.maxTessGenLevel = value; } - else if (string_starts_with(token, "MaxFragment")) + else if (string_starts_with_size(token, "MaxFragment", STRLEN_CONST("MaxFragment"))) { if (string_is_equal(token, "MaxFragmentUniformComponents")) Resources.maxFragmentUniformComponents = value; @@ -360,7 +360,7 @@ SlangProcess::SlangProcess() else if (string_is_equal(token, "MaxSamples")) Resources.maxSamples = value; } - else if (string_starts_with(token, "general")) + else if (string_starts_with_size(token, "general", STRLEN_CONST("general"))) { if (string_is_equal(token, "generalUniformIndexing")) Resources.limits.generalUniformIndexing = (value != 0); diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 84ed0ccfe4..e60ffaedcc 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -1062,7 +1062,7 @@ static void handle_hotplug(android_input_t *android, */ else if( ( - string_starts_with(device_model, "R800") || + string_starts_with_size(device_model, "R800", STRLEN_CONST("R800")) || strstr(device_model, "Xperia Play") || strstr(device_model, "Play") || strstr(device_model, "SO-01D") @@ -1114,7 +1114,7 @@ static void handle_hotplug(android_input_t *android, /* Amazon Fire TV & Fire stick */ else if ( - string_starts_with(device_model, "AFT") && + string_starts_with_size(device_model, "AFT", STRLEN_CONST("AFT")) && ( strstr(device_model, "AFTB") || strstr(device_model, "AFTT") || diff --git a/libretro-common/cdrom/cdrom.c b/libretro-common/cdrom/cdrom.c index ee44502b94..49099d4493 100644 --- a/libretro-common/cdrom/cdrom.c +++ b/libretro-common/cdrom/cdrom.c @@ -1342,7 +1342,8 @@ struct string_list* cdrom_get_available_drives(void) for (i = 0; i < (int)dir_list->size; i++) { - if (string_starts_with(dir_list->elems[i].data, "/dev/sg")) + if (string_starts_with_size(dir_list->elems[i].data, "/dev/sg", + STRLEN_CONST("/dev/sg"))) { libretro_vfs_implementation_file *stream; char drive_model[32] = {0}; diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index badc9d83d0..5c8d9bf53f 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -381,7 +381,8 @@ static bool parse_line(config_file_t *conf, /* Starting a line with an 'include' directive * appends a sub-config file * > All other comments are ignored */ - if (!string_starts_with(comment, "include ")) + if (!string_starts_with_size(comment, "include ", + STRLEN_CONST("include "))) return false; include_line = comment + STRLEN_CONST("include "); diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 80c5c31995..361fc0d6c5 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -635,9 +635,9 @@ bool path_is_absolute(const char *path) #if defined(_WIN32) /* Many roads lead to Rome... * Note: Drive letter can only be 1 character long */ - if (string_starts_with(path, "\\\\") || - string_starts_with(path + 1, ":/") || - string_starts_with(path + 1, ":\\")) + if (string_starts_with_size(path, "\\\\", STRLEN_CONST("\\\\")) || + string_starts_with_size(path + 1, ":/", STRLEN_CONST(":/")) || + string_starts_with_size(path + 1, ":\\", STRLEN_CONST(":\\"))) return true; #elif defined(__wiiu__) || defined(VITA) { diff --git a/libretro-common/include/string/stdstring.h b/libretro-common/include/string/stdstring.h index 9676a50503..55dc9e509a 100644 --- a/libretro-common/include/string/stdstring.h +++ b/libretro-common/include/string/stdstring.h @@ -45,6 +45,12 @@ static INLINE bool string_is_equal(const char *a, const char *b) return (a && b) ? !strcmp(a, b) : false; } +static INLINE bool string_starts_with_size(const char *str, const char *prefix, + size_t size) +{ + return (str && prefix) ? !strncmp(prefix, str, size) : false; +} + static INLINE bool string_starts_with(const char *str, const char *prefix) { return (str && prefix) ? !strncmp(prefix, str, strlen(prefix)) : false; diff --git a/managers/cheat_manager.c b/managers/cheat_manager.c index e0646de9d3..6906ac2c9f 100644 --- a/managers/cheat_manager.c +++ b/managers/cheat_manager.c @@ -436,7 +436,7 @@ static void cheat_manager_load_cb_second_pass(char *key, char *value) cheat_st->cheats[cheat_idx].handler = (unsigned)strtoul(value, NULL, 0); else if (string_is_equal(key, "memory_search_size")) cheat_st->cheats[cheat_idx].memory_search_size = (unsigned)strtoul(value, NULL, 0); - else if (string_starts_with(key, "repeat_")) + else if (string_starts_with_size(key, "repeat_", STRLEN_CONST("repeat_"))) { if (string_is_equal(key, "repeat_add_to_address")) cheat_st->cheats[cheat_idx].repeat_add_to_address = (unsigned)strtoul(value, NULL, 0); @@ -445,7 +445,7 @@ static void cheat_manager_load_cb_second_pass(char *key, char *value) else if (string_is_equal(key, "repeat_count")) cheat_st->cheats[cheat_idx].repeat_count = (unsigned)strtoul(value, NULL, 0); } - else if (string_starts_with(key, "rumble")) + else if (string_starts_with_size(key, "rumble", STRLEN_CONST("rumble"))) { if (string_is_equal(key, "rumble_port")) cheat_st->cheats[cheat_idx].rumble_port = (unsigned)strtoul(value, NULL, 0); diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 4be9f69302..3b66cded7f 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -1901,7 +1901,7 @@ int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs, if (!cbs) return -1; - if ( string_starts_with(label, "input_player") && + if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) && string_ends_with(label, "joypad_index") ) { diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 7da4879fad..724b31b1ff 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -842,7 +842,7 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs, } } - if ( string_starts_with(label, "input_player") && + if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) && string_ends_with(label, "_joypad_index")) { unsigned i; @@ -868,7 +868,7 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs, return 0; } - if (strstr(label, "rdb_entry") || string_starts_with(label, "content_info")) + if (strstr(label, "rdb_entry") || string_starts_with_size(label, "content_info", STRLEN_CONST("content_info"))) { BIND_ACTION_LEFT(cbs, action_left_scroll); } diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index 53478743b8..6580410251 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -959,7 +959,7 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs, } } - if ( string_starts_with(label, "input_player") && + if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) && string_ends_with(label, "_joypad_index")) { unsigned i; @@ -984,7 +984,8 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs, return 0; } - if (strstr(label, "rdb_entry") || string_starts_with(label, "content_info")) + if ( strstr(label, "rdb_entry") || + string_starts_with_size(label, "content_info", STRLEN_CONST("content_info"))) { BIND_ACTION_RIGHT(cbs, action_right_scroll); } diff --git a/menu/cbs/menu_cbs_title.c b/menu/cbs/menu_cbs_title.c index af1a092b19..e74217bb0e 100644 --- a/menu/cbs/menu_cbs_title.c +++ b/menu/cbs/menu_cbs_title.c @@ -169,7 +169,7 @@ static int action_get_title_dropdown_item( if (string_is_empty(path)) return 0; - if (string_starts_with(path, "core_option_")) + if (string_starts_with_size(path, "core_option_", STRLEN_CONST("core_option_"))) { /* This is a core options item */ struct string_list *tmp_str_list = string_split(path, "_"); diff --git a/menu/drivers/ozone/ozone_entries.c b/menu/drivers/ozone/ozone_entries.c index a0613fac58..592808aa55 100644 --- a/menu/drivers/ozone/ozone_entries.c +++ b/menu/drivers/ozone/ozone_entries.c @@ -103,7 +103,7 @@ static void ozone_draw_entry_value( { if (string_is_equal(entry->value, "...")) return; - if (string_starts_with(entry->value, "(") && + if (string_starts_with_size(entry->value, "(", STRLEN_CONST("(")) && string_ends_with (entry->value, ")") ) { diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index eaf1b8a0e3..62ca98c12a 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -3091,7 +3091,7 @@ static int xmb_draw_item( if (string_is_equal(entry.value, "...")) found = true; - else if (string_starts_with(entry.value, "(") && + else if (string_starts_with_size(entry.value, "(", STRLEN_CONST("(")) && string_ends_with (entry.value, ")") ) { diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 2046c74818..593bd05c44 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -10948,7 +10948,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, { menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); - if (string_starts_with(info->path, "core_option_")) + if (string_starts_with_size(info->path, "core_option_", + STRLEN_CONST("core_option_"))) { struct string_list *tmp_str_list = string_split(info->path, "_"); @@ -11366,7 +11367,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, case DISPLAYLIST_DROPDOWN_LIST_SPECIAL: menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); - if (string_starts_with(info->path, "core_option_")) + if (string_starts_with_size(info->path, "core_option_", + STRLEN_CONST("core_option_"))) { struct string_list *tmp_str_list = string_split(info->path, "_"); diff --git a/playlist.c b/playlist.c index 9e3be79ee7..c355b8333d 100644 --- a/playlist.c +++ b/playlist.c @@ -2034,7 +2034,7 @@ static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, cha pCtx->current_entry_val = &pCtx->current_entry->crc32; else if (string_is_equal(pValue, "db_name")) pCtx->current_entry_val = &pCtx->current_entry->db_name; - else if (string_starts_with(pValue, "subsystem_")) + else if (string_starts_with_size(pValue, "subsystem_", STRLEN_CONST("subsystem_"))) { if (string_is_equal(pValue, "subsystem_ident")) pCtx->current_entry_val = &pCtx->current_entry->subsystem_ident; @@ -2043,7 +2043,7 @@ static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, cha else if (string_is_equal(pValue, "subsystem_roms")) pCtx->current_entry_string_list_val = &pCtx->current_entry->subsystem_roms; } - else if (string_starts_with(pValue, "runtime_")) + else if (string_starts_with_size(pValue, "runtime_", STRLEN_CONST("runtime_"))) { if (string_is_equal(pValue, "runtime_hours")) pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_hours; @@ -2052,7 +2052,7 @@ static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, cha else if (string_is_equal(pValue, "runtime_seconds")) pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_seconds; } - else if (string_starts_with(pValue, "last_played_")) + else if (string_starts_with_size(pValue, "last_played_", STRLEN_CONST("last_played_"))) { if (string_is_equal(pValue, "last_played_year")) pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_year; diff --git a/retroarch.c b/retroarch.c index 1e7c5ae290..95fe8b1dfb 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3764,7 +3764,7 @@ static enum action_iterate_type action_iterate_type(const char *label) { if (string_is_equal(label, "info_screen")) return ITERATE_TYPE_INFO; - if (string_starts_with(label, "help")) + if (string_starts_with_size(label, "help", STRLEN_CONST("help"))) if ( string_is_equal(label, "help") || string_is_equal(label, "help_controls") || @@ -3778,7 +3778,7 @@ static enum action_iterate_type action_iterate_type(const char *label) return ITERATE_TYPE_HELP; if (string_is_equal(label, "cheevos_description")) return ITERATE_TYPE_HELP; - if (string_starts_with(label, "custom_bind")) + if (string_starts_with_size(label, "custom_bind", STRLEN_CONST("custom_bind"))) if ( string_is_equal(label, "custom_bind") || string_is_equal(label, "custom_bind_all") || @@ -11042,12 +11042,12 @@ enum rarch_content_type path_is_media_type(const char *path) string_to_lower(ext_lower); /* hack, to detect livestreams so the ffmpeg core can be started */ - if (string_starts_with(path, "udp://") || - string_starts_with(path, "http://") || - string_starts_with(path, "https://") || - string_starts_with(path, "tcp://") || - string_starts_with(path, "rtmp://") || - string_starts_with(path, "rtp://")) + if (string_starts_with_size(path, "udp://", STRLEN_CONST("udp://")) || + string_starts_with_size(path, "http://", STRLEN_CONST("http://")) || + string_starts_with_size(path, "https://", STRLEN_CONST("https://")) || + string_starts_with_size(path, "tcp://", STRLEN_CONST("tcp://")) || + string_starts_with_size(path, "rtmp://", STRLEN_CONST("rtmp://")) || + string_starts_with_size(path, "rtp://", STRLEN_CONST("rtp://"))) return RARCH_CONTENT_MOVIE; switch (msg_hash_to_file_type(msg_hash_calculate(ext_lower))) @@ -24249,7 +24249,7 @@ static void menu_input_pointer_close_messagebox(struct rarch_state *p_rarch) pop_stack = true; /* > Help box */ - if (string_starts_with(label, "help")) + if (string_starts_with_size(label, "help", STRLEN_CONST("help"))) if ( string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_HELP)) || string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_HELP_CONTROLS)) @@ -32355,7 +32355,7 @@ enum gfx_ctx_api video_context_driver_get_api(void) const char *video_ident = (p_rarch->current_video) ? p_rarch->current_video->ident : NULL; - if (string_starts_with(video_ident, "d3d")) + if (string_starts_with_size(video_ident, "d3d", STRLEN_CONST("d3d"))) { if (string_is_equal(video_ident, "d3d9")) return GFX_CTX_DIRECT3D9_API; @@ -32366,7 +32366,7 @@ enum gfx_ctx_api video_context_driver_get_api(void) else if (string_is_equal(video_ident, "d3d12")) return GFX_CTX_DIRECT3D12_API; } - if (string_starts_with(video_ident, "gl")) + if (string_starts_with_size(video_ident, "gl", STRLEN_CONST("gl"))) { if (string_is_equal(video_ident, "gl")) return GFX_CTX_OPENGL_API; diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index 1667d55161..19ca2b788c 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -250,7 +250,7 @@ int detect_psp_game(intfstream_t *fd, char *game_id) bool found = false; game_id[5] = '\0'; - if (string_starts_with(game_id, "UL")) + if (string_starts_with_size(game_id, "UL", STRLEN_CONST("UL"))) { if ( (string_is_equal(game_id, "ULES-")) @@ -263,7 +263,7 @@ int detect_psp_game(intfstream_t *fd, char *game_id) ) found = true; } - if (!found && string_starts_with(game_id, "UC")) + if (!found && string_starts_with_size(game_id, "UC", STRLEN_CONST("UC"))) { if ( (string_is_equal(game_id, "UCES-")) @@ -276,7 +276,7 @@ int detect_psp_game(intfstream_t *fd, char *game_id) found = true; } - if (!found && string_starts_with(game_id, "NP")) + if (!found && string_starts_with_size(game_id, "NP", STRLEN_CONST("NP"))) { if ( (string_is_equal(game_id, "NPEH-")) diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index 42616c2616..39576b6a29 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -2178,16 +2178,17 @@ void MainWindow::setCoreActions() for (i = 0; i < m_launchWithComboBox->count(); i++) { - QByteArray CorePathArray; - const char *core_path_data = NULL; - QVariantMap map = m_launchWithComboBox->itemData(i, Qt::UserRole).toMap(); + QVariantMap map = + m_launchWithComboBox->itemData( + i, Qt::UserRole).toMap(); + QByteArray CorePathArray = + map.value("core_path").toString().toUtf8(); + const char *core_path_data = CorePathArray.constData(); - CorePathArray = map.value("core_path").toString().toUtf8(); - core_path_data = CorePathArray.constData(); - - if (string_starts_with(path_basename(core_path_data), info->core_file_id.str) || - map.value("core_name").toString() == info->core_name || - map.value("core_name").toString() == info->display_name) + if (string_starts_with(path_basename(core_path_data), + info->core_file_id.str) || + map.value("core_name").toString() == info->core_name || + map.value("core_name").toString() == info->display_name) { found_existing = true; break;