diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2014-04-29 22:35:30 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-04-30 11:21:46 -0400 |
commit | 5d65e7f27948764ca74987b0a964e6eee1e404d9 (patch) | |
tree | 76e95694ce9864237c63df8c4437cf0b8f9fc268 /src/eval.c | |
parent | c79d27ee0709b6a66cfcaf5ef1192009b504d2d6 (diff) | |
download | rneovim-5d65e7f27948764ca74987b0a964e6eee1e404d9.tar.gz rneovim-5d65e7f27948764ca74987b0a964e6eee1e404d9.tar.bz2 rneovim-5d65e7f27948764ca74987b0a964e6eee1e404d9.zip |
vim-patch:7.4.272
Problem: Using just "$" does not cause an error message.
Solution: Check for empty environment variable name.
(Christian Brabandt)
https://code.google.com/p/vim/source/detail?r=00228400629e28384f7f52556c3c119ba0d0a44d
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/src/eval.c b/src/eval.c index c237a90b74..91d74d49e2 100644 --- a/src/eval.c +++ b/src/eval.c @@ -6718,45 +6718,50 @@ string2float ( return (int)((char_u *)s - text); } -/* - * Get the value of an environment variable. - * "arg" is pointing to the '$'. It is advanced to after the name. - * If the environment variable was not set, silently assume it is empty. - * Always return OK. - */ +/// Get the value of an environment variable. +/// +/// If the environment variable was not set, silently assume it is empty. +/// +/// @param arg Points to the '$'. It is advanced to after the name. +/// @return FAIL if the name is invalid. +/// static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) { - char_u *string = NULL; - int len; - int cc; - char_u *name; - int mustfree = FALSE; + char_u *name; + char_u *string = NULL; + int mustfree = FALSE; + int len; + int cc; ++*arg; name = *arg; len = get_env_len(arg); + if (evaluate) { - if (len != 0) { - cc = name[len]; - name[len] = '\0'; - /* first try vim_getenv(), fast for normal environment vars */ - string = vim_getenv(name, &mustfree); - if (string != NULL && *string != '\0') { - if (!mustfree) - string = vim_strsave(string); - } else { - if (mustfree) - vim_free(string); - - /* next try expanding things like $VIM and ${HOME} */ - string = expand_env_save(name - 1); - if (string != NULL && *string == '$') { - vim_free(string); - string = NULL; - } + if (len == 0) { + return FAIL; // Can't be an environment variable. + } + cc = name[len]; + name[len] = '\0'; + // First try vim_getenv(), fast for normal environment vars. + string = vim_getenv(name, &mustfree); + if (string != NULL && *string != '\0') { + if (!mustfree) { + string = vim_strsave(string); + } + } else { + if (mustfree) { + vim_free(string); + } + + // Next try expanding things like $VIM and ${HOME}. + string = expand_env_save(name - 1); + if (string != NULL && *string == '$') { + vim_free(string); + string = NULL; } - name[len] = cc; } + name[len] = cc; rettv->v_type = VAR_STRING; rettv->vval.v_string = string; } |