From 26d5a981eb444acf9469853d6c4988140d20cb83 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 18 May 2018 09:07:42 +0200 Subject: do not pass NULL to os_getenv closes #8393 --- src/nvim/eval.c | 3 +++ src/nvim/main.c | 1 + src/nvim/option.c | 2 +- src/nvim/os/stdpaths.c | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a3540b3153..de40bea0dd 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -15712,6 +15712,9 @@ static void get_xdg_var_list(const XDGVarType xdg, typval_T *rettv) rettv->vval.v_list = list; tv_list_ref(list); char *const dirs = stdpaths_get_xdg_var(xdg); + if (dirs == NULL) { + return; + } do { size_t dir_len; const char *dir; diff --git a/src/nvim/main.c b/src/nvim/main.c index a4ed868af1..23cea3e592 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1849,6 +1849,7 @@ static void source_startup_scripts(const mparm_T *const parmp) /// @return FAIL if the environment variable was not executed, /// OK otherwise. static int process_env(char *env, bool is_viminit) + FUNC_ATTR_NONNULL_ALL { const char *initstr = os_getenv(env); if (initstr != NULL) { diff --git a/src/nvim/option.c b/src/nvim/option.c index 1da259e6b8..68f76296c7 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -6585,7 +6585,7 @@ void vimrc_found(char_u *fname, char_u *envname) { char_u *p; - if (fname != NULL) { + if (fname != NULL && envname != NULL) { p = (char_u *)vim_getenv((char *)envname); if (p == NULL) { /* Set $MYVIMRC to the first vimrc file found. */ diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 866a005228..f6503dfdb0 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -65,7 +65,7 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) const char *env_val = os_getenv(env); #ifdef WIN32 - if (env_val == NULL) { + if (env_val == NULL && xdg_defaults_env_vars[idx] != NULL) { env_val = os_getenv(xdg_defaults_env_vars[idx]); } #endif @@ -74,7 +74,7 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) if (env_val != NULL) { ret = xstrdup(env_val); } else if (fallback) { - ret = (char *) expand_env_save((char_u *)fallback); + ret = (char *)expand_env_save((char_u *)fallback); } return ret; -- cgit From 23f052edaca126891bb1a98ea5c14f355fe452f2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 18 May 2018 09:08:04 +0200 Subject: main.c: remove useless call Vim's vimrc_found() also handles setting 'nocompatible', that's why it does vimrc_found(NULL, NULL). --- src/nvim/main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/main.c b/src/nvim/main.c index 23cea3e592..8b0d3bb2cc 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1735,7 +1735,7 @@ static bool do_user_initialization(void) FUNC_ATTR_WARN_UNUSED_RESULT { bool do_exrc = p_exrc; - if (process_env("VIMINIT", true) == OK) { + if (process_env("VIMINIT") == OK) { do_exrc = p_exrc; return do_exrc; } @@ -1780,7 +1780,7 @@ static bool do_user_initialization(void) } while (iter != NULL); xfree(config_dirs); } - if (process_env("EXINIT", false) == OK) { + if (process_env("EXINIT") == OK) { do_exrc = p_exrc; return do_exrc; } @@ -1844,18 +1844,14 @@ static void source_startup_scripts(const mparm_T *const parmp) /// Get an environment variable, and execute it as Ex commands. /// /// @param env environment variable to execute -/// @param is_viminit when true, called for VIMINIT /// /// @return FAIL if the environment variable was not executed, /// OK otherwise. -static int process_env(char *env, bool is_viminit) +static int process_env(char *env) FUNC_ATTR_NONNULL_ALL { const char *initstr = os_getenv(env); if (initstr != NULL) { - if (is_viminit) { - vimrc_found(NULL, NULL); - } char_u *save_sourcing_name = sourcing_name; linenr_T save_sourcing_lnum = sourcing_lnum; sourcing_name = (char_u *)env; -- cgit From 91c4de83c9de9049fc706f319deea38e9436502e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 18 May 2018 09:07:59 +0200 Subject: cleanup --- src/nvim/eval.c | 10 +++++----- src/nvim/option.c | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index de40bea0dd..ffea88aa83 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -15740,15 +15740,15 @@ static void f_stdpath(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; // Type error; errmsg already given. } - if (strcmp(p, "config") == 0) { + if (strequal(p, "config")) { rettv->vval.v_string = (char_u *)get_xdg_home(kXDGConfigHome); - } else if (strcmp(p, "data") == 0) { + } else if (strequal(p, "data")) { rettv->vval.v_string = (char_u *)get_xdg_home(kXDGDataHome); - } else if (strcmp(p, "cache") == 0) { + } else if (strequal(p, "cache")) { rettv->vval.v_string = (char_u *)get_xdg_home(kXDGCacheHome); - } else if (strcmp(p, "config_dirs") == 0) { + } else if (strequal(p, "config_dirs")) { get_xdg_var_list(kXDGConfigDirs, rettv); - } else if (strcmp(p, "data_dirs") == 0) { + } else if (strequal(p, "data_dirs")) { get_xdg_var_list(kXDGDataDirs, rettv); } else { EMSG2(_("E6100: \"%s\" is not a valid stdpath"), p); diff --git a/src/nvim/option.c b/src/nvim/option.c index 68f76296c7..48c874196d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -6583,15 +6583,13 @@ static void paste_option_changed(void) /// When "fname" is not NULL, use it to set $"envname" when it wasn't set yet. void vimrc_found(char_u *fname, char_u *envname) { - char_u *p; - if (fname != NULL && envname != NULL) { - p = (char_u *)vim_getenv((char *)envname); + char *p = vim_getenv((char *)envname); if (p == NULL) { - /* Set $MYVIMRC to the first vimrc file found. */ - p = (char_u *)FullName_save((char *)fname, FALSE); + // Set $MYVIMRC to the first vimrc file found. + p = FullName_save((char *)fname, false); if (p != NULL) { - vim_setenv((char *)envname, (char *)p); + vim_setenv((char *)envname, p); xfree(p); } } else { -- cgit