summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-01-26 12:00:00 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-26 12:00:00 +0000
commit142ed77898facf8f423fee2717efee1749c55f9a (patch)
tree9b8f51cd7992358ae3a01c9cd152eed223d1827e
parent032713f8299abd92fcfb1e490d1ae5c1ecadde41 (diff)
patch 9.0.1246: code is indented more than necessaryv9.0.1246
Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11887)
-rw-r--r--src/ui.c54
-rw-r--r--src/undo.c68
-rw-r--r--src/uninstall.c56
-rw-r--r--src/userfunc.c57
-rw-r--r--src/version.c34
-rw-r--r--src/vim9compile.c34
-rw-r--r--src/vim9execute.c96
-rw-r--r--src/vim9instr.c60
-rw-r--r--src/vim9script.c67
-rw-r--r--src/vim9type.c32
-rw-r--r--src/viminfo.c284
-rw-r--r--src/winclip.c41
-rw-r--r--src/window.c132
13 files changed, 505 insertions, 510 deletions
diff --git a/src/ui.c b/src/ui.c
index 7658c52817..2e78f8adfb 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -83,20 +83,20 @@ ui_inchar_undo(char_u *s, int len)
if (ta_str != NULL)
newlen += ta_len - ta_off;
new = alloc(newlen);
- if (new != NULL)
+ if (new == NULL)
+ return;
+
+ if (ta_str != NULL)
{
- if (ta_str != NULL)
- {
- mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off));
- mch_memmove(new + ta_len - ta_off, s, (size_t)len);
- vim_free(ta_str);
- }
- else
- mch_memmove(new, s, (size_t)len);
- ta_str = new;
- ta_len = newlen;
- ta_off = 0;
+ mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off));
+ mch_memmove(new + ta_len - ta_off, s, (size_t)len);
+ vim_free(ta_str);
}
+ else
+ mch_memmove(new, s, (size_t)len);
+ ta_str = new;
+ ta_len = newlen;
+ ta_off = 0;
}
#endif
@@ -815,25 +815,25 @@ set_input_buf(char_u *p, int overwrite)
{
garray_T *gap = (garray_T *)p;
- if (gap != NULL)
+ if (gap == NULL)
+ return;
+
+ if (gap->ga_data != NULL)
{
- if (gap->ga_data != NULL)
+ if (overwrite || inbufcount + gap->ga_len >= INBUFLEN)
{
- if (overwrite || inbufcount + gap->ga_len >= INBUFLEN)
- {
- mch_memmove(inbuf, gap->ga_data, gap->ga_len);
- inbufcount = gap->ga_len;
- }
- else
- {
- mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount);
- mch_memmove(inbuf, gap->ga_data, gap->ga_len);
- inbufcount += gap->ga_len;
- }
- vim_free(gap->ga_data);
+ mch_memmove(inbuf, gap->ga_data, gap->ga_len);
+ inbufcount = gap->ga_len;
+ }
+ else
+ {
+ mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount);
+ mch_memmove(inbuf, gap->ga_data, gap->ga_len);
+ inbufcount += gap->ga_len;
}
- vim_free(gap);
+ vim_free(gap->ga_data);
}
+ vim_free(gap);
}
/*
diff --git a/src/undo.c b/src/undo.c
index 52455df16c..ea7619c43d 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -1164,21 +1164,21 @@ read_string_decrypt(bufinfo_T *bi, int len)
{
char_u *ptr = alloc(len + 1);
- if (ptr != NULL)
+ if (ptr == NULL)
+ return NULL;
+
+ if (len > 0 && undo_read(bi, ptr, len) == FAIL)
{
- if (len > 0 && undo_read(bi, ptr, len) == FAIL)
- {
- vim_free(ptr);
- return NULL;
- }
- // In case there are text properties there already is a NUL, but
- // checking for that is more expensive than just adding a dummy byte.
- ptr[len] = NUL;
+ vim_free(ptr);
+ return NULL;
+ }
+ // In case there are text properties there already is a NUL, but
+ // checking for that is more expensive than just adding a dummy byte.
+ ptr[len] = NUL;
#ifdef FEAT_CRYPT
- if (bi->bi_state != NULL && bi->bi_buffer == NULL)
- crypt_decode_inplace(bi->bi_state, ptr, len, FALSE);
+ if (bi->bi_state != NULL && bi->bi_buffer == NULL)
+ crypt_decode_inplace(bi->bi_state, ptr, len, FALSE);
#endif
- }
return ptr;
}
@@ -3510,12 +3510,12 @@ u_saveline(linenr_T lnum)
void
u_clearline(void)
{
- if (curbuf->b_u_line_ptr.ul_line != NULL)
- {
- VIM_CLEAR(curbuf->b_u_line_ptr.ul_line);
- curbuf->b_u_line_ptr.ul_len = 0;
- curbuf->b_u_line_lnum = 0;
- }
+ if (curbuf->b_u_line_ptr.ul_line == NULL)
+ return;
+
+ VIM_CLEAR(curbuf->b_u_line_ptr.ul_line);
+ curbuf->b_u_line_ptr.ul_len = 0;
+ curbuf->b_u_line_lnum = 0;
}
/*
@@ -3726,24 +3726,24 @@ u_undofile_reset_and_delete(buf_T *buf)
void
f_undotree(typval_T *argvars UNUSED, typval_T *rettv)
{
- if (rettv_dict_alloc(rettv) == OK)
- {
- dict_T *dict = rettv->vval.v_dict;
- list_T *list;
+ if (rettv_dict_alloc(rettv) == FAIL)
+ return;
- dict_add_number(dict, "synced", (long)curbuf->b_u_synced);
- dict_add_number(dict, "seq_last", curbuf->b_u_seq_last);
- dict_add_number(dict, "save_last", curbuf->b_u_save_nr_last);
- dict_add_number(dict, "seq_cur", curbuf->b_u_seq_cur);
- dict_add_number(dict, "time_cur", (long)curbuf->b_u_time_cur);
- dict_add_number(dict, "save_cur", curbuf->b_u_save_nr_cur);
+ dict_T *dict = rettv->vval.v_dict;
+ list_T *list;
- list = list_alloc();
- if (list != NULL)
- {
- u_eval_tree(curbuf->b_u_oldhead, list);
- dict_add_list(dict, "entries", list);
- }
+ dict_add_number(dict, "synced", (long)curbuf->b_u_synced);
+ dict_add_number(dict, "seq_last", curbuf->b_u_seq_last);
+ dict_add_number(dict, "save_last", curbuf->b_u_save_nr_last);
+ dict_add_number(dict, "seq_cur", curbuf->b_u_seq_cur);
+ dict_add_number(dict, "time_cur", (long)curbuf->b_u_time_cur);
+ dict_add_number(dict, "save_cur", curbuf->b_u_save_nr_cur);
+
+ list = list_alloc();
+ if (list != NULL)
+ {
+ u_eval_tree(curbuf->b_u_oldhead, list);
+ dict_add_list(dict, "entries", list);
}
}
diff --git a/src/uninstall.c b/src/uninstall.c
index c84189f564..78b2b7d3cf 100644
--- a/src/uninstall.c
+++ b/src/uninstall.c
@@ -205,18 +205,18 @@ batfile_thisversion(char *path)
int found = FALSE;
fd = fopen(path, "r");
- if (fd != NULL)
+ if (fd == NULL)
+ return FALSE;
+
+ while (fgets(line, sizeof(line), fd) != NULL)
{
- while (fgets(line, sizeof(line), fd) != NULL)
+ if (strncmp(line, VIMBAT_UNINSTKEY, key_len) == 0)
{
- if (strncmp(line, VIMBAT_UNINSTKEY, key_len) == 0)
- {
- found = TRUE;
- break;
- }
+ found = TRUE;
+ break;
}
- fclose(fd);
}
+ fclose(fd);
return found;
}
@@ -261,12 +261,12 @@ remove_if_exists(char *path, char *filename)
sprintf(buf, "%s\\%s", path, filename);
fd = fopen(buf, "r");
- if (fd != NULL)
- {
- fclose(fd);
- printf("removing %s\n", buf);
- remove(buf);
- }
+ if (fd == NULL)
+ return;
+
+ fclose(fd);
+ printf("removing %s\n", buf);
+ remove(buf);
}
static void
@@ -287,21 +287,21 @@ remove_start_menu(void)
int i;
struct stat st;
- if (get_shell_folder_path(path, VIM_STARTMENU))
+ if (get_shell_folder_path(path, VIM_STARTMENU) == FAIL)
+ return;
+
+ for (i = 1; i < TARGET_COUNT; ++i)
+ remove_if_exists(path, targets[i].lnkname);
+ remove_if_exists(path, "uninstall.lnk");
+ remove_if_exists(path, "Help.lnk");
+ // Win95 uses .pif, WinNT uses .lnk
+ remove_if_exists(path, "Vim tutor.pif");
+ remove_if_exists(path, "Vim tutor.lnk");
+ remove_if_exists(path, "Vim online.url");
+ if (stat(path, &st) == 0)
{
- for (i = 1; i < TARGET_COUNT; ++i)
- remove_if_exists(path, targets[i].lnkname);
- remove_if_exists(path, "uninstall.lnk");
- remove_if_exists(path, "Help.lnk");
- // Win95 uses .pif, WinNT uses .lnk
- remove_if_exists(path, "Vim tutor.pif");
- remove_if_exists(path, "Vim tutor.lnk");
- remove_if_exists(path, "Vim online.url");
- if (stat(path, &st) == 0)
- {
- printf("removing %s\n", path);
- rmdir(path);
- }
+ printf("removing %s\n", path);
+ rmdir(path);
}
}
diff --git a/src/userfunc.c b/src/userfunc.c
index 77a9fc2e61..1009cd7ff0 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -770,25 +770,25 @@ is_function_cmd(char_u **cmd)
static void
function_using_block_scopes(ufunc_T *fp, cstack_T *cstack)
{
- if (cstack != NULL && cstack->cs_idx >= 0)
- {
- int count = cstack->cs_idx + 1;
- int i;
+ if (cstack == NULL || cstack->cs_idx < 0)
+ return;
- fp->uf_block_ids = ALLOC_MULT(int, count);
- if (fp->uf_block_ids != NULL)
- {
- mch_memmove(fp->uf_block_ids, cstack->cs_block_id,
- sizeof(int) * count);
- fp->uf_block_depth = count;
- }
+ int count = cstack->cs_idx + 1;
+ int i;
- // Set flag in each block to indicate a function was defined. This
- // is used to keep the variable when leaving the block, see
- // hide_script_var().
- for (i = 0; i <= cstack->cs_idx; ++i)
- cstack->cs_flags[i] |= CSF_FUNC_DEF;
+ fp->uf_block_ids = ALLOC_MULT(int, count);
+ if (fp->uf_block_ids != NULL)
+ {
+ mch_memmove(fp->uf_block_ids, cstack->cs_block_id,
+ sizeof(int) * count);
+ fp->uf_block_depth = count;
}
+
+ // Set flag in each block to indicate a function was defined. This
+ // is used to keep the variable when leaving the block, see
+ // hide_script_var().
+ for (i = 0; i <= cstack->cs_idx; ++i)
+ cstack->cs_flags[i] |= CSF_FUNC_DEF;
}
/*
@@ -2433,21 +2433,20 @@ func_remove(ufunc_T *fp)
return FALSE;
hi = hash_find(&func_hashtab, UF2HIKEY(fp));
- if (!HASHITEM_EMPTY(hi))
+ if (HASHITEM_EMPTY(hi))
+ return FALSE;
+
+ // When there is a def-function index do not actually remove the
+ // function, so we can find the index when defining the function again.
+ // Do remove it when it's a copy.
+ if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0)
{
- // When there is a def-function index do not actually remove the
- // function, so we can find the index when defining the function again.
- // Do remove it when it's a copy.
- if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0)
- {
- fp->uf_flags |= FC_DEAD;
- return FALSE;
- }
- hash_remove(&func_hashtab, hi, "remove function");
- fp->uf_flags |= FC_DELETED;
- return TRUE;
+ fp->uf_flags |= FC_DEAD;
+ return FALSE;
}
- return FALSE;
+ hash_remove(&func_hashtab, hi, "remove function");
+ fp->uf_flags |= FC_DELETED;
+ return TRUE;
}
static void
diff --git a/src/version.c b/src/version.c
index 84657fd19a..12f444a8c7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -57,26 +57,26 @@ char *longVersion = NULL;
void
init_longVersion(void)
{
- if (longVersion == NULL)
- {
+ if (longVersion != NULL)
+ return;
+
#ifdef BUILD_DATE
- char *date_time = BUILD_DATE;
+ char *date_time = BUILD_DATE;
#else
- char *date_time = __DATE__ " " __TIME__;
+ char *date_time = __DATE__ " " __TIME__;
#endif
- char *msg = _("%s (%s, compiled %s)");
- size_t len = strlen(msg)
- + strlen(VIM_VERSION_LONG_ONLY)
- + strlen(VIM_VERSION_DATE_ONLY)
- + strlen(date_time);
+ char *msg = _("%s (%s, compiled %s)");
+ size_t len = strlen(msg)
+ + strlen(VIM_VERSION_LONG_ONLY)
+ + strlen(VIM_VERSION_DATE_ONLY)
+ + strlen(date_time);
- longVersion = alloc(len);
- if (longVersion == NULL)
- longVersion = VIM_VERSION_LONG;
- else
- vim_snprintf(longVersion, len, msg,
- VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
- }
+ longVersion = alloc(len);
+ if (longVersion == NULL)
+ longVersion = VIM_VERSION_LONG;
+ else
+ vim_snprintf(longVersion, len, msg,
+ VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
}
# endif
#else
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1246,
+/**/
1245,
/**/
1244,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 3a55186de0..3f97c007bb 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3939,18 +3939,18 @@ delete_def_function_contents(dfunc_T *dfunc, int mark_deleted)
void
unlink_def_function(ufunc_T *ufunc)
{
- if (ufunc->uf_dfunc_idx > 0)
- {
- dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
- + ufunc->uf_dfunc_idx;
+ if (ufunc->uf_dfunc_idx <= 0)
+ return;
- if (--dfunc->df_refcount <= 0)
- delete_def_function_contents(dfunc, TRUE);
- ufunc->uf_def_status = UF_NOT_COMPILED;
- ufunc->uf_dfunc_idx = 0;
- if (dfunc->df_ufunc == ufunc)
- dfunc->df_ufunc = NULL;
- }
+ dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
+ + ufunc->uf_dfunc_idx;
+
+ if (--dfunc->df_refcount <= 0)
+ delete_def_function_contents(dfunc, TRUE);
+ ufunc->uf_def_status = UF_NOT_COMPILED;
+ ufunc->uf_dfunc_idx = 0;
+ if (dfunc->df_ufunc == ufunc)
+ dfunc->df_ufunc = NULL;
}
/*
@@ -3959,13 +3959,13 @@ unlink_def_function(ufunc_T *ufunc)
void
link_def_function(ufunc_T *ufunc)
{
- if (ufunc->uf_dfunc_idx > 0)
- {
- dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
- + ufunc->uf_dfunc_idx;
+ if (ufunc->uf_dfunc_idx <= 0)
+ return;
- ++dfunc->df_refcount;
- }
+ dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
+ + ufunc->uf_dfunc_idx;
+
+ ++dfunc->df_refcount;
}
#if defined(EXITFREE) || defined(PROTO)
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 57f875de35..22e1e58eb8 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -279,14 +279,14 @@ exe_newdict(int count, ectx_T *ectx)
void
update_has_breakpoint(ufunc_T *ufunc)
{
- if (ufunc->uf_debug_tick != debug_tick)
- {
- linenr_T breakpoint;
+ if (ufunc->uf_debug_tick == debug_tick)
+ return;
- ufunc->uf_debug_tick = debug_tick;
- breakpoint = dbg_find_breakpoint(FALSE, ufunc->uf_name, 0);
- ufunc->uf_has_breakpoint = breakpoint > 0;
- }
+ linenr_T breakpoint;
+
+ ufunc->uf_debug_tick = debug_tick;
+ breakpoint = dbg_find_breakpoint(FALSE, ufunc->uf_name, 0);
+ ufunc->uf_has_breakpoint = breakpoint > 0;
}
static garray_T dict_stack = GA_EMPTY;
@@ -383,29 +383,29 @@ get_pt_outer(partial_T *pt)
static int
check_ufunc_arg_types(ufunc_T *ufunc, int argcount, int off, ectx_T *ectx)
{
- if (ufunc->uf_arg_types != NULL || ufunc->uf_va_type != NULL)
+ if (ufunc->uf_arg_types == NULL && ufunc->uf_va_type == NULL)
+ return OK;
+
+ typval_T *argv = STACK_TV_BOT(0) - argcount - off;
+
+ // The function can change at runtime, check that the argument
+ // types are correct.
+ for (int i = 0; i < argcount; ++i)
{
- typval_T *argv = STACK_TV_BOT(0) - argcount - off;
+ type_T *type = NULL;
- // The function can change at runtime, check that the argument
- // types are correct.
- for (int i = 0; i < argcount; ++i)
- {
- type_T *type = NULL;
-
- // assume a v:none argument, using the default value, is always OK
- if (argv[i].v_type == VAR_SPECIAL
- && argv[i].vval.v_number == VVAL_NONE)
- continue;
-
- if (i < ufunc->uf_args.ga_len && ufunc->uf_arg_types != NULL)
- type = ufunc->uf_arg_types[i];
- else if (ufunc->uf_va_type != NULL)
- type = ufunc->uf_va_type->tt_member;
- if (type != NULL && check_typval_arg_type(type,
- &argv[i], NULL, i + 1) == FAIL)
- return FAIL;
- }
+ // assume a v:none argument, using the default value, is always OK
+ if (argv[i].v_type == VAR_SPECIAL
+ && argv[i].vval.v_number == VVAL_NONE)
+ continue;
+
+ if (i < ufunc->uf_args.ga_len && ufunc->uf_arg_types != NULL)
+ type = ufunc->uf_arg_types[i];
+ else if (ufunc->uf_va_type != NULL)
+ type = ufunc->uf_va_type->tt_member;
+ if (type != NULL && check_typval_arg_type(type,
+ &argv[i], NULL, i + 1) == FAIL)
+ return FAIL;
}
return OK;
}
@@ -1527,21 +1527,22 @@ store_var(char_u *name, typval_T *tv)
static int
do_2string(typval_T *tv, int is_2string_any, int tolerant)
{
- if (tv->v_type != VAR_STRING)
- {
- char_u *str;
+ if (tv->v_type == VAR_STRING)
+ return OK;
+
+ char_u *str;
- if (is_2string_any)
+ if (is_2string_any)
+ {
+ switch (tv->v_type)
{
- switch (tv->v_type)
- {
- case VAR_SPECIAL:
- case VAR_BOOL:
- case VAR_NUMBER:
- case VAR_FLOAT:
- case VAR_BLOB: break;
+ case VAR_SPECIAL:
+ case VAR_BOOL:
+ case VAR_NUMBER:
+ case VAR_FLOAT:
+ case VAR_BLOB: break;
- case VAR_LIST:
+ case VAR_LIST:
if (tolerant)
{
char_u *s, *e, *p;
@@ -1560,7 +1561,7 @@ do_2string(typval_T *tv, int is_2string_any, int tolerant)
{
*e = NUL;
p = vim_strsave_fnameescape(s,
- VSE_NONE);
+ VSE_NONE);
if (p != NULL)
{
ga_concat(&ga, p);
@@ -1576,15 +1577,14 @@ do_2string(typval_T *tv, int is_2string_any, int tolerant)
return OK;
}
// FALLTHROUGH
- default: to_string_error(tv->v_type);
- return FAIL;
- }
+ default: to_string_error(tv->v_type);
+ return FAIL;
}
- str = typval_tostring(tv, TRUE);
- clear_tv(tv);
- tv->v_type = VAR_STRING;
- tv->vval.v_string = str;
}
+ str = typval_tostring(tv, TRUE);
+ clear_tv(tv);
+ tv->v_type = VAR_STRING;
+ tv->vval.v_string = str;
return OK;
}
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 8b11705712..c86f4cf8d7 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -2306,41 +2306,41 @@ generate_store_lhs(cctx_T *cctx, lhs_T *lhs, int instr_count, int is_decl)
lhs->lhs_opt_flags, lhs->lhs_vimvaridx,
lhs->lhs_type, lhs->lhs_name, lhs);
- if (lhs->lhs_lvar != NULL)
+ if (lhs->lhs_lvar == NULL)
+ return OK;
+
+ garray_T *instr = &cctx->ctx_instr;
+ isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
+
+ // Optimization: turn "var = 123" from ISN_PUSHNR + ISN_STORE into
+ // ISN_STORENR.
+ // And "var = 0" does not need any instruction.
+ if (lhs->lhs_lvar->lv_from_outer == 0
+ && instr->ga_len == instr_count + 1
+ && isn->isn_type == ISN_PUSHNR)
{
- garray_T *instr = &cctx->ctx_instr;
- isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
-
- // Optimization: turn "var = 123" from ISN_PUSHNR + ISN_STORE into
- // ISN_STORENR.
- // And "var = 0" does not need any instruction.
- if (lhs->lhs_lvar->lv_from_outer == 0
- && instr->ga_len == instr_count + 1
- && isn->isn_type == ISN_PUSHNR)
- {
- varnumber_T val = isn->isn_arg.number;
- garray_T *stack = &cctx->ctx_type_stack;
+ varnumber_T val = isn->isn_arg.number;
+ garray_T *stack = &cctx->ctx_type_stack;
- if (val == 0 && is_decl && !inside_loop_scope(cctx))
- {
- // zero is the default value, no need to do anything
- --instr->ga_len;
- }
- else
- {
- isn->isn_type = ISN_STORENR;
- isn->isn_arg.storenr.stnr_idx = lhs->lhs_lvar->lv_idx;
- isn->isn_arg.storenr.stnr_val = val;
- }
- if (stack->ga_len > 0)
- --stack->ga_len;
+ if (val == 0 && is_decl && !inside_loop_scope(cctx))
+ {
+ // zero is the default value, no need to do anything
+ --instr->ga_len;
}
- else if (lhs->lhs_lvar->lv_from_outer > 0)
- generate_STOREOUTER(cctx, lhs->lhs_lvar->lv_idx,
- lhs->lhs_lvar->lv_from_outer, lhs->lhs_lvar->lv_loop_idx);
else
- generate_STORE(cctx, ISN_STORE, lhs->lhs_lvar->lv_idx, NULL);
+ {
+ isn->isn_type = ISN_STORENR;
+ isn->isn_arg.storenr.stnr_idx = lhs->lhs_lvar->lv_idx;
+ isn->isn_arg.storenr.stnr_val = val;
+ }
+ if (stack->ga_len > 0)
+ --stack->ga_len;
}
+ else if (lhs->lhs_lvar->lv_from_outer > 0)
+ generate_STOREOUTER(cctx, lhs->lhs_lvar->lv_idx,
+ lhs->lhs_lvar->lv_from_outer, lhs->lhs_lvar->lv_loop_idx);
+ else
+ generate_STORE(cctx, ISN_STORE, lhs->lhs_lvar->lv_idx, NULL);
return OK;
}
diff --git a/src/vim9script.c b/src/vim9script.c
index 0af7bb6d0d..fd4658c6f0 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -1007,42 +1007,43 @@ hide_script_var(scriptitem_T *si, int idx, int func_defined)
// The typval is moved into the sallvar_T.
script_hi = hash_find(script_ht, sv->sv_name);
all_hi = hash_find(all_ht, sv->sv_name);
- if (!HASHITEM_EMPTY(script_hi) && !HASHITEM_EMPTY(all_hi))
+
+ if (HASHITEM_EMPTY(script_hi) || HASHITEM_EMPTY(all_hi))
+ return;
+
+ dictitem_T *di = HI2DI(script_hi);
+ sallvar_T *sav = HI2SAV(all_hi);
+ sallvar_T *sav_prev = NULL;
+
+ // There can be multiple entries with the same name in different
+ // blocks, find the right one.
+ while (sav != NULL && sav->sav_var_vals_idx != idx)
{
- dictitem_T *di = HI2DI(script_hi);
- sallvar_T *sav = HI2SAV(all_hi);
- sallvar_T *sav_prev = NULL;
+ sav_prev = sav;
+ sav = sav->sav_next;
+ }
+ if (sav == NULL)
+ return;
- // There can be multiple entries with the same name in different
- // blocks, find the right one.
- while (sav != NULL && sav->sav_var_vals_idx != idx)
- {
- sav_prev = sav;
- sav = sav->sav_next;
- }
- if (sav != NULL)
- {
- if (func_defined)
- {
- // move the typval from the dictitem to the sallvar
- sav->sav_tv = di->di_tv;
- di->di_tv.v_type = VAR_UNKNOWN;
- sav->sav_flags = di->di_flags;
- sav->sav_di = NULL;
- sv->sv_tv = &sav->sav_tv;
- }
- else
- {
- if (sav_prev == NULL)
- hash_remove(all_ht, all_hi, "hide variable");
- else
- sav_prev->sav_next = sav->sav_next;
- sv->sv_name = NULL;
- vim_free(sav);
- }
- delete_var(script_ht, script_hi);
- }
+ if (func_defined)
+ {
+ // move the typval from the dictitem to the sallvar
+ sav->sav_tv = di->di_tv;
+ di->di_tv.v_type = VAR_UNKNOWN;
+ sav->sav_flags = di->di_flags;
+ sav->sav_di = NULL;
+ sv->sv_tv = &sav->sav_tv;
+ }
+ else
+ {
+ if (sav_prev == NULL)
+ hash_remove(all_ht, all_hi, "hide variable");
+ else
+ sav_prev->sav_next = sav->sav_next;
+ sv->sv_name = NULL;
+ vim_free(sav);
}
+ delete_var(script_ht, script_hi);
}
/*
diff --git a/src/vim9type.c b/src/vim9type.c
index 61853956e8..075eb60d54 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -37,11 +37,11 @@ get_type_ptr(garray_T *type_gap)
if (ga_grow(type_gap, 1) == FAIL)
return NULL;
type = ALLOC_CLEAR_ONE(type_T);
- if (type != NULL)
- {
- ((type_T **)type_gap->ga_data)[type_gap->ga_len] = type;
- ++type_gap->ga_len;
- }
+ if (type == NULL)
+ return NULL;
+
+ ((type_T **)type_gap->ga_data)[type_gap->ga_len] = type;
+ ++type_gap->ga_len;
return type;
}
@@ -628,17 +628,17 @@ typval2type(typval_T *tv, int copyID, garray_T *type_gap, int flags)
{
type_T *type = typval2type_int(tv, copyID, type_gap, flags);
- if (type != NULL)
- {
- if (type != &t_bool && (tv->v_type == VAR_NUMBER
- && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
- // Number 0 and 1 and expression with "&&" or "||" can also be used
- // for bool.
- type = &t_number_bool;
- else if (type != &t_float && tv->v_type == VAR_NUMBER)
- // A number can also be used for float.
- type = &t_number_float;
- }
+ if (type == NULL)
+ return NULL;
+
+ if (type != &t_bool && (tv->v_type == VAR_NUMBER
+ && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
+ // Number 0 and 1 and expression with "&&" or "||" can also be used
+ // for bool.
+ type = &t_number_bool;
+ else if (type != &t_float && tv->v_type == VAR_NUMBER)
+ // A number can also be used for float.
+ type = &t_number_float;
return type;
}
diff --git a/src/viminfo.c b/src/viminfo.c
index 2e89fb5859..7247394773 100644
--- a/src/viminfo.c
+++ b/src/viminfo.c
@@ -385,23 +385,22 @@ removable(char_u *name)
size_t n;
name = home_replace_save(NULL, name);
- if (name != NULL)
+ if (name == NULL)
+ return FALSE;
+ for (p = p_viminfo; *p; )
{
- for (p = p_viminfo; *p; )
+ copy_option_part(&p, part, 51, ", ");
+ if (part[0] == 'r')
{
- copy_option_part(&p, part, 51, ", ");
- if (part[0] == 'r')
+ n = STRLEN(part + 1);
+ if (MB_STRNICMP(part + 1, name, n) == 0)
{
- n = STRLEN(part + 1);
- if (MB_STRNICMP(part + 1, name, n) == 0)
- {
- retval = TRUE;
- break;
- }
+ retval = TRUE;
+ break;
}
}
- vim_free(name);
}
+ vim_free(name);
return retval;
}
@@ -534,49 +533,51 @@ read_viminfo_history(vir_T *virp, int writing)
{
int type;
long_u len;
- char_u *val;
+ char_u *val = NULL;
char_u *p;
type = hist_char2type(virp->vir_line[0]);
- if (viminfo_hisidx[type] < viminfo_hislen[type])
- {
- val = viminfo_readstring(virp, 1, TRUE);
- if (val != NULL && *val != NUL)
- {
- int sep = (*val == ' ' ? NUL : *val);
+ if (viminfo_hisidx[type] >= viminfo_hislen[type])
+ goto done;
- if (!in_history(type, val + (type == HIST_SEARCH),
- viminfo_add_at_front, sep, writing))
- {
- // Need to re-allocate to append the separator byte.
- len = STRLEN(val);
- p = alloc(len + 2);
- if (p != NULL)
- {
- if (type == HIST_SEARCH)
- {
- // Search entry: Move the separator from the first
- // column to after the NUL.
- mch_memmove(p, val + 1, (size_t)len);
- p[len] = sep;
- }
- else
- {
- // Not a search entry: No separator in the viminfo
- // file, add a NUL separator.
- mch_memmove(p, val, (size_t)len + 1);
- p[len + 1] = NUL;
- }
- viminfo_history[type][viminfo_hisidx[type]].hisstr = p;
- viminfo_history[type][viminfo_hisidx[type]].time_set = 0;
- viminfo_history[type][viminfo_hisidx[type]].viminfo = TRUE;
- viminfo_history[type][viminfo_hisidx[type]].hisnum = 0;
- viminfo_hisidx[type]++;
- }
- }
- }
- vim_free(val);
+ val = viminfo_readstring(virp, 1, TRUE);
+ if (val == NULL || *val == NUL)
+ goto done;
+
+ int sep = (*val == ' ' ? NUL : *val);
+
+ if (in_history(type, val + (type == HIST_SEARCH), viminfo_add_at_front,
+ sep, writing))
+ goto done;
+
+ // Need to re-allocate to append the separator byte.
+ len = STRLEN(val);
+ p = alloc(len + 2);
+ if (p == NULL)
+ goto done;
+
+ if (type == HIST_SEARCH)
+ {
+ // Search entry: Move the separator from the first
+ // column to after the NUL.
+ mch_memmove(p, val + 1, (size_t)len);
+ p[len] = sep;
+ }
+ else
+ {
+ // Not a search entry: No separator in the viminfo
+ // file, add a NUL separator.
+ mch_memmove(p, val, (size_t)len + 1);
+ p[len + 1] = NUL;
}
+ viminfo_history[type][viminfo_hisidx[type]].hisstr = p;
+ viminfo_history[type][viminfo_hisidx[type]].time_set = 0;
+ viminfo_history[type][viminfo_hisidx[type]].viminfo = TRUE;
+ viminfo_history[type][viminfo_hisidx[type]].hisnum = 0;
+ viminfo_hisidx[type]++;
+
+done:
+ vim_free(val);
return viminfo_readline(virp);
}
@@ -607,54 +608,55 @@ handle_viminfo_history(
type = vp[0].bv_nr;
if (type >= HIST_COUNT)
return;
- if (viminfo_hisidx[type] < viminfo_hislen[type])
+
+ if (viminfo_hisidx[type] >= viminfo_hislen[type])
+ return;
+
+ val = vp[3].bv_string;
+ if (val == NULL || *val == NUL)
+ return;
+
+ int sep = type == HIST_SEARCH && vp[2].bv_type == BVAL_NR
+ ? vp[2].bv_nr : NUL;
+ int idx;
+ int overwrite = FALSE;
+
+ if (in_history(type, val, viminfo_add_at_front, sep, writing))
+ return;
+
+ // If lines were written by an older Vim we need to avoid
+ // getting duplicates. See if the entry already exists.
+ for (idx = 0; idx < viminfo_hisidx[type]; ++idx)
{
- val = vp[3].bv_string;
- if (val != NULL && *val != NUL)
+ p = viminfo_history[type][idx].hisstr;
+ if (STRCMP(val, p) == 0
+ && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1]))
{
- int sep = type == HIST_SEARCH && vp[2].bv_type == BVAL_NR
- ? vp[2].bv_nr : NUL;
- int idx;
- int overwrite = FALSE;
-
- if (!in_history(type, val, viminfo_add_at_front, sep, writing))
- {
- // If lines were written by an older Vim we need to avoid
- // getting duplicates. See if the entry already exists.
- for (idx = 0; idx < viminfo_hisidx[type]; ++idx)
- {
- p = viminfo_history[type][idx].hisstr;
- if (STRCMP(val, p) == 0
- && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1]))
- {
- overwrite = TRUE;
- break;
- }
- }
+ overwrite = TRUE;
+ break;
+ }
+ }
- if (!overwrite)
- {
- // Need to re-allocate to append the separator byte.
- len = vp[3].bv_len;
- p = alloc(len + 2);
- }
- else
- len = 0; // for picky compilers
- if (p != NULL)
- {
- viminfo_history[type][idx].time_set = vp[1].bv_nr;
- if (!overwrite)
- {
- mch_memmove(p, val, (size_t)len + 1);
- // Put the separator after the NUL.
- p[len + 1] = sep;
- viminfo_history[type][idx].hisstr = p;
- viminfo_history[type][idx].hisnum = 0;
- viminfo_history[type][idx].viminfo = TRUE;
- viminfo_hisidx[type]++;
- }
- }
- }
+ if (!overwrite)
+ {
+ // Need to re-allocate to append the separator byte.
+ len = vp[3].bv_len;
+ p = alloc(len + 2);
+ }
+ else
+ len = 0; // for picky compilers
+ if (p != NULL)
+ {
+ viminfo_history[type][idx].time_set = vp[1].bv_nr;
+ if (!overwrite)
+ {
+ mch_memmove(p, val, (size_t)len + 1);
+ // Put the separator after the NUL.
+ p[len + 1] = sep;
+ viminfo_history[type][idx].hisstr = p;
+ viminfo_history[type][idx].hisnum = 0;
+ viminfo_history[type][idx].viminfo = TRUE;
+ viminfo_hisidx[type]++;
}
}
}
@@ -943,19 +945,19 @@ write_viminfo_barlines(vir_T *virp, FILE *fp_out)
int seen_useful = FALSE;
char *line;
- if (gap->ga_len > 0)
- {
- fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out);
+ if (gap->ga_len <= 0)
+ return;
+
+ fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out);
- // Skip over continuation lines until seeing a useful line.
- for (i = 0; i < gap->ga_len; ++i)