From 8074a833aaf5dd532d45e4c578ed6d27172be204 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 24 Dec 2024 21:07:31 +0100 Subject: [PATCH] Cleanups/less string copies and indirection --- disk_index_file.c | 14 ++- gfx/gfx_display.c | 7 +- gfx/video_driver.c | 22 ++-- gfx/video_driver.h | 2 +- gfx/video_shader_parse.c | 2 - libretro-common/dynamic/dylib.c | 12 +-- libretro-common/file/archive_file.c | 6 +- libretro-common/file/archive_file_7z.c | 30 +++--- libretro-common/file/file_path.c | 8 +- libretro-common/formats/json/rjson.c | 15 +-- libretro-common/formats/m3u/m3u_file.c | 13 +-- menu/cbs/menu_cbs_get_value.c | 43 ++------ menu/cbs/menu_cbs_ok.c | 4 +- menu/cbs/menu_cbs_sublabel.c | 21 +--- menu/cbs/menu_cbs_title.c | 29 +++-- menu/menu_displaylist.c | 140 +++++++++++++------------ menu/menu_driver.c | 30 +++--- menu/menu_setting.c | 56 +++++----- runloop.c | 3 +- runtime_file.c | 2 - tasks/task_autodetect.c | 23 ++-- tasks/task_overlay.c | 8 +- tasks/task_pl_thumbnail_download.c | 12 +-- tasks/task_save.c | 2 - ui/drivers/ui_qt.cpp | 7 +- 25 files changed, 226 insertions(+), 285 deletions(-) diff --git a/disk_index_file.c b/disk_index_file.c index a4d6c29ef9f6..ae8ce812e9cb 100644 --- a/disk_index_file.c +++ b/disk_index_file.c @@ -235,15 +235,13 @@ bool disk_index_file_init( } /* > Create directory, if required */ - if (!path_is_directory(disk_index_file_dir)) + if ( !path_is_directory(disk_index_file_dir) + && !path_mkdir(disk_index_file_dir)) { - if (!path_mkdir(disk_index_file_dir)) - { - RARCH_ERR( - "[disk index file] failed to create directory for disk index file: %s\n", - disk_index_file_dir); - goto error; - } + RARCH_ERR( + "[disk index file] failed to create directory for disk index file: %s\n", + disk_index_file_dir); + goto error; } /* > Generate final path */ diff --git a/gfx/gfx_display.c b/gfx/gfx_display.c index d69cb2da1c41..67063efade8b 100644 --- a/gfx/gfx_display.c +++ b/gfx/gfx_display.c @@ -1132,7 +1132,6 @@ bool gfx_display_reset_icon_texture( uintptr_t *item, enum texture_filter_type filter_type, unsigned *width, unsigned *height) { - char texpath[PATH_MAX_LENGTH]; struct texture_image ti; ti.width = 0; @@ -1142,15 +1141,11 @@ bool gfx_display_reset_icon_texture( if (string_is_empty(texture_path)) return false; - - strlcpy(texpath, texture_path, sizeof(texpath)); - - if (!image_texture_load(&ti, texpath)) + if (!image_texture_load(&ti, texture_path)) return false; if (width) *width = ti.width; - if (height) *height = ti.height; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 5600e3f3af7e..1ecf09017172 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -718,7 +718,7 @@ bool video_driver_translate_coord_viewport( * This should make it possible to hit the edges on all * * screen resolutions, even when pointer cannot be * * moved offscreen. */ - + if (mouse_x > 0 && mouse_x < norm_full_vp_width) scaled_screen_x = ((mouse_x * 0xffff) / (norm_full_vp_width - 1)) - 0x8000; @@ -3245,10 +3245,10 @@ float video_driver_get_refresh_rate(void) return 0.0f; } -void video_driver_set_gpu_api_version_string(const char *str) +size_t video_driver_set_gpu_api_version_string(const char *str) { video_driver_state_t *video_st = &video_driver_st; - strlcpy(video_st->gpu_api_version_string, str, + return strlcpy(video_st->gpu_api_version_string, str, sizeof(video_st->gpu_api_version_string)); } @@ -3857,7 +3857,10 @@ void video_driver_frame(const void *data, unsigned width, status_text[++buf_pos] = ' '; status_text[++buf_pos] = '\0'; buf_pos += snprintf( - status_text + buf_pos, sizeof(status_text) - buf_pos, "%.2f/%.2f", last_used_memory / (1024.0f * 1024.0f), + status_text + buf_pos, + sizeof(status_text) - buf_pos, + "%.2f/%.2f", + last_used_memory / (1024.0f * 1024.0f), last_total_memory / (1024.0f * 1024.0f)); status_text[buf_pos ] = 'M'; status_text[++buf_pos] = 'B'; @@ -3964,7 +3967,8 @@ void video_driver_frame(const void *data, unsigned width, if ( ( #ifdef HAVE_VIDEO_FILTER - !video_st->state_filter || + !video_st->state_filter + || #endif !video_info.post_filter_record || !data @@ -4125,7 +4129,7 @@ void video_driver_frame(const void *data, unsigned width, " - Reserve: %5.2f ms\n" " Frame Delay: %2u.00 ms\n" " - Target: %2u.00 ms\n", - runloop_st->core_run_time / 1000.0f, + runloop_st->core_run_time / 1000.0f, (1000.0f / video_info.refresh_rate) - video_st->frame_delay_effective - (runloop_st->core_run_time / 1000.0f), video_st->frame_time_reserve / 1000.0f, video_st->frame_delay_effective, @@ -4224,10 +4228,12 @@ void video_driver_frame(const void *data, unsigned width, video_st->frame_count, (unsigned)pitch, #if HAVE_MENU ((video_info.menu_st_flags & MENU_ST_FLAG_SCREENSAVER_ACTIVE) > 0) - || video_info.notifications_hidden ? "" : video_driver_msg, + || video_info.notifications_hidden #else - video_info.notifications_hidden ? "" : video_driver_msg, + video_info.notifications_hidden #endif + ? "" + : video_driver_msg, &video_info)) video_st->flags |= VIDEO_FLAG_ACTIVE; else diff --git a/gfx/video_driver.h b/gfx/video_driver.h index cba45943955e..2d0e372dd413 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -1211,7 +1211,7 @@ bool video_driver_test_all_flags(enum display_flags testflag); gfx_ctx_flags_t video_driver_get_flags_wrapper(void); -void video_driver_set_gpu_api_version_string(const char *str); +size_t video_driver_set_gpu_api_version_string(const char *str); const char* video_driver_get_gpu_api_version_string(void); diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index b5af272d3fa8..16152852baff 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -804,8 +804,6 @@ static bool video_shader_parse_textures(config_file_t *conf, bool smooth = false; struct config_entry_list *entry = NULL; - idx[0] = '\0'; - if ( !(entry = config_get_entry(conf, id)) || string_is_empty(entry->value)) { diff --git a/libretro-common/dynamic/dylib.c b/libretro-common/dynamic/dylib.c index baf7fafa7d59..0b99cb5219f0 100644 --- a/libretro-common/dynamic/dylib.c +++ b/libretro-common/dynamic/dylib.c @@ -58,14 +58,12 @@ static char last_dyn_error[512]; static void set_dl_error(void) { DWORD err = GetLastError(); - - if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - err, + if (FormatMessage( + FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), - last_dyn_error, - sizeof(last_dyn_error) - 1, + last_dyn_error, sizeof(last_dyn_error) - 1, NULL) == 0) snprintf(last_dyn_error, sizeof(last_dyn_error) - 1, "unknown error %lu", err); diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c index 0a30211ae12c..4df2ce51cc68 100644 --- a/libretro-common/file/archive_file.c +++ b/libretro-common/file/archive_file.c @@ -336,7 +336,7 @@ bool file_archive_extract_file( const char *archive_path, const char *valid_exts, const char *extraction_directory, - char *out_path, size_t len) + char *s, size_t len) { struct archive_extract_userdata userdata; bool ret = true; @@ -377,7 +377,7 @@ bool file_archive_extract_file( } if (!string_is_empty(userdata.first_extracted_file_path)) - strlcpy(out_path, userdata.first_extracted_file_path, len); + strlcpy(s, userdata.first_extracted_file_path, len); end: if (userdata.first_extracted_file_path) @@ -455,8 +455,8 @@ bool file_archive_perform_mode(const char *path, const char *valid_exts, const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size, uint32_t crc32, struct archive_extract_userdata *userdata) { - file_archive_file_handle_t handle; int ret; + file_archive_file_handle_t handle; if (!userdata->transfer || !userdata->transfer->backend) return false; diff --git a/libretro-common/file/archive_file_7z.c b/libretro-common/file/archive_file_7z.c index e7faac46068e..1961341236f4 100644 --- a/libretro-common/file/archive_file_7z.c +++ b/libretro-common/file/archive_file_7z.c @@ -412,10 +412,16 @@ static int sevenzip_parse_file_init(file_archive_transfer_t *state, } static int sevenzip_parse_file_iterate_step_internal( - struct sevenzip_context_t *sevenzip_context, char *filename, - const uint8_t **cdata, unsigned *cmode, - uint32_t *size, uint32_t *csize, uint32_t *checksum, - unsigned *payback, struct archive_extract_userdata *userdata) + struct sevenzip_context_t *sevenzip_context, + char *s, + size_t len, + const uint8_t **cdata, + unsigned *cmode, + uint32_t *size, + uint32_t *csize, + uint32_t *checksum, + unsigned *payback, + struct archive_extract_userdata *userdata) { if (sevenzip_context->parse_index < sevenzip_context->db.NumFiles) { @@ -431,24 +437,21 @@ static int sevenzip_parse_file_iterate_step_internal( sevenzip_context->packIndex++; } - if (len < PATH_MAX_LENGTH && - !SzArEx_IsDir(&sevenzip_context->db, sevenzip_context->parse_index)) + if ( (len < PATH_MAX_LENGTH) + && !SzArEx_IsDir(&sevenzip_context->db, sevenzip_context->parse_index)) { - char infile[PATH_MAX_LENGTH]; - SRes res = SZ_ERROR_FAIL; - uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t)); + SRes res = SZ_ERROR_FAIL; + uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t)); if (!temp) return -1; - infile[0] = '\0'; - SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->parse_index, temp); if (temp) { - res = utf16_to_char_string(temp, infile, sizeof(infile)) + res = utf16_to_char_string(temp, s, len) ? SZ_OK : SZ_ERROR_FAIL; free(temp); } @@ -456,8 +459,6 @@ static int sevenzip_parse_file_iterate_step_internal( if (res != SZ_OK) return -1; - strlcpy(filename, infile, PATH_MAX_LENGTH); - *cmode = 0; /* unused for 7zip */ *checksum = sevenzip_context->db.CRCs.Vals[sevenzip_context->parse_index]; *size = (uint32_t)SzArEx_GetFileSize(&sevenzip_context->db, sevenzip_context->parse_index); @@ -491,6 +492,7 @@ static int sevenzip_parse_file_iterate_step(void *context, ret = sevenzip_parse_file_iterate_step_internal(sevenzip_context, userdata->current_file_path, + sizeof(userdata->current_file_path), &cdata, &cmode, &size, &csize, &checksum, &payload, userdata); diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 82a2f8030387..ad9968f918ed 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -902,8 +902,8 @@ size_t path_relative_to(char *s, if (path[i] == PATH_DEFAULT_SLASH_C()) j = i + 1; - trimmed_path = path+j; - trimmed_base = base+i; + trimmed_path = path + j; + trimmed_base = base + i; /* Each segment of base turns into ".." */ s[0] = '\0'; @@ -935,9 +935,7 @@ void fill_pathname_resolve_relative(char *s, return; } - if (s != in_refpath) - strlcpy(s, in_refpath, len); - path_basedir(s); + fill_pathname_basedir(s, in_refpath, len); strlcat(s, in_path, len); path_resolve_realpath(s, len, false); } diff --git a/libretro-common/formats/json/rjson.c b/libretro-common/formats/json/rjson.c index f0d73e4ffa72..fccb80daa342 100644 --- a/libretro-common/formats/json/rjson.c +++ b/libretro-common/formats/json/rjson.c @@ -107,9 +107,12 @@ static enum rjson_type _rjson_error_char(rjson_t *json, char buf[16]; if (json->stack_top->type == RJSON_ERROR) return RJSON_ERROR; - snprintf(buf, sizeof(buf), - (chr == _rJSON_EOF ? "end of stream" : - (chr >= ' ' && chr <= '~' ? "'%c'" : "byte 0x%02X")), chr); + if (chr == _rJSON_EOF) + strlcpy(buf, "end of stream", sizeof(buf)); + else if (chr >= ' ' && chr <= '~') + snprintf(buf, sizeof(buf), "'%c'", chr); + else + snprintf(buf, sizeof(buf), "byte 0x%02X", chr); return _rjson_error(json, fmt, buf); } @@ -455,7 +458,7 @@ static enum rjson_type _rjson_read_string(rjson_t *json) case 'n': esc = '\n'; goto escape_pushchar; - case 'r': + case 'r': if (!(json->option_flags & RJSON_OPTION_IGNORE_STRING_CARRIAGE_RETURN)) { esc = '\r'; @@ -573,7 +576,7 @@ static enum rjson_type _rjson_read_number(rjson_t *json) goto invalid_number; if (*p < '0' || *p > '9') goto invalid_number; - do + do { if (++p == end) return RJSON_NUMBER; @@ -988,7 +991,7 @@ void rjson_set_max_depth(rjson_t *json, unsigned int max_depth) const char *rjson_get_string(rjson_t *json, size_t *length) { - char* str = (json->string_pass_through + char* str = (json->string_pass_through ? json->string_pass_through : json->string); if (length) *length = json->string_len; diff --git a/libretro-common/formats/m3u/m3u_file.c b/libretro-common/formats/m3u/m3u_file.c index 70fc45ae0578..bc85d3f6416e 100644 --- a/libretro-common/formats/m3u/m3u_file.c +++ b/libretro-common/formats/m3u/m3u_file.c @@ -477,8 +477,6 @@ bool m3u_file_save( m3u_file_t *m3u_file, enum m3u_file_label_type label_type) { size_t i; - const char *slash; - const char *backslash; char base_dir[DIR_MAX_LENGTH]; char *last_slash = NULL; RFILE *file = NULL; @@ -490,16 +488,9 @@ bool m3u_file_save( if (string_is_empty(m3u_file->path)) return false; - slash = strrchr(m3u_file->path, '/'); - backslash = strrchr(m3u_file->path, '\\'); - last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; - /* Get M3U file base directory */ - if (last_slash) - { - strlcpy(base_dir, m3u_file->path, sizeof(base_dir)); - path_basedir(base_dir); - } + if ((last_slash = find_last_slash(m3u_file->path))) + fill_pathname_basedir(base_dir, m3u_file->path, sizeof(base_dir)); else base_dir[0] = '\0'; diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 222c564027ff..1fce3631098a 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -79,12 +79,9 @@ static void menu_action_setting_audio_mixer_stream_name( { unsigned offset = (type - MENU_SETTINGS_AUDIO_MIXER_STREAM_BEGIN); *w = 19; - strlcpy(s2, path, len2); - if (offset >= AUDIO_MIXER_MAX_SYSTEM_STREAMS) return; - strlcpy(s, audio_driver_mixer_get_stream_name(offset), len); } @@ -100,10 +97,8 @@ static void menu_action_setting_audio_mixer_stream_volume( unsigned offset = (type - MENU_SETTINGS_AUDIO_MIXER_STREAM_ACTIONS_VOLUME_BEGIN); *w = 19; strlcpy(s2, path, len2); - if (offset >= AUDIO_MIXER_MAX_SYSTEM_STREAMS) return; - _len = snprintf(s, len, "%.2f", audio_driver_mixer_get_stream_volume(offset)); strlcpy(s + _len, " dB", len - _len); } @@ -135,7 +130,6 @@ static void menu_action_setting_disp_set_label_cheevos_entry( { *w = 19; strlcpy(s2, path, len2); - rcheevos_menu_get_state(type - MENU_SETTINGS_CHEEVOS_START, s, len); } #endif @@ -150,15 +144,12 @@ static void menu_action_setting_disp_set_label_remap_file_info( { runloop_state_t *runloop_st = runloop_state_get_ptr(); const char *remap_path = runloop_st->name.remapfile; - *w = 19; - + strlcpy(s2, path, len2); if (!string_is_empty(remap_path)) strlcpy(s, path_basename_nocompression(remap_path), len); else strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), len); - - strlcpy(s2, path, len2); } static void menu_action_setting_disp_set_label_override_file_info( @@ -170,15 +161,12 @@ static void menu_action_setting_disp_set_label_override_file_info( char *s2, size_t len2) { const char *override_path = path_get(RARCH_PATH_CONFIG_OVERRIDE); - *w = 19; - + strlcpy(s2, path, len2); if (!string_is_empty(override_path)) strlcpy(s, path_basename_nocompression(override_path), len); else strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), len); - - strlcpy(s2, path, len2); } static void menu_action_setting_disp_set_label_configurations( @@ -191,7 +179,6 @@ static void menu_action_setting_disp_set_label_configurations( { *w = 19; strlcpy(s2, path, len2); - if (!path_is_empty(RARCH_PATH_CONFIG)) fill_pathname_base(s, path_get(RARCH_PATH_CONFIG), len); @@ -210,11 +197,9 @@ static void menu_action_setting_disp_set_label_shader_filter_pass( { struct video_shader *shader = menu_shader_get(); struct video_shader_pass *shader_pass = shader ? &shader->pass[type - MENU_SETTINGS_SHADER_PASS_FILTER_0] : NULL; - *s = '\0'; *w = 19; strlcpy(s2, path, len2); - if (shader_pass) { switch (shader_pass->filter) @@ -246,10 +231,8 @@ static void menu_action_setting_disp_set_label_shader_watch_for_changes( menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) list->list[i].actiondata; bool val = *cbs->setting->value.target.boolean; - *w = 19; strlcpy(s2, path, len2); - if (val) strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_TRUE), len); else @@ -367,7 +350,6 @@ static void menu_action_setting_disp_set_label_shader_scale_pass( unsigned scale_value = 0; struct video_shader *shader = menu_shader_get(); struct video_shader_pass *shader_pass = shader ? &shader->pass[type - MENU_SETTINGS_SHADER_PASS_SCALE_0] : NULL; - *s = '\0'; *w = 19; strlcpy(s2, path, len2); @@ -385,23 +367,19 @@ static void menu_action_setting_disp_set_label_shader_scale_pass( static void menu_action_setting_disp_set_label_netplay_mitm_server( file_list_t *list, unsigned *w, unsigned type, unsigned i, const char *label, char *s, size_t len, - const char *path, char *path_buf, size_t path_buf_size) + const char *path, char *s2, size_t len2) { size_t j; const char *netplay_mitm_server; menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)list->list[i].actiondata; - *w = 19; *s = '\0'; - strlcpy(path_buf, path, path_buf_size); - + strlcpy(s2, path, len2); if (!cbs || !cbs->setting) return; - netplay_mitm_server = cbs->setting->value.target.string; if (string_is_empty(netplay_mitm_server)) return; - for (j = 0; j < ARRAY_SIZE(netplay_mitm_server_list); j++) { const mitm_server_t *server = &netplay_mitm_server_list[j]; @@ -426,16 +404,10 @@ static void menu_action_setting_disp_set_label_menu_file_core( const char *alt = list->list[i].alt ? list->list[i].alt : list->list[i].path; - s[0] = '('; - s[1] = 'C'; - s[2] = 'O'; - s[3] = 'R'; - s[4] = 'E'; - s[5] = ')'; - s[6] = '\0'; *w = (unsigned)STRLEN_CONST("(CORE)"); if (alt) strlcpy(s2, alt, len2); + strlcpy(s, "(CORES)", len); } #ifdef HAVE_NETWORKING @@ -2102,9 +2074,10 @@ static int menu_cbs_init_bind_get_string_representation_compare_type( unsigned max; void (*cb)(file_list_t* list, unsigned *w, unsigned type, unsigned i, - const char *label, char *s, size_t len, + const char *label, + char *s, size_t len, const char *path, - char *path_buf, size_t path_buf_size); + char *s2, size_t len2); } info_range_list_t; info_range_list_t info_list[] = { diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 14faf82f74a5..a1e43baf7ea5 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1354,8 +1354,8 @@ int generic_action_ok_displaylist_push( case ACTION_OK_DL_DISK_IMAGE_APPEND_LIST: { filebrowser_clear_type(); - strlcpy(tmp, path_get(RARCH_PATH_CONTENT), sizeof(tmp)); - path_basedir(tmp); + fill_pathname_basedir(tmp, + path_get(RARCH_PATH_CONTENT), sizeof(tmp)); info.type = type; info.directory_ptr = idx; diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index d4cf8f6c7e0f..b74695757b3a 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -1424,7 +1424,7 @@ static int action_bind_sublabel_systeminfo_controller_entry( } } - snprintf(tmp, sizeof(tmp), + snprintf(s, len, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT_DEVICE_INFO), input_config_get_device_display_name(controller) ? input_config_get_device_display_name(controller) @@ -1434,7 +1434,6 @@ static int action_bind_sublabel_systeminfo_controller_entry( : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), input_config_get_device_vid(controller), input_config_get_device_pid(controller)); - strlcpy(s, tmp, len); return 0; } @@ -1736,17 +1735,13 @@ static int action_bind_sublabel_netplay_room(file_list_t *list, char *s, size_t len) { size_t _len; - char buf[NAME_MAX_LENGTH]; struct netplay_room *room; net_driver_state_t *net_st = networking_state_get_ptr(); unsigned room_index = type - MENU_SETTINGS_NETPLAY_ROOMS_START; - if (room_index >= (unsigned)net_st->room_count) return -1; - room = &net_st->room_list[room_index]; _len = strlcpy(s, msg_hash_to_str(MSG_PROGRAM), len); - _len += snprintf(s + _len, len - _len, ": %s (%s)\n" "%s: %s (%s)\n" @@ -1768,20 +1763,14 @@ static int action_bind_sublabel_netplay_room(file_list_t *list, if ( string_is_empty(room->subsystem_name) || string_is_equal_case_insensitive(room->subsystem_name, "N/A")) - snprintf(buf, sizeof(buf), "(%08lX)", + snprintf(s + _len, len - _len, "(%08lX)", (unsigned long)(unsigned)room->gamecrc); else { - size_t _len2 = 0; - buf[ _len2] = '('; - buf[++_len2] = '\0'; - _len2 += strlcpy(buf + _len2, room->subsystem_name, sizeof(buf) - _len2); - buf[ _len2] = ')'; - buf[++_len2] = '\0'; + _len += strlcpy(s + _len, "(", len - _len); + _len += strlcpy(s + _len, room->subsystem_name, len - _len); + _len += strlcpy(s + _len, ")", len - _len); } - - strlcpy(s + _len, buf, len - _len); - return 0; } diff --git a/menu/cbs/menu_cbs_title.c b/menu/cbs/menu_cbs_title.c index 5a135269e64d..04cb784f0b6f 100644 --- a/menu/cbs/menu_cbs_title.c +++ b/menu/cbs/menu_cbs_title.c @@ -140,11 +140,12 @@ static int action_get_title_remap_port( const char *path, const char *label, unsigned menu_type, char *s, size_t len) { - char lbl[128]; - snprintf(lbl, sizeof(lbl), + char *pos = NULL; + snprintf(s, len, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_USER_BINDS), atoi(path) + 1); - SANITIZE_TO_STRING(s, lbl, len); + while ((pos = strchr(s, '_'))) + *pos = ' '; return 1; } @@ -152,10 +153,8 @@ static int action_get_title_icon_thumbnails( const char *path, const char *label, unsigned menu_type, char *s, size_t len) { - const char *title = NULL; enum msg_hash_enums label_value = MENU_ENUM_LABEL_VALUE_ICON_THUMBNAILS; - - title = msg_hash_to_str(label_value); + const char *title = msg_hash_to_str(label_value); if (s && !string_is_empty(title)) { @@ -172,6 +171,7 @@ static int action_get_title_thumbnails( { const char *title = NULL; enum msg_hash_enums label_value = MENU_ENUM_LABEL_VALUE_THUMBNAILS; +#ifdef HAVE_MENU const char *menu_ident = menu_driver_ident(); /* Get label value */ #ifdef HAVE_RGUI @@ -182,15 +182,13 @@ static int action_get_title_thumbnails( if (string_is_equal(menu_ident, "glui")) label_value = MENU_ENUM_LABEL_VALUE_THUMBNAILS_MATERIALUI; #endif - +#endif title = msg_hash_to_str(label_value); - if (s && !string_is_empty(title)) { SANITIZE_TO_STRING(s, title, len); return 1; } - return 0; } @@ -363,7 +361,6 @@ static int action_get_title_dropdown_item( { const char *title = msg_hash_to_str(enum_idx); - if (s && !string_is_empty(title)) { SANITIZE_TO_STRING(s, title, len); @@ -541,16 +538,14 @@ static int action_get_title_dropdown_input_description_common( string_trim_whitespace_left(input_label); } - /* Sanity check */ - if (string_is_empty(input_label)) - strlcpy(input_label, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), - sizeof(input_label)); - /* Build title string */ _len = strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT), len); _len += snprintf(s + _len, len - _len, " %u - ", port + 1); - strlcpy(s + _len, input_label, len - _len); - + if (!string_is_empty(input_label)) + strlcpy(s + _len, input_label, len - _len); + else + strlcpy(s + _len, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), + len - _len); return 1; } diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index a70d0e0ba144..d02499cb7823 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1045,7 +1045,7 @@ static int menu_displaylist_parse_core_info( static size_t core_backup_list_get_entry_timestamp_str( const core_backup_list_entry_t *entry, enum core_backup_date_separator_type date_separator, - char *timestamp, size_t len) + char *s, size_t len) { const char *format_str = "%04u-%02u-%02u %02u:%02u:%02u"; /* Get time format string */ @@ -1053,8 +1053,7 @@ static size_t core_backup_list_get_entry_timestamp_str( format_str = "%04u/%02u/%02u %02u:%02u:%02u"; else if (date_separator == CORE_BACKUP_DATE_SEPARATOR_PERIOD) format_str = "%04u.%02u.%02u %02u:%02u:%02u"; - - return snprintf(timestamp, len, + return snprintf(s, len, format_str, entry->date.year, entry->date.month, @@ -1106,11 +1105,9 @@ static unsigned menu_displaylist_parse_core_backup_list( && entry && !string_is_empty(entry->backup_path)) { - size_t _len; char timestamp[128]; - timestamp[0] = '\0'; /* Get timestamp and crc strings */ - _len = core_backup_list_get_entry_timestamp_str( + size_t _len = core_backup_list_get_entry_timestamp_str( entry, date_separator, timestamp, sizeof(timestamp)); /* Append 'auto backup' tag to timestamp, if required */ @@ -1129,7 +1126,6 @@ static unsigned menu_displaylist_parse_core_backup_list( settings_type, 0, 0, NULL)) { char crc[16]; - crc[0] = '\0'; snprintf(crc, sizeof(crc), "%08lx", (unsigned long)entry->crc); /* We need to set backup path, timestamp and crc * > Only have 2 useable fields as standard @@ -2544,7 +2540,7 @@ static int menu_displaylist_parse_playlist( for (i = 0; i < list_size; i++) { - char menu_entry_label[NAME_MAX_LENGTH]; + char menu_entry_lbl[NAME_MAX_LENGTH]; const struct playlist_entry *entry = NULL; const char *entry_path = NULL; bool entry_valid = true; @@ -2562,16 +2558,16 @@ static int menu_displaylist_parse_playlist( * no further action is necessary */ if (string_is_empty(entry->label)) - _len = fill_pathname(menu_entry_label, + _len = fill_pathname(menu_entry_lbl, path_basename(entry->path), "", - sizeof(menu_entry_label)); + sizeof(menu_entry_lbl)); else - _len = strlcpy(menu_entry_label, + _len = strlcpy(menu_entry_lbl, entry->label, - sizeof(menu_entry_label)); + sizeof(menu_entry_lbl)); if (sanitization) - (*sanitization)(menu_entry_label); + (*sanitization)(menu_entry_lbl); if (show_inline_core_name) { @@ -2582,12 +2578,12 @@ static int menu_displaylist_parse_playlist( && !string_is_equal(entry->core_path, "DETECT")) { _len += strlcpy( - menu_entry_label + _len, + menu_entry_lbl + _len, label_spacer, - sizeof(menu_entry_label) - _len); - strlcpy(menu_entry_label + _len, + sizeof(menu_entry_lbl) - _len); + strlcpy(menu_entry_lbl + _len, entry->core_name, - sizeof(menu_entry_label) - _len); + sizeof(menu_entry_lbl) - _len); } } @@ -2602,9 +2598,9 @@ static int menu_displaylist_parse_playlist( * > Use label if available, otherwise core name * > If both are missing, add an empty menu entry */ if (!string_is_empty(entry->label)) - strlcpy(menu_entry_label, entry->label, sizeof(menu_entry_label)); + strlcpy(menu_entry_lbl, entry->label, sizeof(menu_entry_lbl)); else if (!string_is_empty(entry->core_name)) - strlcpy(menu_entry_label, entry->core_name, sizeof(menu_entry_label)); + strlcpy(menu_entry_lbl, entry->core_name, sizeof(menu_entry_lbl)); entry_path = path_playlist; } @@ -2620,7 +2616,7 @@ static int menu_displaylist_parse_playlist( const char *search_term = search_terms->terms[j]; if ( !string_is_empty(search_term) - && !strcasestr(menu_entry_label, search_term)) + && !strcasestr(menu_entry_lbl, search_term)) { entry_valid = false; break; @@ -2630,7 +2626,7 @@ static int menu_displaylist_parse_playlist( /* Add menu entry */ if (entry_valid && menu_entries_append(info_list, - menu_entry_label, entry_path, + menu_entry_lbl, entry_path, MENU_ENUM_LABEL_PLAYLIST_ENTRY, FILE_TYPE_RPL_ENTRY, 0, i, NULL)) count++; } @@ -2771,11 +2767,8 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, for (i = 0; i < db_info->count; i++) { char crc_str[20]; - char tmp[PATH_MAX_LENGTH]; database_info_t *db_info_entry = &db_info->list[i]; - crc_str[0] = tmp[0] = '\0'; - snprintf(crc_str, sizeof(crc_str), "%08lX", (unsigned long)db_info_entry->crc32); if (playlist) @@ -2832,6 +2825,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, if (db_info_entry->name) { + char tmp[NAME_MAX_LENGTH]; size_t _len = strlcpy(tmp, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RDB_ENTRY_NAME), sizeof(tmp)); @@ -2847,6 +2841,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, if (db_info_entry->description) { + char tmp[NAME_MAX_LENGTH]; size_t _len = strlcpy(tmp, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RDB_ENTRY_DESCRIPTION), sizeof(tmp)); @@ -2862,6 +2857,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, if (db_info_entry->genre) { + char tmp[NAME_MAX_LENGTH]; size_t _len = strlcpy(tmp, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RDB_ENTRY_GENRE), sizeof(tmp)); @@ -5661,7 +5657,7 @@ static int menu_displaylist_parse_input_select_reserved_device_list( file_list_t *info_list, const char *info_path, settings_t *settings) { - char device_label[NAME_MAX_LENGTH]; + char device_lbl[NAME_MAX_LENGTH]; const char *val_disabled = NULL; enum msg_hash_enums enum_idx = (enum msg_hash_enums)atoi(info_path); struct menu_state *menu_st = menu_state_get_ptr(); @@ -5670,9 +5666,9 @@ static int menu_displaylist_parse_input_select_reserved_device_list( unsigned count = 0; int i = 0; char reserved_device_name[sizeof(settings->arrays.input_reserved_devices[0])]; - bool device_added = false; + bool device_added = false; - device_label[0] = '\0'; + device_lbl[0] = '\0'; if (!settings || !setting) return 0; @@ -5681,15 +5677,17 @@ static int menu_displaylist_parse_input_select_reserved_device_list( if (string_is_empty(settings->arrays.input_reserved_devices[enum_idx - MENU_ENUM_LABEL_INPUT_DEVICE_RESERVED_DEVICE_NAME])) strlcpy(reserved_device_name, val_disabled, sizeof(reserved_device_name)); else - strlcpy(reserved_device_name, settings->arrays.input_reserved_devices[enum_idx - MENU_ENUM_LABEL_INPUT_DEVICE_RESERVED_DEVICE_NAME], sizeof(reserved_device_name)); + strlcpy(reserved_device_name, settings->arrays.input_reserved_devices[ + enum_idx - MENU_ENUM_LABEL_INPUT_DEVICE_RESERVED_DEVICE_NAME], + sizeof(reserved_device_name)); /* List elements: none/disabled, all existing reservations, all existing devices */ for (i = MAX_INPUT_DEVICES + MAX_USERS; i >= 0; --i) { - device_label[0] = '\0'; + device_lbl[0] = '\0'; if (i == MAX_INPUT_DEVICES + MAX_USERS) - strlcpy(device_label, val_disabled, sizeof(device_label)); + strlcpy(device_lbl, val_disabled, sizeof(device_lbl)); else if (i < MAX_INPUT_DEVICES) { const char *device_name = input_config_get_device_display_name(i) @@ -5699,12 +5697,12 @@ static int menu_displaylist_parse_input_select_reserved_device_list( if (!string_is_empty(device_name)) { unsigned idx = input_config_get_device_name_index(i); - size_t _len = strlcpy(device_label, device_name, - sizeof(device_label)); + size_t _len = strlcpy(device_lbl, device_name, + sizeof(device_lbl)); /* If idx is non-zero, it's part of a set*/ if (idx > 0) - snprintf(device_label + _len, - sizeof(device_label) - _len, " (#%u)", idx); + snprintf(device_lbl + _len, + sizeof(device_lbl) - _len, " (#%u)", idx); } } else @@ -5713,32 +5711,36 @@ static int menu_displaylist_parse_input_select_reserved_device_list( { unsigned int vendor_id; unsigned int product_id; - if (sscanf(settings->arrays.input_reserved_devices[i-MAX_INPUT_DEVICES], "%04x:%04x ", &vendor_id, &product_id) != 2) - strlcpy(device_label, settings->arrays.input_reserved_devices[i-MAX_INPUT_DEVICES], sizeof(reserved_device_name)); + if (sscanf(settings->arrays.input_reserved_devices[i-MAX_INPUT_DEVICES], + "%04x:%04x ", &vendor_id, &product_id) != 2) + strlcpy(device_lbl, + settings->arrays.input_reserved_devices[i-MAX_INPUT_DEVICES], + sizeof(reserved_device_name)); else /* If the vendor_id:product_id is encoded in the name, ignore them. */ - strlcpy(device_label, &settings->arrays.input_reserved_devices[i-MAX_INPUT_DEVICES][10], sizeof(reserved_device_name)); + strlcpy(device_lbl, + &settings->arrays.input_reserved_devices[i-MAX_INPUT_DEVICES][10], + sizeof(reserved_device_name)); } } - if (!string_is_empty(device_label)) + if (!string_is_empty(device_lbl)) { size_t previous_position; - if (file_list_search(info_list, device_label, &previous_position)) + if (file_list_search(info_list, device_lbl, &previous_position)) continue; /* Add menu entry */ if (menu_entries_append(info_list, - device_label, - device_label, - MSG_UNKNOWN, - MENU_SETTING_DROPDOWN_ITEM_INPUT_SELECT_RESERVED_DEVICE, - 0, menu_index, NULL)) + device_lbl, device_lbl, + MSG_UNKNOWN, + MENU_SETTING_DROPDOWN_ITEM_INPUT_SELECT_RESERVED_DEVICE, + 0, menu_index, NULL)) { /* Add checkmark if input is currently * mapped to this entry - with or without vid:pid prefix */ - if (string_is_equal(device_label, &reserved_device_name[10]) || - string_is_equal(device_label, reserved_device_name)) + if ( string_is_equal(device_lbl, &reserved_device_name[10]) + || string_is_equal(device_lbl, reserved_device_name)) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)info_list->list[menu_index].actiondata; if (cbs) @@ -5768,7 +5770,7 @@ static int menu_displaylist_parse_input_select_physical_keyboard_list( file_list_t *info_list, const char *info_path, settings_t *settings) { - char device_label[128]; + char device_lbl[128]; const char *val_disabled = NULL; enum msg_hash_enums enum_idx = (enum msg_hash_enums)atoi(info_path); struct menu_state *menu_st = menu_state_get_ptr(); @@ -5782,7 +5784,7 @@ static int menu_displaylist_parse_input_select_physical_keyboard_list( input_driver_t *current_input = st->current_driver; bool is_android_driver = string_is_equal(current_input->ident, "android"); - device_label[0] = '\0'; + device_lbl[0] = '\0'; if (!settings || !setting || !is_android_driver) return 0; @@ -5803,12 +5805,12 @@ static int menu_displaylist_parse_input_select_physical_keyboard_list( for (i = MAX_INPUT_DEVICES; i >= -1; --i) { - device_label[0] = '\0'; + device_lbl[0] = '\0'; if (i < 0) - strlcpy(device_label, keyboard, sizeof(device_label)); + strlcpy(device_lbl, keyboard, sizeof(device_lbl)); else if (i == MAX_INPUT_DEVICES) - strlcpy(device_label, val_disabled, sizeof(device_label)); + strlcpy(device_lbl, val_disabled, sizeof(device_lbl)); else if (i < MAX_INPUT_DEVICES) { /* @@ -5824,32 +5826,32 @@ static int menu_displaylist_parse_input_select_physical_keyboard_list( if (!string_is_empty(device_name)) { unsigned idx = input_config_get_device_name_index(i); - size_t _len = strlcpy(device_label, device_name, - sizeof(device_label)); + size_t _len = strlcpy(device_lbl, device_name, + sizeof(device_lbl)); /* If idx is non-zero, it's part of a set*/ if (idx > 0) - snprintf(device_label + _len, - sizeof(device_label) - _len, " (#%u)", idx); + snprintf(device_lbl + _len, + sizeof(device_lbl) - _len, " (#%u)", idx); } } - if (!string_is_empty(device_label)) + if (!string_is_empty(device_lbl)) { size_t previous_position; - if (file_list_search(info_list, device_label, &previous_position)) + if (file_list_search(info_list, device_lbl, &previous_position)) continue; /* Add menu entry */ if (menu_entries_append(info_list, - device_label, - device_label, + device_lbl, + device_lbl, MSG_UNKNOWN, MENU_SETTING_DROPDOWN_ITEM_INPUT_SELECT_PHYSICAL_KEYBOARD, 0, menu_index, NULL)) { /* Add checkmark if input is currently * mapped to this entry */ - if (string_is_equal(device_label, keyboard)) + if (string_is_equal(device_lbl, keyboard)) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)info_list->list[menu_index].actiondata; if (cbs) @@ -5880,7 +5882,7 @@ static int menu_displaylist_parse_input_description_list( menu_displaylist_info_t *info, settings_t *settings) { size_t i, j; - char entry_label[21]; + char entry_lbl[21]; unsigned user_idx; unsigned btn_idx; unsigned current_remap_idx; @@ -5891,7 +5893,7 @@ static int menu_displaylist_parse_input_description_list( bool current_input_mapped = false; struct menu_state *menu_st = menu_state_get_ptr(); - entry_label[0] = '\0'; + entry_lbl[0] = '\0'; if (!settings) return 0; @@ -5922,7 +5924,7 @@ static int menu_displaylist_parse_input_description_list( * We need to record the current user/button indices, * and so have to convert 'info->type' to a string * and pass it as the entry label... */ - snprintf(entry_label, sizeof(entry_label), "%u", info->type); + snprintf(entry_lbl, sizeof(entry_lbl), "%u", info->type); /* Loop over core input definitions */ for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++) @@ -5961,7 +5963,7 @@ static int menu_displaylist_parse_input_description_list( /* Add menu entry */ if (menu_entries_append(info->list, input_description, - entry_label, + entry_lbl, MENU_ENUM_LABEL_INPUT_DESCRIPTION, MENU_SETTING_DROPDOWN_ITEM_INPUT_DESCRIPTION, 0, i, NULL)) @@ -5986,7 +5988,7 @@ static int menu_displaylist_parse_input_description_list( /* Add 'unmapped' entry at end of list */ if (menu_entries_append(info->list, "---", - entry_label, + entry_lbl, MENU_ENUM_LABEL_INPUT_DESCRIPTION, MENU_SETTING_DROPDOWN_ITEM_INPUT_DESCRIPTION, 0, RARCH_UNMAPPED, NULL)) @@ -6047,14 +6049,14 @@ static int menu_displaylist_parse_input_description_kbd_list( file_list_t *info_list, unsigned info_type, settings_t *settings) { size_t i; - char entry_label[21]; + char entry_lbl[21]; unsigned current_key_id; unsigned user_idx, btn_idx; unsigned count = 0; size_t menu_index = 0; struct menu_state *menu_st = menu_state_get_ptr(); - entry_label[0] = '\0'; + entry_lbl[0] = '\0'; if (!settings) return 0; @@ -6080,7 +6082,7 @@ static int menu_displaylist_parse_input_description_kbd_list( * We need to record the current user/button indices, * and so have to convert 'info_type' to a string * and pass it as the entry label... */ - snprintf(entry_label, sizeof(entry_label), "%u", info_type); + snprintf(entry_lbl, sizeof(entry_lbl), "%u", info_type); /* Loop over keyboard keys */ for (i = 0; i < RARCH_MAX_KEYS; i++) @@ -6107,7 +6109,7 @@ static int menu_displaylist_parse_input_description_kbd_list( } /* Add menu entry */ - if (menu_entries_append(info_list, input_description, entry_label, + if (menu_entries_append(info_list, input_description, entry_lbl, MENU_ENUM_LABEL_INPUT_DESCRIPTION_KBD, MENU_SETTING_DROPDOWN_ITEM_INPUT_DESCRIPTION_KBD, 0, key_id, NULL)) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 2a34734eba1d..b80c13c49fbd 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -3040,16 +3040,12 @@ bool menu_shader_manager_save_preset(const struct video_shader *shader, const char *preset_dirs[3] = {0}; settings_t *settings = config_get_ptr(); - - if (!path_is_empty(RARCH_PATH_CONFIG)) - { - strlcpy(config_directory, + if (path_is_empty(RARCH_PATH_CONFIG)) + config_directory[0] = '\0'; + else + fill_pathname_basedir(config_directory, path_get(RARCH_PATH_CONFIG), sizeof(config_directory)); - path_basedir(config_directory); - } - else - config_directory[0] = '\0'; preset_dirs[0] = dir_video_shader; preset_dirs[1] = dir_menu_config; @@ -3098,15 +3094,13 @@ static bool menu_shader_manager_operate_auto_preset( || (type == SHADER_PRESET_PARENT))) return false; - if (!path_is_empty(RARCH_PATH_CONFIG)) - { - strlcpy(config_directory, + if (path_is_empty(RARCH_PATH_CONFIG)) + config_directory[0] = '\0'; + else + fill_pathname_basedir( + config_directory, path_get(RARCH_PATH_CONFIG), sizeof(config_directory)); - path_basedir(config_directory); - } - else - config_directory[0] = '\0'; /* We are only including this directory for compatibility purposes with * versions 1.8.7 and older. */ @@ -4615,7 +4609,11 @@ void menu_entries_get_core_title(char *s, size_t len) _len += strlcpy(s + _len, " - ", len - _len); _len += strlcpy(s + _len, core_name, len - _len); if (!string_is_empty(core_version)) - snprintf(s + _len, len - _len, " (%s)", core_version); + { + _len += strlcpy(s + _len, " (", len - _len); + _len += strlcpy(s + _len, core_version, len - _len); + strlcpy(s + _len, ")", len - _len); + } } static bool menu_driver_init_internal( diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 94350a896a8a..1795bef97856 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -2572,7 +2572,7 @@ static int setting_action_ok_bind_all_save_autoconfig( char buf[128]; char msg[NAME_MAX_LENGTH]; config_get_autoconf_profile_filename(name, index_offset, buf, sizeof(buf)); - snprintf(msg, sizeof(msg),msg_hash_to_str(MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY_NAMED),buf); + snprintf(msg, sizeof(msg),msg_hash_to_str(MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY_NAMED), buf); runloop_msg_queue_push( msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); @@ -2980,10 +2980,10 @@ static void setting_get_string_representation_state_slot(rarch_setting_t *settin { if (!setting) return; - - snprintf(s, len, "%d", *setting->value.target.integer); if (*setting->value.target.integer == -1) strlcpy(s, "Auto", len); + else + snprintf(s, len, "%d", *setting->value.target.integer); } static void setting_get_string_representation_percentage(rarch_setting_t *setting, @@ -5010,34 +5010,33 @@ static void setting_get_string_representation_uint_custom_viewport_height(rarch_ static void setting_get_string_representation_uint_audio_wasapi_sh_buffer_length(rarch_setting_t *setting, char *s, size_t len) { + size_t _len; settings_t *settings = config_get_ptr(); if (!setting || !settings) return; + _len = snprintf(s, len, "%u (", *setting->value.target.integer); switch (*setting->value.target.integer) { case WASAPI_SH_BUFFER_AUDIO_LATENCY: - snprintf(s, len, "%u (%s)", - *setting->value.target.integer, - "Audio Latency"); + /* TODO/FIXME - localize */ + _len += strlcpy(s + _len, "Audio Latency", len - _len); break; case WASAPI_SH_BUFFER_DEVICE_PERIOD: - snprintf(s, len, "%u (%s)", - *setting->value.target.integer, - "Device Period"); + /* TODO/FIXME - localize */ + _len += strlcpy(s + _len, "Device Period", len - _len); break; case WASAPI_SH_BUFFER_CLIENT_BUFFER: - snprintf(s, len, "%u (%s)", - *setting->value.target.integer, - "Client Buffer"); + /* TODO/FIXME - localize */ + _len += strlcpy(s + _len, "Client Buffer", len - _len); break; default: - snprintf(s, len, "%u (%.1f ms)", - *setting->value.target.integer, + _len += snprintf(s + _len, len - _len, "%.1f ms", (float)*setting->value.target.integer * 1000 / settings->uints.audio_output_sample_rate); break; } + strlcpy(s + _len, ")", len - _len); } #ifdef HAVE_MICROPHONE @@ -6715,9 +6714,11 @@ static void setting_get_string_representation_video_frame_delay(rarch_setting_t target_unit, (unsigned)(1 / settings->floats.video_refresh_rate * 1000 * (*setting->value.target.unsigned_integer / 100.0f))); else - snprintf(s, len, "%u%s", - *setting->value.target.unsigned_integer, - target_unit); + { + size_t _len = snprintf(s, len, "%u", + *setting->value.target.unsigned_integer); + strlcpy(s + _len, target_unit, len - _len); + } } else { @@ -6739,17 +6740,13 @@ static void setting_get_string_representation_video_frame_delay(rarch_setting_t } else { - const char *target_unit = (*setting->value.target.unsigned_integer >= 20 ? "\%" : "ms"); - + const char *target_unit = (*setting->value.target.unsigned_integer >= 20 ? "\%" : "ms"); + size_t _len = snprintf(s, len, "%u", + *setting->value.target.unsigned_integer); + _len += strlcpy(s + _len, target_unit, len - _len); if (*setting->value.target.unsigned_integer >= 20) - snprintf(s, len, "%u%s (%ums)", - *setting->value.target.unsigned_integer, - target_unit, + snprintf(s + _len, len - _len, " (%ums)", (unsigned)(1 / settings->floats.video_refresh_rate * 1000 * (*setting->value.target.unsigned_integer / 100.0f))); - else - snprintf(s, len, "%u%s", - *setting->value.target.unsigned_integer, - target_unit); } } @@ -9959,7 +9956,10 @@ static bool setting_append_list_input_player_options( input_config_bind_map_get_desc(i), sizeof(label) - _len); - snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(i)); + _len = snprintf(name, sizeof(name), "p%u_", user + 1); + strlcpy(name + _len, + input_config_bind_map_get_base(i), + sizeof(name) - _len); CONFIG_BIND_ALT( list, list_info, @@ -16152,7 +16152,7 @@ static bool setting_append_list( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_USER_BINDS); for (user = 0; user < MAX_USERS; user++) { - static char binds_list[MAX_USERS][NAME_MAX_LENGTH]; + static char binds_list[MAX_USERS][64]; static char binds_label[MAX_USERS][NAME_MAX_LENGTH]; unsigned user_value = user + 1; size_t _len = snprintf(binds_list[user], sizeof(binds_list[user]), "%d", user_value); diff --git a/runloop.c b/runloop.c index 037169cf32ce..3f01fd1d9a9a 100644 --- a/runloop.c +++ b/runloop.c @@ -4197,7 +4197,6 @@ static void runloop_path_init_savefile_internal(runloop_state_t *runloop_st) { path_deinit_savefile(); path_init_savefile_new(); - if (!runloop_path_init_subsystem(runloop_st)) path_init_savefile_rtc(runloop_st->name.savefile); } @@ -7893,7 +7892,7 @@ void runloop_path_set_redirect(settings_t *settings, /* Get content directory name, if per-content-directory * saves/states are enabled */ - if ((sort_savefiles_by_content_enable + if (( sort_savefiles_by_content_enable || sort_savestates_by_content_enable) && !string_is_empty(runloop_st->runtime_content_path_basename)) fill_pathname_parent_dir_name(content_dir_name, diff --git a/runtime_file.c b/runtime_file.c index 42a0ad76e5de..746df908e278 100644 --- a/runtime_file.c +++ b/runtime_file.c @@ -497,11 +497,9 @@ void runtime_log_get_runtime_str(runtime_log_t *runtime_log, len); s[_len ] = ' '; if (runtime_log) - { snprintf(s + _len + 1, len - _len - 1, "%02u:%02u:%02u", runtime_log->runtime.hours, runtime_log->runtime.minutes, runtime_log->runtime.seconds); - } else { s[_len+1] = '0'; diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index b029166e2c7a..92a97b0762af 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -120,11 +120,12 @@ static unsigned input_autoconfigure_get_config_file_affinity( unsigned max_affinity = 0; struct config_entry_list *entry = NULL; char config_key[30]; - char config_key_postfix[7]; /* One main entry and up to 9 alternatives */ for (i=0 ; i < 10; i++) { + size_t _len; + char config_key_postfix[7]; config_vid = 0; config_pid = 0; tmp_int = 0; @@ -135,15 +136,19 @@ static unsigned input_autoconfigure_get_config_file_affinity( else snprintf(config_key_postfix, sizeof(config_key_postfix), "_alt%d",i); - + /* Parse config file */ - snprintf(config_key, sizeof(config_key), - "input_vendor_id%s",config_key_postfix); + _len = strlcpy(config_key, "input_vendor_id", + sizeof(config_key)); + _len += strlcpy(config_key + _len, config_key_postfix, + sizeof(config_key) - _len); if (config_get_int(config, config_key, &tmp_int)) config_vid = (uint16_t)tmp_int; - snprintf(config_key, sizeof(config_key), - "input_product_id%s",config_key_postfix); + _len = strlcpy(config_key, "input_product_id", + sizeof(config_key)); + _len += strlcpy(config_key + _len, config_key_postfix, + sizeof(config_key) - _len); if (config_get_int(config, config_key, &tmp_int)) config_pid = (uint16_t)tmp_int; @@ -170,8 +175,10 @@ static unsigned input_autoconfigure_get_config_file_affinity( affinity += 3; /* Check for matching device name */ - snprintf(config_key, sizeof(config_key), - "input_device%s",config_key_postfix); + _len = strlcpy(config_key, "input_device", + sizeof(config_key)); + _len += strlcpy(config_key + _len, config_key_postfix, + sizeof(config_key) - _len); if ( (entry = config_get_entry(config, config_key)) && !string_is_empty(entry->value) && string_is_equal(entry->value, diff --git a/tasks/task_overlay.c b/tasks/task_overlay.c index c10fb73f6906..b369c1546e68 100644 --- a/tasks/task_overlay.c +++ b/tasks/task_overlay.c @@ -124,7 +124,6 @@ static void task_overlay_desc_populate_eightway_config( size_t _len; input_driver_state_t *input_st = input_state_get_ptr(); overlay_eightway_config_t *eightway; - char conf_key_base[20]; char conf_key[64]; char *str; @@ -162,11 +161,10 @@ static void task_overlay_desc_populate_eightway_config( return; } - snprintf(conf_key_base, sizeof(conf_key_base), "overlay%u_desc%u", ol_idx, desc_idx); + _len = snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u", ol_idx, desc_idx); /* Redefine eightway vals if specified in conf */ - _len = strlcpy(conf_key, conf_key_base, sizeof(conf_key)); strlcpy(conf_key + _len, "_up", sizeof(conf_key) - _len); if (config_get_string(loader->conf, conf_key, &str)) { @@ -683,7 +681,6 @@ static void task_overlay_deferred_load(retro_task_t *task) for (i = 0; i < loader->pos_increment; i++, loader->pos++) { size_t _len; - char conf_key_base[10]; char conf_key[32]; char tmp_str[PATH_MAX_LENGTH]; float tmp_float = 0.0; @@ -704,8 +701,7 @@ static void task_overlay_deferred_load(retro_task_t *task) overlay = &loader->overlays[loader->pos]; - snprintf(conf_key_base, sizeof(conf_key_base), "overlay%u", loader->pos); - _len = strlcpy(conf_key, conf_key_base, sizeof(conf_key)); + _len = snprintf(conf_key, sizeof(conf_key), "overlay%u", loader->pos); strlcpy(conf_key + _len, "_rect", sizeof(conf_key) - _len); strlcpy(overlay->config.rect.key, conf_key, diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index 1bb1d3413f51..115b38ce6a9a 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -136,13 +136,12 @@ static void gfx_thumbnail_get_db_name( *db_name = path_data->content_db_name; } - /* Fetches local and remote paths for current thumbnail * of current type */ static bool task_pl_thumbnail_get_thumbnail_paths( pl_thumb_handle_t *pl_thumb, char *path, size_t path_size, - char *url, size_t url_size) + char *s, size_t len) { char content_dir[DIR_MAX_LENGTH]; char tmp_buf[PATH_MAX_LENGTH]; @@ -210,10 +209,7 @@ static bool task_pl_thumbnail_get_thumbnail_paths( /* Generate remote path */ snprintf(raw_url, raw_url_len, "%s/%s/%s/%s", FILE_PATH_CORE_THUMBNAILS_URL, - system_name, - sub_dir, - img_name - ); + system_name, sub_dir, img_name); if (string_is_empty(raw_url)) { @@ -221,10 +217,10 @@ static bool task_pl_thumbnail_get_thumbnail_paths( return false; } - net_http_urlencode_full(url, raw_url, url_size); + net_http_urlencode_full(s, raw_url, len); free(raw_url); - return !string_is_empty(url); + return !string_is_empty(s); } /* Thumbnail download http task callback function diff --git a/tasks/task_save.c b/tasks/task_save.c index 27fc6c3b9435..94fad0b3cf63 100644 --- a/tasks/task_save.c +++ b/tasks/task_save.c @@ -581,8 +581,6 @@ static void task_save_handler(retro_task_t *task) else { char new_msg[128]; - new_msg[0] = '\0'; - snprintf(new_msg, sizeof(new_msg), msg_hash_to_str(MSG_SAVED_STATE_TO_SLOT), state->state_slot); diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index a4f24f738b5b..571453fd0871 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -2454,6 +2454,7 @@ QVector > MainWindow::getCoreInfo() if (core_info->firmware_count > 0) { + char tmp_path[PATH_MAX_LENGTH]; core_info_ctx_firmware_t firmware_info; bool update_missing_firmware = false; bool set_missing_firmware = false; @@ -2461,7 +2462,6 @@ QVector > MainWindow::getCoreInfo() uint8_t flags = content_get_flags(); bool systemfiles_in_content_dir = settings->bools.systemfiles_in_content_dir; bool content_is_inited = flags & CONTENT_ST_FLAG_IS_INITED; - char tmp_path[PATH_MAX_LENGTH]; firmware_info.path = core_info->path; @@ -2469,8 +2469,9 @@ QVector > MainWindow::getCoreInfo() * adjust the path to check for firmware files */ if (systemfiles_in_content_dir && content_is_inited) { - strlcpy(tmp_path, path_get(RARCH_PATH_CONTENT), sizeof(tmp_path)); - path_basedir(tmp_path); + fill_pathname_basedir(tmp_path, + path_get(RARCH_PATH_CONTENT), + sizeof(tmp_path)); /* If content path is empty, fall back to global system dir path */ if (string_is_empty(tmp_path))