mingw: fix static linking with recent ncurses
[tinc] / src / script.c
index cb3d293..3f44bf9 100644 (file)
@@ -37,12 +37,12 @@ static void unputenv(const char *p) {
 
        ptrdiff_t len = e - p;
 #ifndef HAVE_UNSETENV
-#ifdef HAVE_MINGW
+#ifdef HAVE_WINDOWS
        // Windows requires putenv("FOO=") to unset %FOO%
        len++;
 #endif
 #endif
-       char var[len + 1];
+       char *var = alloca(len + 1);
        strncpy(var, p, len);
        var[len] = 0;
 #ifdef HAVE_UNSETENV
@@ -134,7 +134,7 @@ void environment_init(environment_t *env) {
 
 void environment_exit(environment_t *env) {
        for(int i = 0; i < env->n; i++) {
-               free(env->entries[i]);
+               free_string(env->entries[i]);
        }
 
        free(env->entries);
@@ -148,7 +148,7 @@ bool execute_script(const char *name, environment_t *env) {
 
        /* First check if there is a script */
 
-#ifdef HAVE_MINGW
+#ifdef HAVE_WINDOWS
 
        if(!*scriptextension) {
                const char *pathext = getenv("PATHEXT");
@@ -159,9 +159,11 @@ bool execute_script(const char *name, environment_t *env) {
 
                size_t pathlen = strlen(pathext);
                size_t scriptlen = strlen(scriptname);
-               char fullname[scriptlen + pathlen + 1];
+
+               const size_t fullnamelen = scriptlen + pathlen + 1;
+               char *fullname = alloca(fullnamelen);
                char *ext = fullname + scriptlen;
-               strncpy(fullname, scriptname, sizeof(fullname));
+               strncpy(fullname, scriptname, fullnamelen);
 
                const char *p = pathext;
                bool found = false;