diff options
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 45f317fbea..4501c2e0a6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5162,12 +5162,18 @@ dict_equal ( dictitem_T *item2; int todo; - if (d1 == NULL || d2 == NULL) - return FALSE; - if (d1 == d2) - return TRUE; - if (dict_len(d1) != dict_len(d2)) - return FALSE; + if (d1 == NULL && d2 == NULL) { + return true; + } + if (d1 == NULL || d2 == NULL) { + return false; + } + if (d1 == d2) { + return true; + } + if (dict_len(d1) != dict_len(d2)) { + return false; + } todo = (int)d1->dv_hashtab.ht_used; for (hi = d1->dv_hashtab.ht_array; todo > 0; ++hi) { @@ -6669,9 +6675,12 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len) char_u *tofree = NULL; hashitem_T *hi; - if (len < 0) + if (d == NULL) { + return NULL; + } + if (len < 0) { akey = key; - else if (len >= AKEYLEN) { + } else if (len >= AKEYLEN) { tofree = akey = vim_strnsave(key, len); } else { /* Avoid a malloc/free by using buf[]. */ @@ -9242,7 +9251,7 @@ static void filter_map(typval_T *argvars, typval_T *rettv, int map) dict_T *d = NULL; typval_T save_val; typval_T save_key; - int rem; + int rem = false; int todo; char_u *ermsg = (char_u *)(map ? "map()" : "filter()"); char_u *arg_errmsg = (char_u *)(map ? N_("map() argument") @@ -10067,7 +10076,7 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) } else if (STRCMP(varname, "changedtick") == 0) { rettv->v_type = VAR_NUMBER; rettv->vval.v_number = curbuf->b_changedtick; - done = TRUE; + done = true; } else { /* Look up the variable. */ /* Let getbufvar({nr}, "") return the "b:" dictionary. */ @@ -15064,7 +15073,6 @@ static void f_serverstop(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) { buf_T *buf; - aco_save_T aco; char_u *varname, *bufvarname; typval_T *varp; char_u nbuf[NUMBUFLEN]; @@ -15077,29 +15085,34 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) varp = &argvars[2]; if (buf != NULL && varname != NULL && varp != NULL) { - /* set curbuf to be our buf, temporarily */ - aucmd_prepbuf(&aco, buf); - if (*varname == '&') { long numval; char_u *strval; - int error = FALSE; + int error = false; + aco_save_T aco; + + // set curbuf to be our buf, temporarily + aucmd_prepbuf(&aco, buf); ++varname; numval = get_tv_number_chk(varp, &error); strval = get_tv_string_buf_chk(varp, nbuf); if (!error && strval != NULL) set_option_value(varname, numval, strval, OPT_LOCAL); + + // reset notion of buffer + aucmd_restbuf(&aco); } else { + buf_T *save_curbuf = curbuf; + bufvarname = xmalloc(STRLEN(varname) + 3); + curbuf = buf; STRCPY(bufvarname, "b:"); STRCPY(bufvarname + 2, varname); set_var(bufvarname, varp, TRUE); xfree(bufvarname); + curbuf = save_curbuf; } - - /* reset notion of buffer */ - aucmd_restbuf(&aco); } } @@ -15516,7 +15529,10 @@ static void f_setreg(typval_T *argvars, typval_T *rettv, FunPtr fptr) } if (argvars[1].v_type == VAR_LIST) { - int len = argvars[1].vval.v_list->lv_len; + list_T *ll = argvars[1].vval.v_list; + // If the list is NULL handle like an empty list. + int len = ll == NULL ? 0 : ll->lv_len; + // First half: use for pointers to result lines; second half: use for // pointers to allocated copies. char_u **lstval = xmalloc(sizeof(char_u *) * ((len + 1) * 2)); @@ -15525,7 +15541,7 @@ static void f_setreg(typval_T *argvars, typval_T *rettv, FunPtr fptr) char_u **curallocval = allocval; char_u buf[NUMBUFLEN]; - for (listitem_T *li = argvars[1].vval.v_list->lv_first; + for (listitem_T *li = ll == NULL ? NULL : ll->lv_first; li != NULL; li = li->li_next) { char_u *strval = get_tv_string_buf_chk(&li->li_tv, buf); @@ -17249,14 +17265,6 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } -/* - * "test(list)" function: Just checking the walls... - */ -static void f_test(typval_T *argvars, typval_T *rettv, FunPtr fptr) -{ - /* Used for unit testing. Change the code below to your liking. */ -} - static bool callback_from_typval(Callback *callback, typval_T *arg) { if (arg->v_type == VAR_PARTIAL && arg->vval.v_partial != NULL) { |