OSDN Git Service

* environ.cc (parse_options): Use tmp_pathbuf to allocate buffer.
authorcorinna <corinna>
Tue, 11 Mar 2008 11:42:00 +0000 (11:42 +0000)
committercorinna <corinna>
Tue, 11 Mar 2008 11:42:00 +0000 (11:42 +0000)
(regopt): Take tmp buffer as additional argument.
(environ_init): Alllcate tmpbuf earlier.  Use as temporary buffer in
call to regopt.
* tls_pbuf.cc (tmp_pathbuf::c_get): Allocate one additional char.
(tmp_pathbuf::w_get): Allocate one additional WCHAR.
* winf.cc (av::unshift): Use tmp_pathbuf to allocate buffer.

winsup/cygwin/ChangeLog
winsup/cygwin/environ.cc
winsup/cygwin/tls_pbuf.cc
winsup/cygwin/winf.cc

index f5987d9..3ed49c9 100644 (file)
@@ -1,5 +1,15 @@
 2008-03-11  Corinna Vinschen  <corinna@vinschen.de>
 
+       * environ.cc (parse_options): Use tmp_pathbuf to allocate buffer.
+       (regopt): Take tmp buffer as additional argument.
+       (environ_init): Alllcate tmpbuf earlier.  Use as temporary buffer in
+       call to regopt.
+       * tls_pbuf.cc (tmp_pathbuf::c_get): Allocate one additional char.
+       (tmp_pathbuf::w_get): Allocate one additional WCHAR.
+       * winf.cc (av::unshift): Use tmp_pathbuf to allocate buffer.
+
+2008-03-11  Corinna Vinschen  <corinna@vinschen.de>
+
        * syscalls.cc (sync): Use MAX_PATH rather than CYG_MAX_PATH.
 
 2008-03-10  Corinna Vinschen  <corinna@vinschen.de>
index 3a427bb..76c6820 100644 (file)
@@ -626,7 +626,8 @@ parse_options (char *buf)
 
   if (buf == NULL)
     {
-      char newbuf[CYG_MAX_PATH + 7];
+      tmp_pathbuf tp;
+      char *newbuf = tp.c_get ();
       newbuf[0] = '\0';
       for (k = known; k->name != NULL; k++)
        if (k->remember)
@@ -705,10 +706,9 @@ parse_options (char *buf)
 
 /* Set options from the registry. */
 static bool __stdcall
-regopt (const char *name)
+regopt (const char *name, char *buf)
 {
   bool parsed_something = false;
-  char buf[CYG_MAX_PATH];
   char lname[strlen (name) + 1];
   strlwr (strcpy (lname, name));
 
@@ -716,7 +716,7 @@ regopt (const char *name)
     {
       reg_key r (i, KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
 
-      if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
+      if (r.get_string (lname, buf, NT_MAX_PATH, "") == ERROR_SUCCESS)
        {
          parse_options (buf);
          parsed_something = true;
@@ -754,9 +754,11 @@ environ_init (char **envp, int envc)
        conv_start_chars[(int) cyg_toupper (conv_envvars[i].name[0])] = 1;
       }
 
-  got_something_from_registry = regopt ("default");
+  char *tmpbuf = tp.t_get ();
+  got_something_from_registry = regopt ("default", tmpbuf);
   if (myself->progname[0])
-    got_something_from_registry = regopt (myself->progname) || got_something_from_registry;
+    got_something_from_registry = regopt (myself->progname, tmpbuf)
+                                 || got_something_from_registry;
 
   if (!envp)
     envp_passed_in = 0;
@@ -807,7 +809,6 @@ environ_init (char **envp, int envc)
      form "=X:=X:\foo\bar; these must be changed into something legal
      (we could just ignore them but maybe an application will
      eventually want to use them).  */
-  char *tmpbuf = tp.t_get ();
   for (i = 0, w = rawenv; *w != L'\0'; w = wcschr (w, L'\0') + 1, i++)
     {
       sys_wcstombs_alloc (&newp, HEAP_NOTHEAP, w);
index 704f3bf..802885e 100644 (file)
@@ -42,7 +42,7 @@ tmp_pathbuf::c_get ()
   if (tls_pbuf.c_cnt >= TP_NUM_C_BUFS)
     api_fatal ("Internal error: TP_NUM_C_BUFS too small.");
   if (!tls_pbuf.c_buf[tls_pbuf.c_cnt]
-      && !(tls_pbuf.c_buf[tls_pbuf.c_cnt] = (char *) malloc (NT_MAX_PATH)))
+      && !(tls_pbuf.c_buf[tls_pbuf.c_cnt] = (char *) malloc (NT_MAX_PATH + 1)))
     api_fatal ("Internal error: Out of memory for new path buf.");
   return tls_pbuf.c_buf[tls_pbuf.c_cnt++];
 }
@@ -54,7 +54,7 @@ tmp_pathbuf::w_get ()
     api_fatal ("Internal error: TP_NUM_W_BUFS too small.");
   if (!tls_pbuf.w_buf[tls_pbuf.w_cnt]
       && !(tls_pbuf.w_buf[tls_pbuf.w_cnt]
-          = (PWCHAR) malloc (NT_MAX_PATH * sizeof (WCHAR))))
+          = (PWCHAR) malloc ((NT_MAX_PATH + 1) * sizeof (WCHAR))))
     api_fatal ("Internal error: Out of memory for new wide path buf.");
   return tls_pbuf.w_buf[tls_pbuf.w_cnt++];
 }
index 924e604..033de7b 100644 (file)
@@ -15,6 +15,7 @@ details. */
 #include "fhandler.h"
 #include "dtable.h"
 #include "cygheap.h"
+#include "tls_pbuf.h"
 #include "winf.h"
 #include "sys/cygwin.h"
 
@@ -136,7 +137,8 @@ av::unshift (const char *what, int conv)
 
   argv = av;
   memmove (argv + 1, argv, (argc + 1) * sizeof (char *));
-  char buf[CYG_MAX_PATH];
+  tmp_pathbuf tp;
+  char *buf = tp.c_get ();
   if (conv)
     {
       cygwin_conv_to_posix_path (what, buf);