From e00b99c8180dc354a8f053cefe515214274b676e Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 19 May 2006 19:05:07 +0000 Subject: [PATCH] (init_environment): Perform the processing of environment variables on a copy of default variables and their values, not on the original. --- src/ChangeLog | 6 ++++++ src/w32.c | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 5acc6313bbb..621e2632982 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2006-05-19 Eli Zaretskii + + * w32.c (init_environment): Perform the processing of environment + variables on a copy of default variables and their values, not on + the original. + 2006-05-19 YAMAMOTO Mitsuharu * frame.c (x_set_border_width): Remove #ifndef MAC_OS. diff --git a/src/w32.c b/src/w32.c index 71799befdbb..30474b842d8 100644 --- a/src/w32.c +++ b/src/w32.c @@ -950,11 +950,11 @@ init_environment (char ** argv) struct stat ignored; char default_home[MAX_PATH]; - static struct env_entry + static const struct env_entry { char * name; char * def_value; - } env_vars[] = + } dflt_envvars[] = { {"HOME", "C:/"}, {"PRELOAD_WINSOCK", NULL}, @@ -971,6 +971,17 @@ init_environment (char ** argv) {"LANG", NULL}, }; +#define N_ENV_VARS sizeof(dflt_envvars)/sizeof(dflt_envvars[0]) + + /* We need to copy dflt_envvars[] and work on the copy because we + don't want the dumped Emacs to inherit the values of + environment variables we saw during dumping (which could be on + a different system). The defaults above must be left intact. */ + struct env_entry env_vars[N_ENV_VARS]; + + for (i = 0; i < N_ENV_VARS; i++) + env_vars[i] = dflt_envvars[i]; + /* For backwards compatibility, check if a .emacs file exists in C:/ If not, then we can try to default to the appdata directory under the user's profile, which is more likely to be writable. */ @@ -1005,7 +1016,7 @@ init_environment (char ** argv) LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP, locale_name, sizeof (locale_name))) { - for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++) + for (i = 0; i < N_ENV_VARS; i++) { if (strcmp (env_vars[i].name, "LANG") == 0) { @@ -1069,7 +1080,7 @@ init_environment (char ** argv) } } - for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++) + for (i = 0; i < N_ENV_VARS; i++) { if (!getenv (env_vars[i].name)) { -- 2.39.5