From 76bc15156f94dab9e489eb6008b9c2ad38accaed Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Tue, 9 Jun 2020 17:45:55 -0700 Subject: [PATCH] dirname can modify its argument; don't pass in a const char * --- sc2/src/options.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sc2/src/options.c b/sc2/src/options.c index 46c7c30c1..ee9a577e4 100644 --- a/sc2/src/options.c +++ b/sc2/src/options.c @@ -156,9 +156,16 @@ prepareContentDir (const char *contentDirName, const char* addonDirName, const c if (loc == NULL) { char *tempDir = (char *) HMalloc (PATH_MAX); + char *execFileDup; + + /* dirname can modify its argument, so we need a local + * mutable copy of it. */ + execFileDup = (char *) HMalloc (strlen (execFile) + 1); + strcpy (execFileDup, execFile); snprintf (tempDir, PATH_MAX, "%s/../Resources/content", - dirname (execFile)); + dirname (execFileDup)); loc = findFileInDirs ((const char **) &tempDir, 1, testFile); + HFree (execFileDup); HFree (tempDir); } #endif