From 714631b38dd0c364a984aa39fc78c4a6b3c31965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Sat, 5 Jan 2019 19:16:28 -0500 Subject: [PATCH] Discord ask-to-join fixes (#7903) * C89 Fix * use strlcat instead * declare i on top * declare buf on top --- menu/cbs/menu_cbs_ok.c | 2 +- retroarch.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 1443aa5f0e..fa7a287141 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -3351,6 +3351,7 @@ void cb_generic_download(void *task_data, void *user_data, const char *err) { char output_path[PATH_MAX_LENGTH]; + char buf[PATH_MAX_LENGTH]; #if defined(HAVE_COMPRESSION) && defined(HAVE_ZLIB) bool extract = true; #endif @@ -3363,7 +3364,6 @@ void cb_generic_download(void *task_data, goto finish; output_path[0] = '\0'; - char buf[PATH_MAX_LENGTH];; /* we have to determine dir_path at the time of writting or else * we'd run into races when the user changes the setting during an diff --git a/retroarch.c b/retroarch.c index 73593f4e4a..d36142a2f5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -640,16 +640,9 @@ static void retroarch_parse_input_and_config(int argc, char *argv[]) { const char *optstring = NULL; bool explicit_menu = false; + unsigned i; global_t *global = global_get_ptr(); - /* Nasty hack to copy the args into a global so discord can register the same arguments for launch */ - char buf[4096]; - for (unsigned i = 0; i < argc; i++) - { - snprintf(buf, sizeof(buf), "%s %s", launch_arguments, argv[i]); - strlcpy(launch_arguments, buf, sizeof(launch_arguments)); - } - string_trim_whitespace_left(launch_arguments); const struct option opts[] = { #ifdef HAVE_DYNAMIC @@ -701,6 +694,15 @@ static void retroarch_parse_input_and_config(int argc, char *argv[]) { NULL, 0, NULL, 0 } }; + /* Copy the args into a buffer so launch arguments can be reused */ + + for (i = 0; i < argc; i++) + { + strlcat(launch_arguments, argv[i], sizeof(launch_arguments)); + strlcat(launch_arguments, " ", sizeof(launch_arguments)); + } + string_trim_whitespace_left(launch_arguments); + /* Handling the core type is finicky. Based on the arguments we pass in, * we handle it differently. * Some current cases which track desired behavior and how it is supposed to work: