From 4c83cee8108e5d56d142117512d1e4bc017b7180 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Sat, 10 Nov 2018 08:29:53 +0100 Subject: [PATCH 1/2] core: Use dynamic string in OpenURL() OpenURL() is a function that most games probably will never need. Wasting 512 bytes to store of a static char to store an the URL is not wise. I propose to have it dynamic building the string on the fly. --- src/core.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/core.c b/src/core.c index da2869233..380137b7f 100644 --- a/src/core.c +++ b/src/core.c @@ -1822,10 +1822,7 @@ int StorageLoadValue(int position) // Open URL with default system browser (if available) void OpenURL(const char *url) { - // Max length is "explorer ".length + url.maxlength (which is 2083), - // but we are not wasting that much memory here... let's set it up to 512 - static char cmd[512] = { 0 }; - + char *cmd = calloc(10 + strlen(url), sizeof(char)); #if defined(_WIN32) strcpy(cmd, "explorer "); #elif defined(__linux__) @@ -1833,11 +1830,9 @@ void OpenURL(const char *url) #elif defined(__APPLE__) strcpy(cmd, "open "); #endif - strcat(cmd, url); system(cmd); - - memset(cmd, 0, 512); + free(cmd); } //---------------------------------------------------------------------------------- From 80dbe636cd647c48b36db8df70708b4bc5ca1d6f Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Sat, 10 Nov 2018 08:36:15 +0100 Subject: [PATCH 2/2] core: OpenURL() fix xdg-open call Calling just `xdg-open` is not right. One needs to pack the URL in `'`. If we don't do this then some special characters (like ampersand) will be executed. Maybe this is true for Windows and Apple case too, but I don't own any such system. So please merge this, and if it's true for more cases let's use `sprintf()` in the other cases too. --- src/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core.c b/src/core.c index 380137b7f..d6c5f243a 100644 --- a/src/core.c +++ b/src/core.c @@ -1823,14 +1823,17 @@ int StorageLoadValue(int position) void OpenURL(const char *url) { char *cmd = calloc(10 + strlen(url), sizeof(char)); + #if defined(_WIN32) strcpy(cmd, "explorer "); + strcat(cmd, url); #elif defined(__linux__) - strcpy(cmd, "xdg-open "); // Alternatives: firefox, x-www-browser + sprintf(cmd, "xdg-open '%s'", url); // Alternatives: firefox, x-www-browser #elif defined(__APPLE__) strcpy(cmd, "open "); -#endif strcat(cmd, url); +#endif + system(cmd); free(cmd); }