]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.272 v7.4.272
authorBram Moolenaar <Bram@vim.org>
Tue, 29 Apr 2014 15:41:22 +0000 (17:41 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 29 Apr 2014 15:41:22 +0000 (17:41 +0200)
Problem:    Using just "$" does not cause an error message.
Solution:   Check for empty environment variable name. (Christian Brabandt)

src/eval.c
src/testdir/test_eval.in
src/testdir/test_eval.ok
src/version.c

index 3e1088a1e23c97847e7c01df191e3766ace06ac2..5085b975b8b5114c6e1f99c234f77987e47a9d23 100644 (file)
@@ -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;
     }
index 8c3d839a44fb67576c130ae3b4809cc282bec9b4..11bc7e8e676f39e815119bc6e67f03b7239f9872 100644 (file)
@@ -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()
index f81927bae793f17312ce2f6dad8cf7fba80c8454..313f39eef393647a0c4727c03c1f546a10eaf8e0 100644 (file)
Binary files a/src/testdir/test_eval.ok and b/src/testdir/test_eval.ok differ
index 929925793bf7d922b46a8cb491d97802568066c9..06b949453bc67bd3523ce5fb6acc2019d3823936 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    272,
 /**/
     271,
 /**/