shithub: choc

Download patch

ref: 2ecf987df183e01f2e73db001542cfc56a84c6ce
parent: 5ff1698982eb861a55031de14654a195a6895006
author: Ioan Chera <ioan.chera@gmail.com>
date: Sun Mar 18 05:42:17 EDT 2018

Fix TXT_SelectFile for macOS

First parameter needed to be const, and the content updated to work under this restriction.

--- a/textscreen/txt_fileselect.c
+++ b/textscreen/txt_fileselect.c
@@ -463,13 +463,21 @@
     return 1;
 }
 
-char *TXT_SelectFile(char *window_title, char **extensions)
+char *TXT_SelectFile(const char *window_title, char **extensions)
 {
     char *argv[4];
     char *result, *applescript;
 
-    applescript = GenerateAppleScript(window_title, extensions);
+    // We need to create a temporary copy of window_title because GenerateApple-
+    // Script works with non-const string.
+    char *window_title_copy = strdup(window_title);
+    if (!window_title_copy)
+    {
+        return NULL;
+    }
 
+    applescript = GenerateAppleScript(window_title_copy, extensions);
+
     argv[0] = "/usr/bin/osascript";
     argv[1] = "-e";
     argv[2] = applescript;
@@ -478,6 +486,7 @@
     result = ExecReadOutput(argv);
 
     free(applescript);
+    free(window_title_copy);
 
     return result;
 }