diff options
author | Bram Moolenaar <Bram@vim.org> | 2014-04-29 17:41:22 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2014-04-29 17:41:22 +0200 |
commit | e512c8c049c2e5768c0ea86531093224e2919955 (patch) | |
tree | b6fb316e5a71cd082f037f3f1a8bb31a6d532426 /src | |
parent | 121f9bdde4a474ae729fd0b1e5fc9ad1ffcd8651 (diff) | |
download | vim-e512c8c049c2e5768c0ea86531093224e2919955.zip |
updated for version 7.4.272
Problem: Using just "$" does not cause an error message.
Solution: Check for empty environment variable name. (Christian Brabandt)
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 47 | ||||
-rw-r--r-- | src/testdir/test_eval.in | 7 | ||||
-rw-r--r-- | src/testdir/test_eval.ok | bin | 10932 -> 10986 bytes | |||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 33 insertions, 23 deletions
diff --git a/src/eval.c b/src/eval.c index 3e1088a1e..5085b975b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -7798,7 +7798,7 @@ string2float(text, value) * 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. + * Return FAIL if the name is invalid. */ static int get_env_tv(arg, rettv, evaluate) @@ -7817,32 +7817,33 @@ get_env_tv(arg, rettv, evaluate) len = get_env_len(arg); if (evaluate) { - if (len != 0) + if (len == 0) + return FAIL; /* can't be an environment variable */ + + cc = name[len]; + name[len] = NUL; + /* first try vim_getenv(), fast for normal environment vars */ + string = vim_getenv(name, &mustfree); + if (string != NULL && *string != NUL) { - cc = name[len]; - name[len] = NUL; - /* first try vim_getenv(), fast for normal environment vars */ - string = vim_getenv(name, &mustfree); - if (string != NULL && *string != NUL) - { - if (!mustfree) - string = vim_strsave(string); - } - else - { - if (mustfree) - vim_free(string); + 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; - } + /* 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; } diff --git a/src/testdir/test_eval.in b/src/testdir/test_eval.in index 8c3d839a4..11bc7e8e6 100644 --- a/src/testdir/test_eval.in +++ b/src/testdir/test_eval.in @@ -183,6 +183,13 @@ endfun :" script-local function used in Funcref must exist. :so test_eval_func.vim :" +:" Using $ instead of '$' must give an error +:try +: call append($, 'foobar') +:catch +:$put =v:exception +:endtry +:" :/^start:/+1,$wq! test.out :" vim: et ts=4 isk-=\: fmr=???,??? :call getchar() diff --git a/src/testdir/test_eval.ok b/src/testdir/test_eval.ok Binary files differindex f81927bae..313f39eef 100644 --- a/src/testdir/test_eval.ok +++ b/src/testdir/test_eval.ok diff --git a/src/version.c b/src/version.c index 929925793..06b949453 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 272, +/**/ 271, /**/ 270, |