From bd090dea714d481085f3fbd9d60cd3c03dc6ec8d Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sun, 16 Jul 2023 18:07:49 +0200 Subject: [PATCH] Replace more strlcat calls --- frontend/drivers/platform_darwin.m | 24 +++++---- frontend/drivers/platform_switch.c | 9 ++-- frontend/drivers/platform_unix.c | 10 ++-- frontend/drivers/platform_uwp.c | 39 ++++++++------- frontend/drivers/platform_win32.c | 66 ++++++++++++------------- gfx/drivers_shader/shader_gl_cg.c | 4 +- gfx/drivers_shader/slang_reflection.cpp | 4 +- gfx/gfx_thumbnail_path.c | 4 +- gfx/gfx_thumbnail_path.h | 2 +- intl/msg_hash_chs.c | 5 +- intl/msg_hash_pt_br.c | 54 ++++++++++---------- manual_content_scan.c | 2 +- network/discord.c | 12 ++--- network/natt.c | 8 +-- network/netplay/netplay_frontend.c | 13 +++-- tasks/task_database_cue.c | 6 ++- tasks/task_playlist_manager.c | 2 +- ui/drivers/ui_qt.cpp | 6 +-- verbosity.c | 4 +- 19 files changed, 134 insertions(+), 140 deletions(-) diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index 46b3faa301..f6602e0320 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -296,7 +296,7 @@ static void frontend_darwin_get_os(char *s, size_t len, int *major, int *minor) #endif #elif defined(OSX) -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 // MAC_OS_X_VERSION_10_13 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 /* MAC_OS_X_VERSION_10_13 */ NSOperatingSystemVersion version = NSProcessInfo.processInfo.operatingSystemVersion; *major = (int)version.majorVersion; *minor = (int)version.minorVersion; @@ -355,7 +355,7 @@ static void frontend_darwin_get_env(int *argc, char *argv[], CFRelease(bundle_url); #if HAVE_STEAM - // for steam we're going to put everything next to the .app + /* For Steam, we're going to put everything next to the .app */ fill_pathname_application_data(documents_dir_buf, sizeof(documents_dir_buf)); #else CFSearchPathForDirectoriesInDomains(documents_dir_buf, sizeof(documents_dir_buf)); @@ -377,16 +377,16 @@ static void frontend_darwin_get_env(int *argc, char *argv[], #if defined(OSX) fill_pathname_application_data(application_data, sizeof(application_data)); #else - // ios and tvos are going to put everything in the documents dir + /* iOS and tvOS are going to put everything in the documents dir */ strncpy(application_data, documents_dir_buf, sizeof(application_data)); #endif - // By the time we are here: - // bundle_path_buf is the full path of the .app - // documents_dir_buf is where user documents go (macos: ~/Documents/RetroArch) - // application_data is where "hidden" app data goes (macos: ~/Library/Application Support/RetroArch, ios: documents dir) + /* By the time we are here: + * bundle_path_buf is the full path of the .app + * documents_dir_buf is where user documents go (macos: ~/Documents/RetroArch) + * application_data is where "hidden" app data goes (macos: ~/Library/Application Support/RetroArch, ios: documents dir) - // this stuff we expect the user to find easily, possibly sync across iCloud + * this stuff we expect the user to find easily, possibly sync across iCloud */ fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_LOGS], documents_dir_buf, "logs", sizeof(g_defaults.dirs[DEFAULT_DIR_LOGS])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_PLAYLIST], documents_dir_buf, "playlists", sizeof(g_defaults.dirs[DEFAULT_DIR_PLAYLIST])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_RECORD_OUTPUT], documents_dir_buf, "records", sizeof(g_defaults.dirs[DEFAULT_DIR_RECORD_OUTPUT])); @@ -441,16 +441,14 @@ static void frontend_darwin_get_env(int *argc, char *argv[], fill_pathname_join_special(assets_zip_path, bundle_path_buf, "assets.zip", sizeof(assets_zip_path)); #else - CFURLRef resource_url; - CFStringRef resource_path; + char full_resource_path_buf[PATH_MAX_LENGTH]; char resource_path_buf[PATH_MAX_LENGTH] = {0}; - resource_url = CFBundleCopyResourcesDirectoryURL(bundle); - resource_path = CFURLCopyPath(resource_url); + CFURLRef resource_url = CFBundleCopyResourcesDirectoryURL(bundle); + CFStringRef resource_path = CFURLCopyPath(resource_url); CFStringGetCString(resource_path, resource_path_buf, sizeof(resource_path_buf), kCFStringEncodingUTF8); CFRelease(resource_path); CFRelease(resource_url); - char full_resource_path_buf[PATH_MAX_LENGTH]; fill_pathname_join_special(full_resource_path_buf, bundle_path_buf, resource_path_buf, sizeof(full_resource_path_buf)); fill_pathname_join_special(assets_zip_path, diff --git a/frontend/drivers/platform_switch.c b/frontend/drivers/platform_switch.c index 6ca3accde5..78d04bc4d7 100644 --- a/frontend/drivers/platform_switch.c +++ b/frontend/drivers/platform_switch.c @@ -172,10 +172,10 @@ static void get_first_valid_core(char *path_return, size_t len) if (strlen(ent->d_name) > strlen(extension) && !strcmp(ent->d_name + strlen(ent->d_name) - strlen(extension), extension)) { size_t _len = strlcpy(path_return, SD_PREFIX "/retroarch/cores", len); - strlcpy(path_return + _len, + _len += strlcpy(path_return + _len, "/", len - _len); - strlcat(path_return, ent->d_name, len); + strlcpy(path_return + _len, ent->d_name, len - _len); break; } } @@ -328,19 +328,16 @@ static void frontend_switch_exec(const char *path, bool should_load_game) const char *content = path_get(RARCH_PATH_CONTENT); #ifdef HAVE_NETWORKING char *arg_data[NETPLAY_FORK_MAX_ARGS]; - if (netplay_driver_ctl(RARCH_NETPLAY_CTL_GET_FORK_ARGS, (void*)arg_data)) { char buf[PATH_MAX]; char **arg = arg_data; - do { snprintf(buf, sizeof(buf), " \"%s\"", *arg); strlcat(args, buf, sizeof(args)); - } - while (*(++arg)); + } while (*(++arg)); } else #endif diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c index 0b90c0f47e..79d3e31605 100644 --- a/frontend/drivers/platform_unix.c +++ b/frontend/drivers/platform_unix.c @@ -167,10 +167,10 @@ int system_property_get(const char *command, char *curpos = NULL; size_t buf_pos = strlcpy(cmd, command, sizeof(cmd)); - cmd[buf_pos] = ' '; - cmd[buf_pos+1] = '\0'; + cmd[ buf_pos] = ' '; + cmd[++buf_pos] = '\0'; - buf_pos = strlcat(cmd, args, sizeof(cmd)); + strlcpy(cmd + buf_pos, args, sizeof(cmd) - buf_pos); if (!(pipe = popen(cmd, "r"))) { @@ -2246,8 +2246,8 @@ static int frontend_unix_parse_drive_list(void *data, bool load_content) size_t _len = strlcpy(udisks_media_path, "/run/media", sizeof(udisks_media_path)); if (user) { - strlcpy(udisks_media_path + _len, "/", sizeof(udisks_media_path) - _len); - strlcat(udisks_media_path, user, sizeof(udisks_media_path)); + _len += strlcpy(udisks_media_path + _len, "/", sizeof(udisks_media_path) - _len); + strlcpy(udisks_media_path + _len, user, sizeof(udisks_media_path) - _len); } } diff --git a/frontend/drivers/platform_uwp.c b/frontend/drivers/platform_uwp.c index 662281427d..9c55c3a2b1 100644 --- a/frontend/drivers/platform_uwp.c +++ b/frontend/drivers/platform_uwp.c @@ -49,6 +49,7 @@ static void frontend_uwp_get_os(char *s, size_t len, int *major, int *minor) { + size_t _len; char build_str[11] = {0}; bool server = false; const char *arch = ""; @@ -95,65 +96,65 @@ static void frontend_uwp_get_os(char *s, size_t len, int *major, int *minor) { case 10: if (server) - strlcpy(s, "Windows Server 2016", len); + _len = strlcpy(s, "Windows Server 2016", len); else - strlcpy(s, "Windows 10", len); + _len = strlcpy(s, "Windows 10", len); break; case 6: switch (vi.dwMinorVersion) { case 3: if (server) - strlcpy(s, "Windows Server 2012 R2", len); + _len = strlcpy(s, "Windows Server 2012 R2", len); else - strlcpy(s, "Windows 8.1", len); + _len = strlcpy(s, "Windows 8.1", len); break; case 2: if (server) - strlcpy(s, "Windows Server 2012", len); + _len = strlcpy(s, "Windows Server 2012", len); else - strlcpy(s, "Windows 8", len); + _len = strlcpy(s, "Windows 8", len); break; case 1: if (server) - strlcpy(s, "Windows Server 2008 R2", len); + _len = strlcpy(s, "Windows Server 2008 R2", len); else - strlcpy(s, "Windows 7", len); + _len = strlcpy(s, "Windows 7", len); break; case 0: if (server) - strlcpy(s, "Windows Server 2008", len); + _len = strlcpy(s, "Windows Server 2008", len); else - strlcpy(s, "Windows Vista", len); + _len = strlcpy(s, "Windows Vista", len); break; default: break; } break; default: - snprintf(s, len, "Windows %i.%i", *major, *minor); + _len = snprintf(s, len, "Windows %i.%i", *major, *minor); break; } if (!string_is_empty(arch)) { - strlcat(s, " ", len); - strlcat(s, arch, len); + _len += strlcpy(s + _len, " ", len - _len); + _len += strlcpy(s + _len, arch, len - _len); } - strlcat(s, " Build ", len); - strlcat(s, build_str, len); + _len += strlcpy(s + _len, " Build ", len - _len); + _len += strlcpy(s + _len, build_str, len - _len); if (!string_is_empty(vi.szCSDVersion)) { - strlcat(s, " ", len); - strlcat(s, vi.szCSDVersion, len); + _len += strlcpy(s + _len, " ", len - _len); + _len += strlcpy(s + _len, vi.szCSDVersion, len - _len); } if (!string_is_empty(uwp_device_family)) { - strlcat(s, " ", len); - strlcat(s, uwp_device_family, len); + _len += strlcpy(s + _len, " ", len - _len); + strlcpy(s + _len, uwp_device_family, len - _len); } } diff --git a/frontend/drivers/platform_win32.c b/frontend/drivers/platform_win32.c index 2a50e52800..94e45b3610 100644 --- a/frontend/drivers/platform_win32.c +++ b/frontend/drivers/platform_win32.c @@ -269,7 +269,8 @@ static void gfx_set_dwm(void) static void frontend_win32_get_os(char *s, size_t len, int *major, int *minor) { - char buildStr[11] = {0}; + size_t _len; + char build_str[11] = {0}; bool server = false; const char *arch = ""; @@ -315,46 +316,46 @@ static void frontend_win32_get_os(char *s, size_t len, int *major, int *minor) *minor = vi.dwMinorVersion; if (vi.dwMajorVersion == 4 && vi.dwMinorVersion == 0) - snprintf(buildStr, sizeof(buildStr), "%lu", (DWORD)(LOWORD(vi.dwBuildNumber))); /* Windows 95 build number is in the low-order word only */ + snprintf(build_str, sizeof(build_str), "%lu", (DWORD)(LOWORD(vi.dwBuildNumber))); /* Windows 95 build number is in the low-order word only */ else - snprintf(buildStr, sizeof(buildStr), "%lu", vi.dwBuildNumber); + snprintf(build_str, sizeof(build_str), "%lu", vi.dwBuildNumber); switch (vi.dwMajorVersion) { case 10: - if (atoi(buildStr) >= 21996) - strlcpy(s, "Windows 11", len); + if (atoi(build_str) >= 21996) + _len = strlcpy(s, "Windows 11", len); else if (server) - strlcpy(s, "Windows Server 2016", len); + _len = strlcpy(s, "Windows Server 2016", len); else - strlcpy(s, "Windows 10", len); + _len = strlcpy(s, "Windows 10", len); break; case 6: switch (vi.dwMinorVersion) { case 3: if (server) - strlcpy(s, "Windows Server 2012 R2", len); + _len = strlcpy(s, "Windows Server 2012 R2", len); else - strlcpy(s, "Windows 8.1", len); + _len = strlcpy(s, "Windows 8.1", len); break; case 2: if (server) - strlcpy(s, "Windows Server 2012", len); + _len = strlcpy(s, "Windows Server 2012", len); else - strlcpy(s, "Windows 8", len); + _len = strlcpy(s, "Windows 8", len); break; case 1: if (server) - strlcpy(s, "Windows Server 2008 R2", len); + _len = strlcpy(s, "Windows Server 2008 R2", len); else - strlcpy(s, "Windows 7", len); + _len = strlcpy(s, "Windows 7", len); break; case 0: if (server) - strlcpy(s, "Windows Server 2008", len); + _len = strlcpy(s, "Windows Server 2008", len); else - strlcpy(s, "Windows Vista", len); + _len = strlcpy(s, "Windows Vista", len); break; default: break; @@ -366,22 +367,22 @@ static void frontend_win32_get_os(char *s, size_t len, int *major, int *minor) case 2: if (server) { - size_t _len = strlcpy(s, "Windows Server 2003", len); + _len = strlcpy(s, "Windows Server 2003", len); if (GetSystemMetrics(SM_SERVERR2)) - strlcpy(s + _len, " R2", len - _len); + _len += strlcpy(s + _len, " R2", len - _len); } else { /* Yes, XP Pro x64 is a higher version number than XP x86 */ if (string_is_equal(arch, "x64")) - strlcpy(s, "Windows XP", len); + _len = strlcpy(s, "Windows XP", len); } break; case 1: - strlcpy(s, "Windows XP", len); + _len = strlcpy(s, "Windows XP", len); break; case 0: - strlcpy(s, "Windows 2000", len); + _len = strlcpy(s, "Windows 2000", len); break; } break; @@ -390,40 +391,39 @@ static void frontend_win32_get_os(char *s, size_t len, int *major, int *minor) { case 0: if (vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) - strlcpy(s, "Windows 95", len); + _len = strlcpy(s, "Windows 95", len); else if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) - strlcpy(s, "Windows NT 4.0", len); + _len = strlcpy(s, "Windows NT 4.0", len); else - strlcpy(s, "Unknown", len); + _len = strlcpy(s, "Unknown", len); break; case 90: - strlcpy(s, "Windows ME", len); + _len = strlcpy(s, "Windows ME", len); break; case 10: - strlcpy(s, "Windows 98", len); + _len = strlcpy(s, "Windows 98", len); break; } break; default: - snprintf(s, len, "Windows %i.%i", *major, *minor); + _len = snprintf(s, len, "Windows %i.%i", *major, *minor); break; } if (!string_is_empty(arch)) { - strlcat(s, " ", len); - strlcat(s, arch, len); + _len += strlcpy(s + _len, " ", len - _len); + _len += strlcpy(s + _len, arch, len - _len); } - strlcat(s, " Build ", len); - strlcat(s, buildStr, len); + _len += strlcpy(s + _len, " Build ", len - _len); + _len += strlcpy(s + _len, build_str, len - _len); if (!string_is_empty(vi.szCSDVersion)) { - strlcat(s, " ", len); - strlcat(s, vi.szCSDVersion, len); + _len += strlcpy(s + _len, " ", len - _len); + strlcpy(s + _len, vi.szCSDVersion, len - _len); } - } static void frontend_win32_init(void *data) diff --git a/gfx/drivers_shader/shader_gl_cg.c b/gfx/drivers_shader/shader_gl_cg.c index 111a48f327..57c54360bf 100644 --- a/gfx/drivers_shader/shader_gl_cg.c +++ b/gfx/drivers_shader/shader_gl_cg.c @@ -167,8 +167,8 @@ static void gl_cg_set_uniform_parameter( if (param->lookup.add_prefix) { - strlcpy(ident, "IN.", sizeof(ident)); - strlcat(ident, param->lookup.ident, sizeof(ident)); + size_t _len = strlcpy(ident, "IN.", sizeof(ident)); + strlcpy(ident + _len, param->lookup.ident, sizeof(ident) - _len); } location = cgGetNamedParameter(prog, param->lookup.add_prefix ? ident : param->lookup.ident); } diff --git a/gfx/drivers_shader/slang_reflection.cpp b/gfx/drivers_shader/slang_reflection.cpp index 8c828e6ae3..dce9c835dd 100644 --- a/gfx/drivers_shader/slang_reflection.cpp +++ b/gfx/drivers_shader/slang_reflection.cpp @@ -688,8 +688,8 @@ bool slang_reflect( { char buf[64]; size_t _len = strlcpy(buf, "[slang]:\n", sizeof(buf)); - strlcpy(buf + _len, FILE_PATH_LOG_INFO, sizeof(buf) - _len); - strlcat(buf, " [slang]: Parameters:\n", sizeof(buf)); + _len += strlcpy(buf + _len, FILE_PATH_LOG_INFO, sizeof(buf) - _len); + strlcpy(buf + _len, " [slang]: Parameters:\n", sizeof(buf) - _len); RARCH_LOG(buf); } diff --git a/gfx/gfx_thumbnail_path.c b/gfx/gfx_thumbnail_path.c index 099a01b433..94cd31ebd2 100644 --- a/gfx/gfx_thumbnail_path.c +++ b/gfx/gfx_thumbnail_path.c @@ -41,7 +41,7 @@ static void gfx_thumbnail_fill_content_img(char *s, size_t len, const char *src) { char *scrub_char_ptr = NULL; /* Copy source label string */ - strlcpy(s, src, len); + size_t _len = strlcpy(s, src, len); /* Scrub characters that are not cross-platform and/or violate the * No-Intro filename standard: * http://datomatic.no-intro.org/stuff/The%20Official%20No-Intro%20Convention%20(20071030).zip @@ -49,7 +49,7 @@ static void gfx_thumbnail_fill_content_img(char *s, size_t len, const char *src) while ((scrub_char_ptr = strpbrk(s, "&*/:`\"<>?\\|"))) *scrub_char_ptr = '_'; /* Add PNG extension */ - strlcat(s, ".png", len); + strlcpy(s + _len, ".png", len - _len); } /* Returns currently set thumbnail 'type' (Named_Snaps, diff --git a/gfx/gfx_thumbnail_path.h b/gfx/gfx_thumbnail_path.h index bc3fa9c7b9..e4deb8c313 100644 --- a/gfx/gfx_thumbnail_path.h +++ b/gfx/gfx_thumbnail_path.h @@ -59,10 +59,10 @@ struct gfx_thumbnail_path_data enum playlist_thumbnail_mode playlist_left_mode; size_t playlist_index; char content_path[PATH_MAX_LENGTH]; - char content_label[PATH_MAX_LENGTH]; char content_img[PATH_MAX_LENGTH]; char right_path[PATH_MAX_LENGTH]; char left_path[PATH_MAX_LENGTH]; + char content_label[256]; char content_core_name[256]; char system[256]; char content_db_name[256]; diff --git a/intl/msg_hash_chs.c b/intl/msg_hash_chs.c index 4e21df0feb..1ac9479535 100644 --- a/intl/msg_hash_chs.c +++ b/intl/msg_hash_chs.c @@ -604,6 +604,7 @@ int msg_hash_get_help_chs_enum(enum msg_hash_enums msg, char *s, size_t len) { /* Work around C89 limitations */ char u[501]; + size_t _len; const char * t = "RetroArch 依赖于一种独特的音频/视频同步形式,\n" "需要根据显示器的刷新率对其进行校准,以获得最佳\n" @@ -623,8 +624,8 @@ int msg_hash_get_help_chs_enum(enum msg_hash_enums msg, char *s, size_t len) msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SETTINGS), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SETTINGS), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_REFRESH_RATE_AUTO)); - strlcpy(s, t, len); - strlcat(s, u, len); + _len = strlcpy(s, t, len); + strlcpy(s + _len, u, len - _len); } break; case MENU_ENUM_LABEL_VALUE_HELP_SCANNING_CONTENT_DESC: diff --git a/intl/msg_hash_pt_br.c b/intl/msg_hash_pt_br.c index 5ea9c1f17b..2c8a733e51 100644 --- a/intl/msg_hash_pt_br.c +++ b/intl/msg_hash_pt_br.c @@ -712,38 +712,40 @@ int msg_hash_get_help_pt_br_enum(enum msg_hash_enums msg, char *s, size_t len) "Bem-vindo ao RetroArch \n" ); break; - case MENU_ENUM_LABEL_VALUE_HELP_AUDIO_VIDEO_TROUBLESHOOTING_DESC: { - /* Work around C89 limitations */ - char u[501]; - const char *t = - "O RetroArch utiliza uma forma única de \n" - "sincronização de áudio/video aonde ele \n" - "precisa ser calibrado pela taxa de \n" - "atualização da sua tela para um melhor \n" - "resultado no desempenho. \n" - " \n" - "Se você experimentar qualquer estalido \n" - "no áudio ou rasgo de vídeo, normalmente \n" - "isto significa que você precisa calibrar \n" - "as configurações. Algumas escolhas abaixo: \n" - " \n"; - snprintf(u, sizeof(u), /* can't inline this due to the printf arguments */ + case MENU_ENUM_LABEL_VALUE_HELP_AUDIO_VIDEO_TROUBLESHOOTING_DESC: + { + /* Work around C89 limitations */ + char u[501]; + size_t _len; + const char *t = + "O RetroArch utiliza uma forma única de \n" + "sincronização de áudio/video aonde ele \n" + "precisa ser calibrado pela taxa de \n" + "atualização da sua tela para um melhor \n" + "resultado no desempenho. \n" + " \n" + "Se você experimentar qualquer estalido \n" + "no áudio ou rasgo de vídeo, normalmente \n" + "isto significa que você precisa calibrar \n" + "as configurações. Algumas escolhas abaixo: \n" + " \n"; + snprintf(u, sizeof(u), /* can't inline this due to the printf arguments */ "a) Vá para '%s' -> '%s', e habilite \n" - "'Vídeo paralelizado'. A taxa de atualização \n" - "não irá importar neste modo, a taxa de \n" - "quadros será maior, mas o vídeo será \n" - "menos fluído. \n" - "b) Vá para '%s' -> '%s', e observe \n" - "'%s'. Deixe executar até \n" - "2048 quadros, então pressione 'OK'.", + "'Vídeo paralelizado'. A taxa de atualização \n" + "não irá importar neste modo, a taxa de \n" + "quadros será maior, mas o vídeo será \n" + "menos fluído. \n" + "b) Vá para '%s' -> '%s', e observe \n" + "'%s'. Deixe executar até \n" + "2048 quadros, então pressione 'OK'.", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SETTINGS), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SETTINGS), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SETTINGS), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SETTINGS), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_REFRESH_RATE_AUTO)); - strlcpy(s, t, len); - strlcat(s, u, len); - } + _len = strlcpy(s, t, len); + strlcpy(s + _len, u, len - _len); + } break; case MENU_ENUM_LABEL_VALUE_HELP_SCANNING_CONTENT_DESC: snprintf(s, len, diff --git a/manual_content_scan.c b/manual_content_scan.c index 2c5d0b1d67..efd91c2ad4 100644 --- a/manual_content_scan.c +++ b/manual_content_scan.c @@ -1274,7 +1274,7 @@ static bool manual_content_scan_get_playlist_content_path( /* Build path to file inside archive */ s[ _len] = '#'; s[++_len] = '\0'; - strlcat(s, archive_file, len); + strlcpy(s + _len, archive_file, len - _len); } string_list_free(archive_list); diff --git a/network/discord.c b/network/discord.c index 8395b1ec60..dafad2ab40 100644 --- a/network/discord.c +++ b/network/discord.c @@ -451,6 +451,7 @@ void discord_update(enum presence presence) void discord_init(const char *discord_app_id, char *args) { + size_t _len; DiscordEventHandlers handlers; #ifdef _WIN32 char full_path[PATH_MAX_LENGTH]; @@ -478,7 +479,6 @@ void discord_init(const char *discord_app_id, char *args) strlcpy(command, args, sizeof(command)); else { - size_t _len; path_basedir(full_path); _len = strlcpy(command, full_path, sizeof(command)); strlcpy(command + _len, @@ -486,14 +486,8 @@ void discord_init(const char *discord_app_id, char *args) sizeof(command) - _len); } #else - command[0] = 's'; - command[1] = 'h'; - command[2] = ' '; - command[3] = '-'; - command[4] = 'c'; - command[5] = ' '; - command[6] = '\0'; - strlcat(command, args, sizeof(command)); + _len = strlcpy(command, "sh -c ", sizeof(command)); + strlcpy(command + _len, args, sizeof(command) - _len); #endif Discord_Register(discord_app_id, command); #ifdef DISCORD_DISABLE_IO_THREAD diff --git a/network/natt.c b/network/natt.c index f7237dddfa..ff0a030a90 100644 --- a/network/natt.c +++ b/network/natt.c @@ -244,17 +244,17 @@ static bool build_control_url(rxml_node_t *control_url, /* We don't have a full url. Build one using the desc url. */ char *control_path; - - strlcpy(device->control, device->desc, + size_t _len = strlcpy(device->control, device->desc, sizeof(device->control)); - control_path = (char *) strchr(device->control + + control_path = (char *)strchr(device->control + STRLEN_CONST("http://"), '/'); if (control_path) *control_path = '\0'; if (control_url->data[0] != '/') - strlcat(device->control, "/", sizeof(device->control)); + strlcpy(device->control + _len, "/", + sizeof(device->control) - _len); /* Make sure the control URL isn't too long. */ if (strlcat(device->control, control_url->data, sizeof(device->control)) >= sizeof(device->control)) diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 8c7051921b..5ae93bf44a 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -4489,6 +4489,7 @@ static void announce_play_spectate(netplay_t *netplay, enum rarch_netplay_connection_mode mode, uint32_t devices, int32_t ping, uint32_t client_num) { + size_t _len; char msg[512]; const char *dmsg = NULL; @@ -4515,9 +4516,7 @@ static void announce_play_spectate(netplay_t *netplay, char *pdevice_str = NULL; if (netplay->modus == NETPLAY_MODUS_CORE_PACKET_INTERFACE) - { one_device = client_num; - } else { for (device = 0; device < MAX_INPUT_DEVICES; device++) @@ -4538,11 +4537,11 @@ static void announce_play_spectate(netplay_t *netplay, { /* Only have one device, simpler message */ if (nick) - snprintf(msg, sizeof(msg), + _len = snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_NETPLAY_S_HAS_JOINED_AS_PLAYER_N), NETPLAY_NICK_LEN, nick, one_device + 1); else - snprintf(msg, sizeof(msg), + _len = snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_NETPLAY_YOU_HAVE_JOINED_AS_PLAYER_N), one_device + 1); } @@ -4564,11 +4563,11 @@ static void announce_play_spectate(netplay_t *netplay, /* Then we make the final string */ if (nick) - snprintf(msg, sizeof(msg), + _len = snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_NETPLAY_S_HAS_JOINED_WITH_INPUT_DEVICES_S), NETPLAY_NICK_LEN, nick, sizeof(device_str), device_str); else - snprintf(msg, sizeof(msg), + _len = snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_NETPLAY_YOU_HAVE_JOINED_WITH_INPUT_DEVICES_S), sizeof(device_str), device_str); } @@ -4577,7 +4576,7 @@ static void announce_play_spectate(netplay_t *netplay, { snprintf(ping_str, sizeof(ping_str), " (ping: %i ms)", (int)ping); - strlcat(msg, ping_str, sizeof(msg)); + strlcpy(msg + _len, ping_str, sizeof(msg) - _len); } dmsg = msg; diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index 1c5e39d8c6..3dfbe96f19 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -638,7 +638,8 @@ int detect_scd_game(intfstream_t *fd, char *s, size_t len, const char *filename) check_suffix_50[2] = '\0'; /** redump serials are built differently for each prefix **/ - if (pre_game_id[0] == 'T' && pre_game_id[1] == '-') + if ( pre_game_id[0] == 'T' + && pre_game_id[1] == '-') { if (region_id == 'U' || region_id == 'J') { @@ -661,7 +662,8 @@ int detect_scd_game(intfstream_t *fd, char *s, size_t len, const char *filename) cue_append_multi_disc_suffix(s, filename); return true; } - else if (pre_game_id[0] == 'G' && pre_game_id[1] == '-') + else if (pre_game_id[0] == 'G' + && pre_game_id[1] == '-') { if ((index = string_index_last_occurance(pre_game_id, '-')) == -1) return false; diff --git a/tasks/task_playlist_manager.c b/tasks/task_playlist_manager.c index 59f57a6fa6..103f213f9e 100644 --- a/tasks/task_playlist_manager.c +++ b/tasks/task_playlist_manager.c @@ -208,7 +208,7 @@ static void task_pl_manager_reset_cores_handler(retro_task_t *task) char entry_name[128]; fill_pathname_base(entry_name, entry->path, sizeof(entry_name)); path_remove_extension(entry_name); - strlcat(task_title, entry_name, sizeof(task_title)); + strlcpy(task_title + _len, entry_name, sizeof(task_title) - _len); } task_set_title(task, strdup(task_title)); diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index 6fd692f3a4..73ea6f01e4 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -5107,9 +5107,9 @@ void LoadCoreWindow::onLoadCustomCoreClicked() frontend_driver_get_core_extension(core_ext, sizeof(core_ext)); - _len = strlcpy(filters, "Cores (*.", sizeof(filters)); - strlcpy(filters + _len, core_ext, sizeof(filters) - _len); - strlcat(filters, ");;All Files (*.*)", sizeof(filters)); + _len = strlcpy(filters, "Cores (*.", sizeof(filters)); + _len += strlcpy(filters + _len, core_ext, sizeof(filters) - _len); + strlcpy(filters + _len, ");;All Files (*.*)", sizeof(filters) - _len); path = QFileDialog::getOpenFileName( this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_LOAD_CORE), diff --git a/verbosity.c b/verbosity.c index 6c989a1827..69fdae2666 100644 --- a/verbosity.c +++ b/verbosity.c @@ -468,8 +468,8 @@ void rarch_log_file_init( } /* If nothing has changed, do nothing */ - if ((!log_to_file && !logging_to_file) || - (log_to_file && logging_to_file)) + if ( (!log_to_file && !logging_to_file) + || (log_to_file && logging_to_file)) return; /* If we are currently logging to file and wish to stop,