comparison src/eval.c @ 5858:00228400629e v7.4.272

updated for version 7.4.272 Problem: Using just "$" does not cause an error message. Solution: Check for empty environment variable name. (Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Tue, 29 Apr 2014 17:41:22 +0200
parents 1a5ed2626b26
children b4ce0e1fb5a6
comparison
equal deleted inserted replaced
5857:fddd2a7b6ea7 5858:00228400629e
7796 7796
7797 /* 7797 /*
7798 * Get the value of an environment variable. 7798 * Get the value of an environment variable.
7799 * "arg" is pointing to the '$'. It is advanced to after the name. 7799 * "arg" is pointing to the '$'. It is advanced to after the name.
7800 * If the environment variable was not set, silently assume it is empty. 7800 * If the environment variable was not set, silently assume it is empty.
7801 * Always return OK. 7801 * Return FAIL if the name is invalid.
7802 */ 7802 */
7803 static int 7803 static int
7804 get_env_tv(arg, rettv, evaluate) 7804 get_env_tv(arg, rettv, evaluate)
7805 char_u **arg; 7805 char_u **arg;
7806 typval_T *rettv; 7806 typval_T *rettv;
7815 ++*arg; 7815 ++*arg;
7816 name = *arg; 7816 name = *arg;
7817 len = get_env_len(arg); 7817 len = get_env_len(arg);
7818 if (evaluate) 7818 if (evaluate)
7819 { 7819 {
7820 if (len != 0) 7820 if (len == 0)
7821 { 7821 return FAIL; /* can't be an environment variable */
7822 cc = name[len]; 7822
7823 name[len] = NUL; 7823 cc = name[len];
7824 /* first try vim_getenv(), fast for normal environment vars */ 7824 name[len] = NUL;
7825 string = vim_getenv(name, &mustfree); 7825 /* first try vim_getenv(), fast for normal environment vars */
7826 if (string != NULL && *string != NUL) 7826 string = vim_getenv(name, &mustfree);
7827 if (string != NULL && *string != NUL)
7828 {
7829 if (!mustfree)
7830 string = vim_strsave(string);
7831 }
7832 else
7833 {
7834 if (mustfree)
7835 vim_free(string);
7836
7837 /* next try expanding things like $VIM and ${HOME} */
7838 string = expand_env_save(name - 1);
7839 if (string != NULL && *string == '$')
7827 { 7840 {
7828 if (!mustfree) 7841 vim_free(string);
7829 string = vim_strsave(string); 7842 string = NULL;
7830 } 7843 }
7831 else 7844 }
7832 { 7845 name[len] = cc;
7833 if (mustfree) 7846
7834 vim_free(string);
7835
7836 /* next try expanding things like $VIM and ${HOME} */
7837 string = expand_env_save(name - 1);
7838 if (string != NULL && *string == '$')
7839 {
7840 vim_free(string);
7841 string = NULL;
7842 }
7843 }
7844 name[len] = cc;
7845 }
7846 rettv->v_type = VAR_STRING; 7847 rettv->v_type = VAR_STRING;
7847 rettv->vval.v_string = string; 7848 rettv->vval.v_string = string;
7848 } 7849 }
7849 7850
7850 return OK; 7851 return OK;