0
0
mirror of https://github.com/vim/vim.git synced 2025-08-26 20:03:41 -04:00

patch 9.0.1246: code is indented more than necessary

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes #11887)
This commit is contained in:
Yegappan Lakshmanan 2023-01-26 12:00:00 +00:00 committed by Bram Moolenaar
parent 032713f829
commit 142ed77898
13 changed files with 510 additions and 515 deletions

View File

@ -83,20 +83,20 @@ ui_inchar_undo(char_u *s, int len)
if (ta_str != NULL) if (ta_str != NULL)
newlen += ta_len - ta_off; newlen += ta_len - ta_off;
new = alloc(newlen); 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);
mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off)); vim_free(ta_str);
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;
} }
else
mch_memmove(new, s, (size_t)len);
ta_str = new;
ta_len = newlen;
ta_off = 0;
} }
#endif #endif
@ -815,25 +815,25 @@ set_input_buf(char_u *p, int overwrite)
{ {
garray_T *gap = (garray_T *)p; 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;
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);
} }
vim_free(gap); 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);
} }
vim_free(gap);
} }
/* /*

View File

@ -1164,21 +1164,21 @@ read_string_decrypt(bufinfo_T *bi, int len)
{ {
char_u *ptr = alloc(len + 1); 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;
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);
#endif
} }
// 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);
#endif
return ptr; return ptr;
} }
@ -3510,12 +3510,12 @@ u_saveline(linenr_T lnum)
void void
u_clearline(void) u_clearline(void)
{ {
if (curbuf->b_u_line_ptr.ul_line != NULL) 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; VIM_CLEAR(curbuf->b_u_line_ptr.ul_line);
curbuf->b_u_line_lnum = 0; 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 void
f_undotree(typval_T *argvars UNUSED, typval_T *rettv) f_undotree(typval_T *argvars UNUSED, typval_T *rettv)
{ {
if (rettv_dict_alloc(rettv) == OK) if (rettv_dict_alloc(rettv) == FAIL)
return;
dict_T *dict = rettv->vval.v_dict;
list_T *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)
{ {
dict_T *dict = rettv->vval.v_dict; u_eval_tree(curbuf->b_u_oldhead, list);
list_T *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);
}
} }
} }

View File

@ -205,18 +205,18 @@ batfile_thisversion(char *path)
int found = FALSE; int found = FALSE;
fd = fopen(path, "r"); 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; return found;
} }
@ -261,12 +261,12 @@ remove_if_exists(char *path, char *filename)
sprintf(buf, "%s\\%s", path, filename); sprintf(buf, "%s\\%s", path, filename);
fd = fopen(buf, "r"); fd = fopen(buf, "r");
if (fd != NULL) if (fd == NULL)
{ return;
fclose(fd);
printf("removing %s\n", buf); fclose(fd);
remove(buf); printf("removing %s\n", buf);
} remove(buf);
} }
static void static void
@ -287,21 +287,21 @@ remove_start_menu(void)
int i; int i;
struct stat st; 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) printf("removing %s\n", path);
remove_if_exists(path, targets[i].lnkname); rmdir(path);
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);
}
} }
} }

View File

@ -770,25 +770,25 @@ is_function_cmd(char_u **cmd)
static void static void
function_using_block_scopes(ufunc_T *fp, cstack_T *cstack) function_using_block_scopes(ufunc_T *fp, cstack_T *cstack)
{ {
if (cstack != NULL && cstack->cs_idx >= 0) if (cstack == NULL || cstack->cs_idx < 0)
return;
int count = cstack->cs_idx + 1;
int i;
fp->uf_block_ids = ALLOC_MULT(int, count);
if (fp->uf_block_ids != NULL)
{ {
int count = cstack->cs_idx + 1; mch_memmove(fp->uf_block_ids, cstack->cs_block_id,
int i; sizeof(int) * count);
fp->uf_block_depth = count;
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;
} }
// 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; return FALSE;
hi = hash_find(&func_hashtab, UF2HIKEY(fp)); 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 fp->uf_flags |= FC_DEAD;
// function, so we can find the index when defining the function again. return FALSE;
// 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;
} }
return FALSE; hash_remove(&func_hashtab, hi, "remove function");
fp->uf_flags |= FC_DELETED;
return TRUE;
} }
static void static void

View File

@ -57,26 +57,26 @@ char *longVersion = NULL;
void void
init_longVersion(void) init_longVersion(void)
{ {
if (longVersion == NULL) if (longVersion != NULL)
{ return;
#ifdef BUILD_DATE
char *date_time = BUILD_DATE;
#else
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);
longVersion = alloc(len); #ifdef BUILD_DATE
if (longVersion == NULL) char *date_time = BUILD_DATE;
longVersion = VIM_VERSION_LONG; #else
else char *date_time = __DATE__ " " __TIME__;
vim_snprintf(longVersion, len, msg, #endif
VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, 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);
} }
# endif # endif
#else #else
@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1246,
/**/ /**/
1245, 1245,
/**/ /**/

View File

@ -3939,18 +3939,18 @@ delete_def_function_contents(dfunc_T *dfunc, int mark_deleted)
void void
unlink_def_function(ufunc_T *ufunc) unlink_def_function(ufunc_T *ufunc)
{ {
if (ufunc->uf_dfunc_idx > 0) if (ufunc->uf_dfunc_idx <= 0)
{ return;
dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
+ ufunc->uf_dfunc_idx;
if (--dfunc->df_refcount <= 0) dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
delete_def_function_contents(dfunc, TRUE); + ufunc->uf_dfunc_idx;
ufunc->uf_def_status = UF_NOT_COMPILED;
ufunc->uf_dfunc_idx = 0; if (--dfunc->df_refcount <= 0)
if (dfunc->df_ufunc == ufunc) delete_def_function_contents(dfunc, TRUE);
dfunc->df_ufunc = NULL; 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 void
link_def_function(ufunc_T *ufunc) link_def_function(ufunc_T *ufunc)
{ {
if (ufunc->uf_dfunc_idx > 0) if (ufunc->uf_dfunc_idx <= 0)
{ return;
dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
+ ufunc->uf_dfunc_idx;
++dfunc->df_refcount; dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
} + ufunc->uf_dfunc_idx;
++dfunc->df_refcount;
} }
#if defined(EXITFREE) || defined(PROTO) #if defined(EXITFREE) || defined(PROTO)

View File

@ -279,14 +279,14 @@ exe_newdict(int count, ectx_T *ectx)
void void
update_has_breakpoint(ufunc_T *ufunc) update_has_breakpoint(ufunc_T *ufunc)
{ {
if (ufunc->uf_debug_tick != debug_tick) if (ufunc->uf_debug_tick == debug_tick)
{ return;
linenr_T breakpoint;
ufunc->uf_debug_tick = debug_tick; linenr_T breakpoint;
breakpoint = dbg_find_breakpoint(FALSE, ufunc->uf_name, 0);
ufunc->uf_has_breakpoint = breakpoint > 0; 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; static garray_T dict_stack = GA_EMPTY;
@ -383,29 +383,29 @@ get_pt_outer(partial_T *pt)
static int static int
check_ufunc_arg_types(ufunc_T *ufunc, int argcount, int off, ectx_T *ectx) 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 // assume a v:none argument, using the default value, is always OK
// types are correct. if (argv[i].v_type == VAR_SPECIAL
for (int i = 0; i < argcount; ++i) && argv[i].vval.v_number == VVAL_NONE)
{ continue;
type_T *type = NULL;
// assume a v:none argument, using the default value, is always OK if (i < ufunc->uf_args.ga_len && ufunc->uf_arg_types != NULL)
if (argv[i].v_type == VAR_SPECIAL type = ufunc->uf_arg_types[i];
&& argv[i].vval.v_number == VVAL_NONE) else if (ufunc->uf_va_type != NULL)
continue; type = ufunc->uf_va_type->tt_member;
if (type != NULL && check_typval_arg_type(type,
if (i < ufunc->uf_args.ga_len && ufunc->uf_arg_types != NULL) &argv[i], NULL, i + 1) == FAIL)
type = ufunc->uf_arg_types[i]; return FAIL;
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; return OK;
} }
@ -1527,21 +1527,22 @@ store_var(char_u *name, typval_T *tv)
static int static int
do_2string(typval_T *tv, int is_2string_any, int tolerant) do_2string(typval_T *tv, int is_2string_any, int tolerant)
{ {
if (tv->v_type != VAR_STRING) if (tv->v_type == VAR_STRING)
return OK;
char_u *str;
if (is_2string_any)
{ {
char_u *str; switch (tv->v_type)
if (is_2string_any)
{ {
switch (tv->v_type) case VAR_SPECIAL:
{ case VAR_BOOL:
case VAR_SPECIAL: case VAR_NUMBER:
case VAR_BOOL: case VAR_FLOAT:
case VAR_NUMBER: case VAR_BLOB: break;
case VAR_FLOAT:
case VAR_BLOB: break;
case VAR_LIST: case VAR_LIST:
if (tolerant) if (tolerant)
{ {
char_u *s, *e, *p; char_u *s, *e, *p;
@ -1560,7 +1561,7 @@ do_2string(typval_T *tv, int is_2string_any, int tolerant)
{ {
*e = NUL; *e = NUL;
p = vim_strsave_fnameescape(s, p = vim_strsave_fnameescape(s,
VSE_NONE); VSE_NONE);
if (p != NULL) if (p != NULL)
{ {
ga_concat(&ga, p); ga_concat(&ga, p);
@ -1576,15 +1577,14 @@ do_2string(typval_T *tv, int is_2string_any, int tolerant)
return OK; return OK;
} }
// FALLTHROUGH // FALLTHROUGH
default: to_string_error(tv->v_type); default: to_string_error(tv->v_type);
return FAIL; 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; return OK;
} }

View File

@ -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_opt_flags, lhs->lhs_vimvaridx,
lhs->lhs_type, lhs->lhs_name, lhs); 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; varnumber_T val = isn->isn_arg.number;
isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; garray_T *stack = &cctx->ctx_type_stack;
// Optimization: turn "var = 123" from ISN_PUSHNR + ISN_STORE into if (val == 0 && is_decl && !inside_loop_scope(cctx))
// 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; // zero is the default value, no need to do anything
garray_T *stack = &cctx->ctx_type_stack; --instr->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
{
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 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; return OK;
} }

View File

@ -1007,42 +1007,43 @@ hide_script_var(scriptitem_T *si, int idx, int func_defined)
// The typval is moved into the sallvar_T. // The typval is moved into the sallvar_T.
script_hi = hash_find(script_ht, sv->sv_name); script_hi = hash_find(script_ht, sv->sv_name);
all_hi = hash_find(all_ht, sv->sv_name); all_hi = hash_find(all_ht, sv->sv_name);
if (!HASHITEM_EMPTY(script_hi) && !HASHITEM_EMPTY(all_hi))
{
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 if (HASHITEM_EMPTY(script_hi) || HASHITEM_EMPTY(all_hi))
// blocks, find the right one. return;
while (sav != NULL && sav->sav_var_vals_idx != idx)
{ dictitem_T *di = HI2DI(script_hi);
sav_prev = sav; sallvar_T *sav = HI2SAV(all_hi);
sav = sav->sav_next; sallvar_T *sav_prev = NULL;
}
if (sav != NULL) // There can be multiple entries with the same name in different
{ // blocks, find the right one.
if (func_defined) while (sav != NULL && sav->sav_var_vals_idx != idx)
{ {
// move the typval from the dictitem to the sallvar sav_prev = sav;
sav->sav_tv = di->di_tv; sav = sav->sav_next;
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 (sav == NULL)
return;
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);
} }
/* /*

View File

@ -37,11 +37,11 @@ get_type_ptr(garray_T *type_gap)
if (ga_grow(type_gap, 1) == FAIL) if (ga_grow(type_gap, 1) == FAIL)
return NULL; return NULL;
type = ALLOC_CLEAR_ONE(type_T); type = ALLOC_CLEAR_ONE(type_T);
if (type != NULL) if (type == NULL)
{ return NULL;
((type_T **)type_gap->ga_data)[type_gap->ga_len] = type;
++type_gap->ga_len; ((type_T **)type_gap->ga_data)[type_gap->ga_len] = type;
} ++type_gap->ga_len;
return type; 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); type_T *type = typval2type_int(tv, copyID, type_gap, flags);
if (type != NULL) if (type == NULL)
{ return NULL;
if (type != &t_bool && (tv->v_type == VAR_NUMBER
&& (tv->vval.v_number == 0 || tv->vval.v_number == 1))) if (type != &t_bool && (tv->v_type == VAR_NUMBER
// Number 0 and 1 and expression with "&&" or "||" can also be used && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
// for bool. // Number 0 and 1 and expression with "&&" or "||" can also be used
type = &t_number_bool; // for bool.
else if (type != &t_float && tv->v_type == VAR_NUMBER) type = &t_number_bool;
// A number can also be used for float. else if (type != &t_float && tv->v_type == VAR_NUMBER)
type = &t_number_float; // A number can also be used for float.
} type = &t_number_float;
return type; return type;
} }

View File

@ -385,23 +385,22 @@ removable(char_u *name)
size_t n; size_t n;
name = home_replace_save(NULL, name); 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, ", "); n = STRLEN(part + 1);
if (part[0] == 'r') if (MB_STRNICMP(part + 1, name, n) == 0)
{ {
n = STRLEN(part + 1); retval = TRUE;
if (MB_STRNICMP(part + 1, name, n) == 0) break;
{
retval = TRUE;
break;
}
} }
} }
vim_free(name);
} }
vim_free(name);
return retval; return retval;
} }
@ -534,49 +533,51 @@ read_viminfo_history(vir_T *virp, int writing)
{ {
int type; int type;
long_u len; long_u len;
char_u *val; char_u *val = NULL;
char_u *p; char_u *p;
type = hist_char2type(virp->vir_line[0]); type = hist_char2type(virp->vir_line[0]);
if (viminfo_hisidx[type] < viminfo_hislen[type]) if (viminfo_hisidx[type] >= viminfo_hislen[type])
{ goto done;
val = viminfo_readstring(virp, 1, TRUE);
if (val != NULL && *val != NUL)
{
int sep = (*val == ' ' ? NUL : *val);
if (!in_history(type, val + (type == HIST_SEARCH), val = viminfo_readstring(virp, 1, TRUE);
viminfo_add_at_front, sep, writing)) if (val == NULL || *val == NUL)
{ goto done;
// Need to re-allocate to append the separator byte.
len = STRLEN(val); int sep = (*val == ' ' ? NUL : *val);
p = alloc(len + 2);
if (p != NULL) if (in_history(type, val + (type == HIST_SEARCH), viminfo_add_at_front,
{ sep, writing))
if (type == HIST_SEARCH) goto done;
{
// Search entry: Move the separator from the first // Need to re-allocate to append the separator byte.
// column to after the NUL. len = STRLEN(val);
mch_memmove(p, val + 1, (size_t)len); p = alloc(len + 2);
p[len] = sep; if (p == NULL)
} goto done;
else
{ if (type == HIST_SEARCH)
// Not a search entry: No separator in the viminfo {
// file, add a NUL separator. // Search entry: Move the separator from the first
mch_memmove(p, val, (size_t)len + 1); // column to after the NUL.
p[len + 1] = NUL; mch_memmove(p, val + 1, (size_t)len);
} p[len] = sep;
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);
} }
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); return viminfo_readline(virp);
} }
@ -607,54 +608,55 @@ handle_viminfo_history(
type = vp[0].bv_nr; type = vp[0].bv_nr;
if (type >= HIST_COUNT) if (type >= HIST_COUNT)
return; 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; p = viminfo_history[type][idx].hisstr;
if (val != NULL && *val != NUL) if (STRCMP(val, p) == 0
&& (type != HIST_SEARCH || sep == p[STRLEN(p) + 1]))
{ {
int sep = type == HIST_SEARCH && vp[2].bv_type == BVAL_NR overwrite = TRUE;
? vp[2].bv_nr : NUL; break;
int idx; }
int overwrite = FALSE; }
if (!in_history(type, val, viminfo_add_at_front, sep, writing)) if (!overwrite)
{ {
// If lines were written by an older Vim we need to avoid // Need to re-allocate to append the separator byte.
// getting duplicates. See if the entry already exists. len = vp[3].bv_len;
for (idx = 0; idx < viminfo_hisidx[type]; ++idx) p = alloc(len + 2);
{ }
p = viminfo_history[type][idx].hisstr; else
if (STRCMP(val, p) == 0 len = 0; // for picky compilers
&& (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) if (p != NULL)
{ {
overwrite = TRUE; viminfo_history[type][idx].time_set = vp[1].bv_nr;
break; if (!overwrite)
} {
} mch_memmove(p, val, (size_t)len + 1);
// Put the separator after the NUL.
if (!overwrite) p[len + 1] = sep;
{ viminfo_history[type][idx].hisstr = p;
// Need to re-allocate to append the separator byte. viminfo_history[type][idx].hisnum = 0;
len = vp[3].bv_len; viminfo_history[type][idx].viminfo = TRUE;
p = alloc(len + 2); viminfo_hisidx[type]++;
}
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; int seen_useful = FALSE;
char *line; char *line;
if (gap->ga_len > 0) if (gap->ga_len <= 0)
{ return;
fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out);
// Skip over continuation lines until seeing a useful line. fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out);
for (i = 0; i < gap->ga_len; ++i)
// Skip over continuation lines until seeing a useful line.
for (i = 0; i < gap->ga_len; ++i)
{
line = ((char **)(gap->ga_data))[i];
if (seen_useful || line[1] != '<')
{ {
line = ((char **)(gap->ga_data))[i]; fputs(line, fp_out);
if (seen_useful || line[1] != '<') seen_useful = TRUE;
{
fputs(line, fp_out);
seen_useful = TRUE;
}
} }
} }
} }
@ -1408,11 +1410,11 @@ write_viminfo_sub_string(FILE *fp)
{ {
char_u *old_sub = get_old_sub(); char_u *old_sub = get_old_sub();
if (get_viminfo_parameter('/') != 0 && old_sub != NULL) if (get_viminfo_parameter('/') == 0 || old_sub == NULL)
{ return;
fputs(_("\n# Last Substitute String:\n$"), fp);
viminfo_writestring(fp, old_sub); fputs(_("\n# Last Substitute String:\n$"), fp);
} viminfo_writestring(fp, old_sub);
} }
/* /*
@ -1511,34 +1513,34 @@ wvsp_one(
int sc) // dir char int sc) // dir char
{ {
spat_T *spat = get_spat(idx); spat_T *spat = get_spat(idx);
if (spat->pat != NULL) if (spat->pat == NULL)
{ return;
fprintf(fp, _("\n# Last %sSearch Pattern:\n~"), s);
// off.dir is not stored, it's reset to forward fprintf(fp, _("\n# Last %sSearch Pattern:\n~"), s);
fprintf(fp, "%c%c%c%c%ld%s%c", // off.dir is not stored, it's reset to forward
spat->magic ? 'M' : 'm', // magic fprintf(fp, "%c%c%c%c%ld%s%c",
spat->no_scs ? 's' : 'S', // smartcase spat->magic ? 'M' : 'm', // magic
spat->off.line ? 'L' : 'l', // line offset spat->no_scs ? 's' : 'S', // smartcase
spat->off.end ? 'E' : 'e', // offset from end spat->off.line ? 'L' : 'l', // line offset
spat->off.off, // offset spat->off.end ? 'E' : 'e', // offset from end
get_spat_last_idx() == idx ? "~" : "", // last used pat spat->off.off, // offset
sc); get_spat_last_idx() == idx ? "~" : "", // last used pat
viminfo_writestring(fp, spat->pat); sc);
} viminfo_writestring(fp, spat->pat);
} }
static void static void
write_viminfo_search_pattern(FILE *fp) write_viminfo_search_pattern(FILE *fp)
{ {
if (get_viminfo_parameter('/') != 0) if (get_viminfo_parameter('/') == 0)
{ return;
#ifdef FEAT_SEARCH_EXTRA #ifdef FEAT_SEARCH_EXTRA
fprintf(fp, "\n# hlsearch on (H) or off (h):\n~%c", fprintf(fp, "\n# hlsearch on (H) or off (h):\n~%c",
(no_hlsearch || find_viminfo_parameter('h') != NULL) ? 'h' : 'H'); (no_hlsearch || find_viminfo_parameter('h') != NULL) ? 'h' : 'H');
#endif #endif
wvsp_one(fp, RE_SEARCH, "", '/'); wvsp_one(fp, RE_SEARCH, "", '/');
wvsp_one(fp, RE_SUBST, _("Substitute "), '&'); wvsp_one(fp, RE_SUBST, _("Substitute "), '&');
}
} }
/* /*
@ -1565,17 +1567,17 @@ finish_viminfo_registers(void)
int i; int i;
int j; int j;
if (y_read_regs != NULL) if (y_read_regs == NULL)
{ return;
for (i = 0; i < NUM_REGISTERS; ++i)
if (y_read_regs[i].y_array != NULL) for (i = 0; i < NUM_REGISTERS; ++i)
{ if (y_read_regs[i].y_array != NULL)
for (j = 0; j < y_read_regs[i].y_size; j++) {
vim_free(y_read_regs[i].y_array[j]); for (j = 0; j < y_read_regs[i].y_size; j++)
vim_free(y_read_regs[i].y_array); vim_free(y_read_regs[i].y_array[j]);
} vim_free(y_read_regs[i].y_array);
VIM_CLEAR(y_read_regs); }
} VIM_CLEAR(y_read_regs);
} }
static int static int

View File

@ -149,11 +149,11 @@ MultiByteToWideChar_alloc(UINT cp, DWORD flags,
*outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0);
// Add one word to avoid a zero-length alloc(). // Add one word to avoid a zero-length alloc().
*out = ALLOC_MULT(WCHAR, *outlen + 1); *out = ALLOC_MULT(WCHAR, *outlen + 1);
if (*out != NULL) if (*out == NULL)
{ return;
MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen);
(*out)[*outlen] = 0; MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen);
} (*out)[*outlen] = 0;
} }
/* /*
@ -169,11 +169,10 @@ WideCharToMultiByte_alloc(UINT cp, DWORD flags,
*outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef);
// Add one byte to avoid a zero-length alloc(). // Add one byte to avoid a zero-length alloc().
*out = alloc(*outlen + 1); *out = alloc(*outlen + 1);
if (*out != NULL) if (*out == NULL)
{ return;
WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef); WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef);
(*out)[*outlen] = 0; (*out)[*outlen] = 0;
}
} }
@ -743,12 +742,11 @@ acp_to_enc(
MultiByteToWideChar_alloc(GetACP(), 0, (LPCSTR)str, str_size, MultiByteToWideChar_alloc(GetACP(), 0, (LPCSTR)str, str_size,
&widestr, outlen); &widestr, outlen);
if (widestr != NULL) if (widestr == NULL)
{ return;
++*outlen; // Include the 0 after the string ++*outlen; // Include the 0 after the string
*out = utf16_to_enc((short_u *)widestr, outlen); *out = utf16_to_enc((short_u *)widestr, outlen);
vim_free(widestr); vim_free(widestr);
}
} }
/* /*
@ -768,10 +766,9 @@ enc_to_acp(
int len = str_size; int len = str_size;
widestr = (WCHAR *)enc_to_utf16(str, &len); widestr = (WCHAR *)enc_to_utf16(str, &len);
if (widestr != NULL) if (widestr == NULL)
{ return;
WideCharToMultiByte_alloc(GetACP(), 0, widestr, len, WideCharToMultiByte_alloc(GetACP(), 0, widestr, len,
(LPSTR *)out, outlen, 0, 0); (LPSTR *)out, outlen, 0, 0);
vim_free(widestr); vim_free(widestr);
}
} }

View File

@ -2469,37 +2469,36 @@ close_last_window_tabpage(
int free_buf, int free_buf,
tabpage_T *prev_curtab) tabpage_T *prev_curtab)
{ {
if (ONE_WINDOW) if (!ONE_WINDOW)
{ return FALSE;
buf_T *old_curbuf = curbuf;
/* buf_T *old_curbuf = curbuf;
* Closing the last window in a tab page. First go to another tab
* page and then close the window and the tab page. This avoids that
* curwin and curtab are invalid while we are freeing memory, they may
* be used in GUI events.
* Don't trigger autocommands yet, they may use wrong values, so do
* that below.
*/
goto_tabpage_tp(alt_tabpage(), FALSE, TRUE);
// Safety check: Autocommands may have closed the window when jumping /*
// to the other tab page. * Closing the last window in a tab page. First go to another tab
if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win) * page and then close the window and the tab page. This avoids that
win_close_othertab(win, free_buf, prev_curtab); * curwin and curtab are invalid while we are freeing memory, they may
* be used in GUI events.
* Don't trigger autocommands yet, they may use wrong values, so do
* that below.
*/
goto_tabpage_tp(alt_tabpage(), FALSE, TRUE);
// Safety check: Autocommands may have closed the window when jumping
// to the other tab page.
if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win)
win_close_othertab(win, free_buf, prev_curtab);
#ifdef FEAT_JOB_CHANNEL #ifdef FEAT_JOB_CHANNEL
entering_window(curwin); entering_window(curwin);
#endif #endif
// Since goto_tabpage_tp above did not trigger *Enter autocommands, do // Since goto_tabpage_tp above did not trigger *Enter autocommands, do
// that now. // that now.
apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf);
if (old_curbuf != curbuf) if (old_curbuf != curbuf)
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
return TRUE; return TRUE;
}
return FALSE;
} }
/* /*
@ -4205,15 +4204,14 @@ win_alloc_popup_win(void)
win_T *wp; win_T *wp;
wp = win_alloc(NULL, TRUE); wp = win_alloc(NULL, TRUE);
if (wp != NULL) if (wp == NULL)
{ return NULL;
// We need to initialize options with something, using the current // We need to initialize options with something, using the current
// window makes most sense. // window makes most sense.
win_init_some(wp, curwin); win_init_some(wp, curwin);
RESET_BINDING(wp); RESET_BINDING(wp);
new_frame(wp); new_frame(wp);
}
return wp; return wp;
} }
@ -4287,11 +4285,10 @@ new_frame(win_T *wp)
frame_T *frp = ALLOC_CLEAR_ONE(frame_T); frame_T *frp = ALLOC_CLEAR_ONE(frame_T);
wp->w_frame = frp; wp->w_frame = frp;
if (frp != NULL) if (frp == NULL)
{ return;
frp->fr_layout = FR_LEAF; frp->fr_layout = FR_LEAF;
frp->fr_win = wp; frp->fr_win = wp;
}
} }
/* /*
@ -4489,13 +4486,12 @@ may_open_tabpage(void)
int n = (cmdmod.cmod_tab == 0) int n = (cmdmod.cmod_tab == 0)
? postponed_split_tab : cmdmod.cmod_tab; ? postponed_split_tab : cmdmod.cmod_tab;
if (n != 0) if (n == 0)
{ return FAIL;
cmdmod.cmod_tab = 0; // reset it to avoid doing it twice
postponed_split_tab = 0; cmdmod.cmod_tab = 0; // reset it to avoid doing it twice
return win_new_tabpage(n); postponed_split_tab = 0;
} return win_new_tabpage(n);
return FAIL;
} }
/* /*
@ -4880,12 +4876,11 @@ goto_tabpage_tp(
int int
goto_tabpage_lastused(void) goto_tabpage_lastused(void)
{ {
if (valid_tabpage(lastused_tabpage)) if (!valid_tabpage(lastused_tabpage))
{ return FAIL;
goto_tabpage_tp(lastused_tabpage, TRUE, TRUE);
return OK; goto_tabpage_tp(lastused_tabpage, TRUE, TRUE);
} return OK;
return FAIL;
} }
/* /*
@ -5907,17 +5902,17 @@ win_size_save(garray_T *gap)
win_T *wp; win_T *wp;
ga_init2(gap, sizeof(int), 1); ga_init2(gap, sizeof(int), 1);
if (ga_grow(gap, win_count() * 2 + 1) == OK) if (ga_grow(gap, win_count() * 2 + 1) == FAIL)
{ return;
// first entry is value of 'lines'
((int *)gap->ga_data)[gap->ga_len++] = Rows;
FOR_ALL_WINDOWS(wp) // first entry is value of 'lines'
{ ((int *)gap->ga_data)[gap->ga_len++] = Rows;
((int *)gap->ga_data)[gap->ga_len++] =
wp->w_width + wp->w_vsep_width; FOR_ALL_WINDOWS(wp)
((int *)gap->ga_data)[gap->ga_len++] = wp->w_height; {
} ((int *)gap->ga_data)[gap->ga_len++] =
wp->w_width + wp->w_vsep_width;
((int *)gap->ga_data)[gap->ga_len++] = wp->w_height;
} }
} }
@ -7429,12 +7424,11 @@ clear_snapshot(tabpage_T *tp, int idx)
static void static void
clear_snapshot_rec(frame_T *fr) clear_snapshot_rec(frame_T *fr)
{ {
if (fr != NULL) if (fr == NULL)
{ return;
clear_snapshot_rec(fr->fr_next); clear_snapshot_rec(fr->fr_next);
clear_snapshot_rec(fr->fr_child); clear_snapshot_rec(fr->fr_child);
vim_free(fr); vim_free(fr);
}
} }
/* /*