4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-11 19:49:15 +08:00

* 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.
This commit is contained in:
Corinna Vinschen 2008-03-11 11:42:00 +00:00
parent ff488124ff
commit becf251f67
4 changed files with 23 additions and 10 deletions

View File

@ -1,3 +1,13 @@
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> 2008-03-11 Corinna Vinschen <corinna@vinschen.de>
* syscalls.cc (sync): Use MAX_PATH rather than CYG_MAX_PATH. * syscalls.cc (sync): Use MAX_PATH rather than CYG_MAX_PATH.

View File

@ -626,7 +626,8 @@ parse_options (char *buf)
if (buf == NULL) if (buf == NULL)
{ {
char newbuf[CYG_MAX_PATH + 7]; tmp_pathbuf tp;
char *newbuf = tp.c_get ();
newbuf[0] = '\0'; newbuf[0] = '\0';
for (k = known; k->name != NULL; k++) for (k = known; k->name != NULL; k++)
if (k->remember) if (k->remember)
@ -705,10 +706,9 @@ parse_options (char *buf)
/* Set options from the registry. */ /* Set options from the registry. */
static bool __stdcall static bool __stdcall
regopt (const char *name) regopt (const char *name, char *buf)
{ {
bool parsed_something = false; bool parsed_something = false;
char buf[CYG_MAX_PATH];
char lname[strlen (name) + 1]; char lname[strlen (name) + 1];
strlwr (strcpy (lname, name)); strlwr (strcpy (lname, name));
@ -716,7 +716,7 @@ regopt (const char *name)
{ {
reg_key r (i, KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL); 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); parse_options (buf);
parsed_something = true; 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; 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]) 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) if (!envp)
envp_passed_in = 0; 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 form "=X:=X:\foo\bar; these must be changed into something legal
(we could just ignore them but maybe an application will (we could just ignore them but maybe an application will
eventually want to use them). */ 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++) for (i = 0, w = rawenv; *w != L'\0'; w = wcschr (w, L'\0') + 1, i++)
{ {
sys_wcstombs_alloc (&newp, HEAP_NOTHEAP, w); sys_wcstombs_alloc (&newp, HEAP_NOTHEAP, w);

View File

@ -42,7 +42,7 @@ tmp_pathbuf::c_get ()
if (tls_pbuf.c_cnt >= TP_NUM_C_BUFS) if (tls_pbuf.c_cnt >= TP_NUM_C_BUFS)
api_fatal ("Internal error: TP_NUM_C_BUFS too small."); api_fatal ("Internal error: TP_NUM_C_BUFS too small.");
if (!tls_pbuf.c_buf[tls_pbuf.c_cnt] 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."); api_fatal ("Internal error: Out of memory for new path buf.");
return tls_pbuf.c_buf[tls_pbuf.c_cnt++]; 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."); api_fatal ("Internal error: TP_NUM_W_BUFS too small.");
if (!tls_pbuf.w_buf[tls_pbuf.w_cnt] if (!tls_pbuf.w_buf[tls_pbuf.w_cnt]
&& !(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."); api_fatal ("Internal error: Out of memory for new wide path buf.");
return tls_pbuf.w_buf[tls_pbuf.w_cnt++]; return tls_pbuf.w_buf[tls_pbuf.w_cnt++];
} }

View File

@ -15,6 +15,7 @@ details. */
#include "fhandler.h" #include "fhandler.h"
#include "dtable.h" #include "dtable.h"
#include "cygheap.h" #include "cygheap.h"
#include "tls_pbuf.h"
#include "winf.h" #include "winf.h"
#include "sys/cygwin.h" #include "sys/cygwin.h"
@ -136,7 +137,8 @@ av::unshift (const char *what, int conv)
argv = av; argv = av;
memmove (argv + 1, argv, (argc + 1) * sizeof (char *)); memmove (argv + 1, argv, (argc + 1) * sizeof (char *));
char buf[CYG_MAX_PATH]; tmp_pathbuf tp;
char *buf = tp.c_get ();
if (conv) if (conv)
{ {
cygwin_conv_to_posix_path (what, buf); cygwin_conv_to_posix_path (what, buf);