aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/option.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/option.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/option.c')
-rw-r--r--src/nvim/option.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 8b12a6f2a1..057937f60e 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1804,19 +1804,20 @@ void set_init_1(void)
# endif
int len;
garray_T ga;
- bool mustfree;
ga_init(&ga, 1, 100);
for (size_t n = 0; n < ARRAY_SIZE(names); ++n) {
- mustfree = FALSE;
+ bool mustfree = true;
# ifdef UNIX
- if (*names[n] == NUL)
+ if (*names[n] == NUL) {
p = (char_u *)"/tmp";
+ mustfree = false;
+ }
else
# endif
- p = (char_u *)vim_getenv(names[n], &mustfree);
+ p = (char_u *)vim_getenv(names[n]);
if (p != NULL && *p != NUL) {
- /* First time count the NUL, otherwise count the ','. */
+ // First time count the NUL, otherwise count the ','.
len = (int)STRLEN(p) + 3;
ga_grow(&ga, len);
if (!GA_EMPTY(&ga))
@@ -1826,8 +1827,9 @@ void set_init_1(void)
STRCAT(ga.ga_data, "*");
ga.ga_len += len;
}
- if (mustfree)
+ if(mustfree) {
xfree(p);
+ }
}
if (ga.ga_data != NULL) {
set_string_default("bsk", ga.ga_data);
@@ -1861,10 +1863,9 @@ void set_init_1(void)
char_u *buf;
int i;
int j;
- bool mustfree = false;
/* Initialize the 'cdpath' option's default value. */
- cdpath = (char_u *)vim_getenv("CDPATH", &mustfree);
+ cdpath = (char_u *)vim_getenv("CDPATH");
if (cdpath != NULL) {
buf = xmalloc(2 * STRLEN(cdpath) + 2);
{
@@ -1887,8 +1888,7 @@ void set_init_1(void)
} else
xfree(buf); /* cannot happen */
}
- if (mustfree)
- xfree(cdpath);
+ xfree(cdpath);
}
}
@@ -7428,11 +7428,10 @@ static void paste_option_changed(void)
/// When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
void vimrc_found(char_u *fname, char_u *envname)
{
- bool dofree = false;
char_u *p;
if (fname != NULL) {
- p = (char_u *)vim_getenv((char *)envname, &dofree);
+ p = (char_u *)vim_getenv((char *)envname);
if (p == NULL) {
/* Set $MYVIMRC to the first vimrc file found. */
p = FullName_save(fname, FALSE);
@@ -7440,8 +7439,9 @@ void vimrc_found(char_u *fname, char_u *envname)
vim_setenv((char *)envname, (char *)p);
xfree(p);
}
- } else if (dofree)
+ } else {
xfree(p);
+ }
}
}