OSDN Git Service

* environ.cc (winenv): Allocate exact amount of space needed for forced windows
authorcgf <cgf>
Sun, 30 Sep 2001 21:37:53 +0000 (21:37 +0000)
committercgf <cgf>
Sun, 30 Sep 2001 21:37:53 +0000 (21:37 +0000)
environment variable rather than just using MAX_PATH.

winsup/cygwin/ChangeLog
winsup/cygwin/environ.cc

index 8d0483d..bd81827 100644 (file)
@@ -1,3 +1,8 @@
+Sun Sep 30 17:37:43 2001  Christopher Faylor <cgf@cygnus.com>
+
+       * environ.cc (winenv): Allocate exact amount of space needed for forced
+       windows environment variable rather than just using MAX_PATH.
+
 Sun Sep 30 17:10:18 2001  Christopher Faylor <cgf@cygnus.com>
 
        * Makefile.in: Depend on stamp to ensure rebuilding.  Remove stamp file
index 1be0b79..c1529e7 100644 (file)
@@ -806,14 +806,17 @@ winenv (const char * const *envp, int keep_posix)
          saw_forced_winenv[i] = strncasematch (forced_winenv_vars[i], *srcp, len);
     }
 
+  char dum[1];
   for (int i = 0; forced_winenv_vars[i]; i++)
     if (!saw_forced_winenv[i])
       {
-       len = strlen (forced_winenv_vars[i]);
-       p = (char *) alloca (len + MAX_PATH + 1);
+       int namelen = strlen (forced_winenv_vars[i]) + 1;
+       int vallen = GetEnvironmentVariable (forced_winenv_vars[i], dum, 0) + 1;
+       p = (char *) alloca (namelen + vallen);
        strcpy (p, forced_winenv_vars[i]);
        strcat (p, "=");
-       if (!GetEnvironmentVariable (forced_winenv_vars[i], p + len + 1, MAX_PATH))
+       if (!GetEnvironmentVariable (forced_winenv_vars[i], p + namelen,
+                                    vallen + 1))
          debug_printf ("warning: %s not present in environment", *srcp);
        else
          {