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.
This commit is contained in:
Michael Vetter 2018-11-10 08:29:53 +01:00
parent 5167f78d5f
commit 4c83cee810

View File

@ -1822,10 +1822,7 @@ int StorageLoadValue(int position)
// Open URL with default system browser (if available) // Open URL with default system browser (if available)
void OpenURL(const char *url) void OpenURL(const char *url)
{ {
// Max length is "explorer ".length + url.maxlength (which is 2083), char *cmd = calloc(10 + strlen(url), sizeof(char));
// but we are not wasting that much memory here... let's set it up to 512
static char cmd[512] = { 0 };
#if defined(_WIN32) #if defined(_WIN32)
strcpy(cmd, "explorer "); strcpy(cmd, "explorer ");
#elif defined(__linux__) #elif defined(__linux__)
@ -1833,11 +1830,9 @@ void OpenURL(const char *url)
#elif defined(__APPLE__) #elif defined(__APPLE__)
strcpy(cmd, "open "); strcpy(cmd, "open ");
#endif #endif
strcat(cmd, url); strcat(cmd, url);
system(cmd); system(cmd);
free(cmd);
memset(cmd, 0, 512);
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------