aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorMark Bainter <mbainter+github@gmail.com>2015-04-12 22:31:00 +0000
committerMark Bainter <mbainter+github@gmail.com>2015-04-18 21:37:10 +0000
commita7e17de048b0791329cf1ad4d4c291290a99040a (patch)
tree39381ae903acab0bf818c7cce68fce1997d29255 /src/nvim/eval.c
parent08c08ecdf3c4837889d837dbe4a3ace0bd301ead (diff)
downloadrneovim-a7e17de048b0791329cf1ad4d4c291290a99040a.tar.gz
rneovim-a7e17de048b0791329cf1ad4d4c291290a99040a.tar.bz2
rneovim-a7e17de048b0791329cf1ad4d4c291290a99040a.zip
Refactor get_env() to respect const qualifier
Without the casts*, the compiler rightly warns about the os_getenv losing the qualifier. This refactor adds a variable to manage this properly, and renames the original variables to increase clarity.
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 405b2b1e98..6cabdcc45e 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1751,13 +1751,11 @@ ex_let_one (
name[len] = NUL;
p = get_tv_string_chk(tv);
if (p != NULL && op != NULL && *op == '.') {
- bool mustfree = false;
- char *s = vim_getenv((char *)name, &mustfree);
+ char *s = vim_getenv((char *)name);
if (s != NULL) {
p = tofree = concat_str((char_u *)s, p);
- if (mustfree)
- xfree(s);
+ xfree(s);
}
}
if (p != NULL) {
@@ -6357,7 +6355,6 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
{
char_u *name;
char_u *string = NULL;
- bool mustfree = false;
int len;
int cc;
@@ -6372,15 +6369,9 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
cc = name[len];
name[len] = NUL;
// First try vim_getenv(), fast for normal environment vars.
- string = (char_u *)vim_getenv((char *)name, &mustfree);
- if (string != NULL && *string != NUL) {
- if (!mustfree) {
- string = vim_strsave(string);
- }
- } else {
- if (mustfree) {
- xfree(string);
- }
+ string = (char_u *)vim_getenv((char *)name);
+ if (string == NULL || *string == NUL) {
+ xfree(string);
// Next try expanding things like $VIM and ${HOME}.
string = expand_env_save(name - 1);