0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.0.1208: 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 #11819)
This commit is contained in:
Yegappan Lakshmanan 2023-01-16 18:19:05 +00:00 committed by Bram Moolenaar
parent 450c7a97d1
commit a41e221935
12 changed files with 1318 additions and 1312 deletions

View File

@ -938,13 +938,13 @@ nb_partialremove(linenr_T lnum, colnr_T first, colnr_T last)
if (lastbyte >= oldlen)
lastbyte = oldlen - 1;
newtext = alloc(oldlen - (int)(lastbyte - first));
if (newtext != NULL)
{
if (newtext == NULL)
return;
mch_memmove(newtext, oldtext, first);
STRMOVE(newtext + first, oldtext + lastbyte + 1);
nbdebug((" NEW LINE %ld: %s\n", lnum, newtext));
ml_replace(lnum, newtext, FALSE);
}
}
/*
@ -960,12 +960,12 @@ nb_joinlines(linenr_T first, linenr_T other)
len_first = (int)STRLEN(ml_get(first));
len_other = (int)STRLEN(ml_get(other));
p = alloc(len_first + len_other + 1);
if (p != NULL)
{
if (p == NULL)
return;
mch_memmove(p, ml_get(first), len_first);
mch_memmove(p + len_first, ml_get(other), len_other + 1);
ml_replace(first, p, FALSE);
}
}
#define SKIP_STOP 2
@ -2247,13 +2247,14 @@ nb_do_cmd(
static void
nb_set_curbuf(buf_T *buf)
{
if (curbuf != buf) {
if (curbuf == buf)
return;
if (buf_jump_open_win(buf) != NULL)
return;
if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf) != NULL)
return;
set_curbuf(buf, DOBUF_GOTO);
}
}
/*
@ -2364,14 +2365,14 @@ nb_init_graphics(void)
{
static int did_init = FALSE;
if (!did_init)
{
if (did_init)
return;
coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
" ctermbg=LightCyan ctermfg=Black");
coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
did_init = TRUE;
}
}
/*
@ -2468,8 +2469,9 @@ netbeans_beval_cb(
if (!can_use_beval() || !NETBEANS_OPEN)
return;
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
{
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) != OK)
return;
// Send debugger request. Only when the text is of reasonable
// length.
if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
@ -2490,7 +2492,6 @@ netbeans_beval_cb(
}
}
vim_free(text);
}
}
#endif
@ -2555,12 +2556,12 @@ set_ref_in_nb_channel(int copyID)
int abort = FALSE;
typval_T tv;
if (nb_channel != NULL)
{
if (nb_channel == NULL)
return FALSE;
tv.v_type = VAR_CHANNEL;
tv.vval.v_channel = nb_channel;
abort = set_ref_in_item(&tv, copyID, NULL, NULL);
}
return abort;
}
#endif
@ -2827,8 +2828,9 @@ netbeans_button_release(int button)
bufno = nb_getbufno(curbuf);
if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
{
if (bufno < 0 || curwin == NULL || curwin->w_buffer != curbuf)
return;
int col = mouse_col - curwin->w_wincol
- ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
long off = pos2off(curbuf, &curwin->w_cursor);
@ -2842,7 +2844,6 @@ netbeans_button_release(int button)
button, (long)curwin->w_cursor.lnum, col);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_button_release");
}
}
@ -3308,8 +3309,7 @@ get_buf_size(buf_T *bufp)
if (bufp->b_ml.ml_flags & ML_EMPTY)
return 0;
else
{
if (get_fileformat(bufp) == EOL_DOS)
eol_size = 2;
else
@ -3330,7 +3330,6 @@ get_buf_size(buf_T *bufp)
// Correction for when last line doesn't have an EOL.
if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol))
char_count -= eol_size;
}
return char_count;
}
@ -3393,12 +3392,12 @@ pos2off(buf_T *buf, pos_T *pos)
{
long offset = 0;
if (!(buf->b_ml.ml_flags & ML_EMPTY))
{
if (buf->b_ml.ml_flags & ML_EMPTY)
return 0;
if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
return 0;
offset += pos->col;
}
return offset;
}

View File

@ -186,14 +186,13 @@ find_command(int cmdchar)
static int
check_text_locked(oparg_T *oap)
{
if (text_locked())
{
if (!text_locked())
return FALSE;
if (oap != NULL)
clearopbeep(oap);
text_locked_msg();
return TRUE;
}
return FALSE;
}
/*
@ -206,13 +205,13 @@ check_text_or_curbuf_locked(oparg_T *oap)
{
if (check_text_locked(oap))
return TRUE;
if (curbuf_locked())
{
if (!curbuf_locked())
return FALSE;
if (oap != NULL)
clearop(oap);
return TRUE;
}
return FALSE;
}
/*
@ -2030,8 +2029,9 @@ nv_addsub(cmdarg_T *cap)
static void
nv_page(cmdarg_T *cap)
{
if (!checkclearop(cap->oap))
{
if (checkclearop(cap->oap))
return;
if (mod_mask & MOD_MASK_CTRL)
{
// <C-PageUp>: tab page back; <C-PageDown>: tab page forward
@ -2042,7 +2042,6 @@ nv_page(cmdarg_T *cap)
}
else
(void)onepage(cap->arg, cap->count1);
}
}
/*
@ -2062,9 +2061,9 @@ nv_gd(
== FAIL)
{
clearopbeep(oap);
return;
}
else
{
#ifdef FEAT_FOLDING
if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP)
foldOpenCursor();
@ -2072,7 +2071,6 @@ nv_gd(
// clear any search statistics
if (messaging() && !msg_silent && !shortmess(SHM_SEARCHCOUNT))
clear_cmdline = TRUE;
}
}
/*
@ -3157,9 +3155,11 @@ nv_colon(cmdarg_T *cap)
int flags;
if (VIsual_active && !is_cmdkey)
nv_operator(cap);
else
{
nv_operator(cap);
return;
}
if (cap->oap->op_type != OP_NOP)
{
// Using ":" as a movement is characterwise exclusive.
@ -3210,7 +3210,6 @@ nv_colon(cmdarg_T *cap)
))
// The start of the operator has become invalid by the Ex command.
clearopbeep(cap->oap);
}
}
/*
@ -3251,8 +3250,9 @@ nv_ctrlh(cmdarg_T *cap)
static void
nv_clear(cmdarg_T *cap)
{
if (!checkclearop(cap->oap))
{
if (checkclearop(cap->oap))
return;
#ifdef FEAT_SYN_HL
// Clear all syntax states to force resyncing.
syn_stack_free_all(curwin->w_s);
@ -3272,7 +3272,6 @@ nv_clear(cmdarg_T *cap)
# endif
resize_console_buf();
#endif
}
}
/*
@ -3314,8 +3313,9 @@ nv_hat(cmdarg_T *cap)
static void
nv_Zet(cmdarg_T *cap)
{
if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
switch (cap->nchar)
{
// "ZZ": equivalent to ":x".
@ -3328,7 +3328,6 @@ nv_Zet(cmdarg_T *cap)
default: clearopbeep(cap->oap);
}
}
}
/*
@ -3982,15 +3981,14 @@ nv_up(cmdarg_T *cap)
// <S-Up> is page up
cap->arg = BACKWARD;
nv_page(cap);
return;
}
else
{
cap->oap->motion_type = MLINE;
if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL)
clearopbeep(cap->oap);
else if (cap->arg)
beginline(BL_WHITE | BL_FIX);
}
}
/*
@ -4249,9 +4247,11 @@ nv_csearch(cmdarg_T *cap)
cap->oap->motion_type = MCHAR;
if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL)
clearopbeep(cap->oap);
else
{
clearopbeep(cap->oap);
return;
}
curwin->w_set_curswant = TRUE;
// Include a Tab for "tx" and for "dfx".
if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
@ -4269,7 +4269,6 @@ nv_csearch(cmdarg_T *cap)
if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
foldOpenCursor();
#endif
}
}
/*
@ -4654,9 +4653,11 @@ nv_brace(cmdarg_T *cap)
curwin->w_set_curswant = TRUE;
if (findsent(cap->arg, cap->count1) == FAIL)
clearopbeep(cap->oap);
else
{
clearopbeep(cap->oap);
return;
}
// Don't leave the cursor on the NUL past end of line.
adjust_cursor(cap->oap);
curwin->w_cursor.coladd = 0;
@ -4664,7 +4665,6 @@ nv_brace(cmdarg_T *cap)
if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
foldOpenCursor();
#endif
}
}
/*
@ -4673,11 +4673,11 @@ nv_brace(cmdarg_T *cap)
static void
nv_mark(cmdarg_T *cap)
{
if (!checkclearop(cap->oap))
{
if (checkclearop(cap->oap))
return;
if (setmark(cap->nchar) == FAIL)
clearopbeep(cap->oap);
}
}
/*
@ -4692,15 +4692,16 @@ nv_findpar(cmdarg_T *cap)
cap->oap->use_reg_one = TRUE;
curwin->w_set_curswant = TRUE;
if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE))
clearopbeep(cap->oap);
else
{
clearopbeep(cap->oap);
return;
}
curwin->w_cursor.coladd = 0;
#ifdef FEAT_FOLDING
if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
foldOpenCursor();
#endif
}
}
/*
@ -4726,8 +4727,9 @@ nv_undo(cmdarg_T *cap)
static void
nv_kundo(cmdarg_T *cap)
{
if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
#ifdef FEAT_JOB_CHANNEL
if (bt_prompt(curbuf))
{
@ -4737,7 +4739,6 @@ nv_kundo(cmdarg_T *cap)
#endif
u_undo((int)cap->count1);
curwin->w_set_curswant = TRUE;
}
}
/*
@ -5008,9 +5009,12 @@ nv_Replace(cmdarg_T *cap)
VIsual_mode_orig = VIsual_mode; // remember original area for gv
VIsual_mode = 'V';
nv_operator(cap);
return;
}
else if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
if (!curbuf->b_p_ma)
emsg(_(e_cannot_make_changes_modifiable_is_off));
else
@ -5019,7 +5023,6 @@ nv_Replace(cmdarg_T *cap)
coladvance(getviscol());
invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE);
}
}
}
/*
@ -5033,9 +5036,12 @@ nv_vreplace(cmdarg_T *cap)
cap->cmdchar = 'r';
cap->nchar = cap->extra_char;
nv_replace(cap); // Do same as "r" in Visual mode for now
return;
}
else if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
if (!curbuf->b_p_ma)
emsg(_(e_cannot_make_changes_modifiable_is_off));
else
@ -5048,7 +5054,6 @@ nv_vreplace(cmdarg_T *cap)
coladvance(getviscol());
invoke_edit(cap, TRUE, 'v', FALSE);
}
}
}
/*
@ -5345,8 +5350,9 @@ nv_pcmark(cmdarg_T *cap)
int old_KeyTyped = KeyTyped; // getting file may reset it
#endif
if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL)
{
if (goto_tabpage_lastused() == FAIL)
@ -5382,7 +5388,6 @@ nv_pcmark(cmdarg_T *cap)
&& old_KeyTyped)
foldOpenCursor();
# endif
}
}
/*
@ -6237,8 +6242,9 @@ n_opencmd(cmdarg_T *cap)
linenr_T oldline = curwin->w_cursor.lnum;
#endif
if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
#ifdef FEAT_FOLDING
if (cap->cmdchar == 'O')
// Open above the first line of a folded sequence of lines
@ -6272,7 +6278,6 @@ n_opencmd(cmdarg_T *cap)
cap->count1 = 1;
invoke_edit(cap, FALSE, cap->cmdchar, TRUE);
}
}
}
/*
@ -6281,14 +6286,14 @@ n_opencmd(cmdarg_T *cap)
static void
nv_dot(cmdarg_T *cap)
{
if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
// If "restart_edit" is TRUE, the last but one command is repeated
// instead of the last command (inserting text). This is used for
// CTRL-O <.> in insert mode.
if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL)
clearopbeep(cap->oap);
}
}
/*
@ -6316,11 +6321,11 @@ nv_redo_or_register(cmdarg_T *cap)
return;
}
if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
u_redo((int)cap->count1);
curwin->w_set_curswant = TRUE;
}
}
/*
@ -6336,12 +6341,14 @@ nv_Undo(cmdarg_T *cap)
cap->cmdchar = 'g';
cap->nchar = 'U';
nv_operator(cap);
return;
}
else if (!checkclearopq(cap->oap))
{
if (checkclearopq(cap->oap))
return;
u_undoline();
curwin->w_set_curswant = TRUE;
}
}
/*
@ -7146,9 +7153,12 @@ nv_record(cmdarg_T *cap)
cap->cmdchar = 'g';
cap->nchar = 'q';
nv_operator(cap);
return;
}
else if (!checkclearop(cap->oap))
{
if (checkclearop(cap->oap))
return;
if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?')
{
if (cmdwin_type != 0)
@ -7164,7 +7174,6 @@ nv_record(cmdarg_T *cap)
// register
if (reg_executing == 0 && do_record(cap->nchar) == FAIL)
clearopbeep(cap->oap);
}
}
/*
@ -7214,9 +7223,14 @@ nv_halfpage(cmdarg_T *cap)
nv_join(cmdarg_T *cap)
{
if (VIsual_active) // join the visual lines
nv_operator(cap);
else if (!checkclearop(cap->oap))
{
nv_operator(cap);
return;
}
if (checkclearop(cap->oap))
return;
if (cap->count0 <= 1)
cap->count0 = 2; // default for join is two lines!
if (curwin->w_cursor.lnum + cap->count0 - 1 >
@ -7235,7 +7249,6 @@ nv_join(cmdarg_T *cap)
prep_redo(cap->oap->regname, cap->count0,
NUL, cap->cmdchar, NUL, NUL, cap->nchar);
(void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE);
}
}
/*
@ -7274,15 +7287,17 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
else
#endif
clearopbeep(cap->oap);
return;
}
#ifdef FEAT_JOB_CHANNEL
else if (bt_prompt(curbuf) && !prompt_curpos_editable())
if (bt_prompt(curbuf) && !prompt_curpos_editable())
{
clearopbeep(cap->oap);
return;
}
#endif
else
{
if (fix_indent)
{
dir = (cap->cmdchar == ']' && cap->nchar == 'p')
@ -7398,7 +7413,6 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
}
}
auto_format(FALSE, TRUE);
}
}
/*

View File

@ -989,11 +989,11 @@ mb_adjust_opend(oparg_T *oap)
{
char_u *p;
if (oap->inclusive)
{
if (!oap->inclusive)
return;
p = ml_get(oap->end.lnum);
oap->end.col += mb_tail_off(p, p + oap->end.col);
}
}
/*
@ -1869,11 +1869,13 @@ adjust_cursor_eol(void)
{
unsigned int cur_ve_flags = get_ve_flags();
if (curwin->w_cursor.col > 0
int adj_cursor = (curwin->w_cursor.col > 0
&& gchar_cursor() == NUL
&& (cur_ve_flags & VE_ONEMORE) == 0
&& !(restart_edit || (State & MODE_INSERT)))
{
&& !(restart_edit || (State & MODE_INSERT)));
if (!adj_cursor)
return;
// Put the cursor on the last character in the line.
dec_cursor();
@ -1885,7 +1887,6 @@ adjust_cursor_eol(void)
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
curwin->w_cursor.coladd = ecol - scol + 1;
}
}
}
/*
@ -2235,12 +2236,12 @@ reset_lbr(void)
static void
restore_lbr(int lbr_saved)
{
if (!curwin->w_p_lbr && lbr_saved)
{
if (curwin->w_p_lbr || !lbr_saved)
return;
// changing 'linebreak' may require w_virtcol to be updated
curwin->w_p_lbr = TRUE;
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
}
}
#endif

View File

@ -672,17 +672,17 @@ set_string_default_esc(char *name, char_u *val, int escape)
p = vim_strsave_escaped(val, (char_u *)" ");
else
p = vim_strsave(val);
if (p != NULL) // we don't want a NULL
{
if (p == NULL) // we don't want a NULL
return;
opt_idx = findoption((char_u *)name);
if (opt_idx >= 0)
{
if (opt_idx < 0)
return;
if (options[opt_idx].flags & P_DEF_ALLOCED)
vim_free(options[opt_idx].def_val[VI_DEFAULT]);
options[opt_idx].def_val[VI_DEFAULT] = p;
options[opt_idx].flags |= P_DEF_ALLOCED;
}
}
}
void
@ -1112,8 +1112,9 @@ set_helplang_default(char_u *lang)
if (lang == NULL || STRLEN(lang) < 2) // safety check
return;
idx = findoption((char_u *)"hlg");
if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
{
if (idx < 0 || (options[idx].flags & P_WAS_SET))
return;
if (options[idx].flags & P_ALLOCED)
free_string_option(p_hlg);
p_hlg = vim_strsave(lang);
@ -1136,7 +1137,6 @@ set_helplang_default(char_u *lang)
p_hlg[2] = NUL;
}
options[idx].flags |= P_ALLOCED;
}
}
#endif
@ -1171,8 +1171,11 @@ set_title_defaults(void)
p_title = val;
}
idx1 = findoption((char_u *)"icon");
if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
if (idx1 < 0 || (options[idx1].flags & P_WAS_SET))
{
return;
}
#ifdef FEAT_GUI
if (gui.starting || gui.in_use)
val = TRUE;
@ -1181,7 +1184,6 @@ set_title_defaults(void)
val = mch_can_restore_icon();
options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
p_icon = val;
}
}
void
@ -7084,12 +7086,11 @@ reset_option_was_set(char_u *name)
{
int idx = findoption(name);
if (idx >= 0)
{
if (idx < 0)
return FAIL;
options[idx].flags &= ~P_WAS_SET;
return OK;
}
return FAIL;
}
/*

View File

@ -155,9 +155,10 @@ trigger_optionset_string(
char_u *newval)
{
// Don't do this recursively.
if (oldval != NULL && newval != NULL
&& *get_vim_var_str(VV_OPTION_TYPE) == NUL)
{
if (oldval == NULL || newval == NULL
|| *get_vim_var_str(VV_OPTION_TYPE) != NUL)
return;
char_u buf_type[7];
sprintf((char *)buf_type, "%s",
@ -190,7 +191,6 @@ trigger_optionset_string(
get_option_fullname(opt_idx), NULL, FALSE,
NULL);
reset_v_option_vars();
}
}
#endif
@ -387,8 +387,9 @@ set_string_option_direct(
return;
s = vim_strsave(val);
if (s != NULL)
{
if (s == NULL)
return;
varp = (char_u **)get_option_varp_scope(idx,
both ? OPT_LOCAL : opt_flags);
if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED))
@ -425,7 +426,6 @@ set_string_option_direct(
set_option_sctx_idx(idx, opt_flags, script_ctx);
}
# endif
}
}
/*
@ -507,8 +507,9 @@ set_string_option(
return NULL;
s = vim_strsave(value == NULL ? (char_u *)"" : value);
if (s != NULL)
{
if (s == NULL)
return NULL;
varp = (char_u **)get_option_varp_scope(opt_idx,
(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
? (is_global_local_option(opt_idx)
@ -554,7 +555,6 @@ set_string_option(
vim_free(saved_oldval_g);
vim_free(saved_newval);
#endif
}
return errmsg;
}

View File

@ -234,13 +234,13 @@ mch_delay(long msec, int flags)
void Delay(long);
#endif
if (msec > 0)
{
if (msec <= 0)
return;
if (flags & MCH_DELAY_IGNOREINPUT)
Delay(msec / 20L); // Delay works with 20 msec intervals
else
WaitForChar(raw_in, msec * 1000L);
}
}
/*
@ -577,8 +577,9 @@ fname_case(
size_t flen;
fib = get_fib(name);
if (fib != NULL)
{
if (fib == NULL)
return;
flen = STRLEN(name);
// TODO: Check if this fix applies to AmigaOS < 4 too.
#ifdef __amigaos4__
@ -588,7 +589,6 @@ fname_case(
if (flen == strlen(fib->fib_FileName)) // safety check
mch_memmove(name, fib->fib_FileName, flen);
free_fib(fib);
}
}
/*
@ -609,8 +609,9 @@ get_fib(char_u *fname)
#else
fib = ALLOC_ONE(struct FileInfoBlock);
#endif
if (fib != NULL)
{
if (fib == NULL)
return;
flock = Lock((UBYTE *)fname, (long)ACCESS_READ);
if (flock == (BPTR)NULL || !Examine(flock, fib))
{
@ -619,7 +620,6 @@ get_fib(char_u *fname)
}
if (flock)
UnLock(flock);
}
return fib;
}
@ -815,11 +815,11 @@ mch_getperm(char_u *name)
long retval = -1;
fib = get_fib(name);
if (fib != NULL)
{
if (fib == NULL)
return -1;
retval = fib->fib_Protection;
free_fib(fib);
}
return retval;
}
@ -856,15 +856,15 @@ mch_isdir(char_u *name)
int retval = FALSE;
fib = get_fib(name);
if (fib != NULL)
{
if (fib == NULL)
return FALSE;
#ifdef __amigaos4__
retval = (FIB_IS_DRAWER(fib)) ? TRUE : FALSE;
#else
retval = ((fib->fib_DirEntryType >= 0) ? TRUE : FALSE);
#endif
free_fib(fib);
}
return retval;
}
@ -877,12 +877,11 @@ mch_mkdir(char_u *name)
BPTR lock;
lock = CreateDir(name);
if (lock != NULL)
{
if (lock == NULL)
return -1;
UnLock(lock);
return 0;
}
return -1;
}
/*
@ -1173,8 +1172,9 @@ out:
void
mch_set_shellsize(void)
{
if (term_console)
{
if (!term_console)
return;
size_set = TRUE;
out_char(CSI);
out_num((long)Rows);
@ -1183,7 +1183,6 @@ mch_set_shellsize(void)
out_num((long)Columns);
out_char('u');
out_flush();
}
}
/*

View File

@ -568,8 +568,9 @@ mac_utf8_to_utf16(
void
mac_lang_init(void)
{
if (mch_getenv((char_u *)"LANG") == NULL)
{
if (mch_getenv((char_u *)"LANG") != NULL)
return;
char buf[50];
// $LANG is not set, either because it was unset or Vim was started
@ -590,6 +591,5 @@ mac_lang_init(void)
setlocale(LC_NUMERIC, "C");
# endif
}
}
}
#endif // MACOS_CONVERT

View File

@ -835,8 +835,9 @@ check_str_len(char_u *str)
GetSystemInfo(&si);
// get memory information
if (VirtualQuery(str, &mbi, sizeof(mbi)))
{
if (!VirtualQuery(str, &mbi, sizeof(mbi)))
return 0;
// pre cast these (typing savers)
long_u dwStr = (long_u)str;
long_u dwBaseAddress = (long_u)mbi.BaseAddress;
@ -852,7 +853,6 @@ check_str_len(char_u *str)
for (i = 0; i < pageLength; ++i, ++length)
if (p[i] == NUL)
return length + 1;
}
return 0;
}
@ -1213,8 +1213,9 @@ PrintHookProc(
RECT rc, rcDlg, rcOwner;
PRINTDLGW *pPD;
if (uiMsg == WM_INITDIALOG)
{
if (uiMsg != WM_INITDIALOG)
return FALSE;
// Get the owner window and dialog box rectangles.
if ((hwndOwner = GetParent(hDlg)) == NULL)
hwndOwner = GetDesktopWindow();
@ -1249,7 +1250,6 @@ PrintHookProc(
// Bring the window to top
BringWindowToTop(GetParent(hDlg));
SetForegroundWindow(hDlg);
}
return FALSE;
}
@ -1571,7 +1571,6 @@ mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
return TRUE;
init_fail_dlg:
{
DWORD err = CommDlgExtendedError();
if (err)
@ -1593,7 +1592,6 @@ init_fail_dlg:
mch_print_cleanup();
return FALSE;
}
}
@ -1999,11 +1997,11 @@ serverSendEnc(HWND target)
static void
CleanUpMessaging(void)
{
if (message_window != 0)
{
if (message_window == 0)
return;
DestroyWindow(message_window);
message_window = 0;
}
}
static int save_reply(HWND server, char_u *reply, int expr);

View File

@ -67,8 +67,9 @@ clip_mch_request_selection(Clipboard_T *cbd)
char_u *clip_text = NULL;
cbdata = PhClipboardPasteStart(PhInputGroup(NULL));
if (cbdata != NULL)
{
if (cbdata == NULL)
return;
// Look for the vim specific clip first
clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM);
if (clip_header != NULL && clip_header->data != NULL)
@ -98,7 +99,6 @@ clip_mch_request_selection(Clipboard_T *cbd)
clip_yank_selection(type, clip_text, clip_length, cbd);
PhClipboardPasteFinish(cbdata);
}
}
void

View File

@ -780,8 +780,9 @@ get_stack_limit(void)
int
mch_stackcheck(char *p)
{
if (stack_limit != NULL)
{
if (stack_limit == NULL)
return OK;
if (stack_grows_downwards)
{
if (p < stack_limit)
@ -789,7 +790,6 @@ mch_stackcheck(char *p)
}
else if (p > stack_limit)
return FAIL;
}
return OK;
}
#endif
@ -837,8 +837,9 @@ static char *signal_stack;
static void
init_signal_stack(void)
{
if (signal_stack != NULL)
{
if (signal_stack == NULL)
return;
# ifdef HAVE_SIGALTSTACK
# ifdef HAVE_SS_BASE
sigstk.ss_base = signal_stack;
@ -855,7 +856,6 @@ init_signal_stack(void)
sigstk.ss_onstack = 0;
(void)sigstack(&sigstk, NULL);
# endif
}
}
#endif
@ -2020,8 +2020,9 @@ get_x11_thing(
int retval = FALSE;
Status status;
if (get_x11_windis() == OK)
{
if (get_x11_windis() != OK)
return FALSE;
// Get window/icon name if any
if (get_title)
status = XGetWMName(x11_display, x11_window, &text_prop);
@ -2037,7 +2038,6 @@ get_x11_thing(
// Previously this was only done for xterm and alike. I don't see a
// reason why it would fail for other terminal emulators.
// if (term_is_xterm)
{
Window root;
Window parent;
Window win = x11_window;
@ -2060,7 +2060,7 @@ get_x11_thing(
else
status = XGetWMIconName(x11_display, win, &text_prop);
}
}
if (status && text_prop.value != NULL)
{
retval = TRUE;
@ -2105,7 +2105,6 @@ get_x11_thing(
}
XFree((void *)text_prop.value);
}
}
return retval;
}
@ -2772,8 +2771,9 @@ fname_case(
DIR *dirp;
struct dirent *dp;
if (mch_lstat((char *)name, &st) >= 0)
{
if (mch_lstat((char *)name, &st) < 0)
return;
// Open the directory where the file is located.
slash = vim_strrchr(name, '/');
if (slash == NULL)
@ -2789,8 +2789,9 @@ fname_case(
tail = slash + 1;
}
if (dirp != NULL)
{
if (dirp == NULL)
return;
while ((dp = readdir(dirp)) != NULL)
{
// Only accept names that differ in case and are the same byte
@ -2816,8 +2817,6 @@ fname_case(
}
closedir(dirp);
}
}
}
#endif
@ -2902,8 +2901,9 @@ mch_copy_sec(char_u *from_file, char_u *to_file)
if (selinux_enabled == -1)
selinux_enabled = is_selinux_enabled();
if (selinux_enabled > 0)
{
if (selinux_enabled <= 0)
return;
// Use "char *" instead of "security_context_t" to avoid a deprecation
// warning.
char *from_context = NULL;
@ -2941,7 +2941,6 @@ mch_copy_sec(char_u *from_file, char_u *to_file)
}
freecon(to_context);
freecon(from_context);
}
}
#endif // HAVE_SELINUX
@ -3549,8 +3548,9 @@ mch_tcgetattr(int fd, void *term)
int retval = -1;
tty_fd = get_tty_fd(fd);
if (tty_fd >= 0)
{
if (tty_fd < 0)
return -1;
#ifdef NEW_TTY_SYSTEM
# ifdef HAVE_TERMIOS_H
retval = tcgetattr(tty_fd, (struct termios *)term);
@ -3563,7 +3563,6 @@ mch_tcgetattr(int fd, void *term)
#endif
if (tty_fd != fd)
close(tty_fd);
}
return retval;
}
@ -3682,8 +3681,9 @@ get_stty(void)
char_u buf[2];
char_u *p;
if (get_tty_info(read_cmd_fd, &info) == OK)
{
if (get_tty_info(read_cmd_fd, &info) != OK)
return;
intr_char = info.interrupt;
buf[0] = info.backspace;
buf[1] = NUL;
@ -3693,7 +3693,6 @@ get_stty(void)
p = find_termcode((char_u *)"kD");
if (p != NULL && p[0] == buf[0] && p[1] == buf[1])
do_fixdel(NULL);
}
}
/*
@ -4160,8 +4159,9 @@ mch_report_winsize(int fd, int rows, int cols)
int retval = -1;
tty_fd = get_tty_fd(fd);
if (tty_fd >= 0)
{
if (tty_fd < 0)
return FAIL;
# if defined(TIOCSWINSZ)
struct winsize ws;
@ -4183,7 +4183,6 @@ mch_report_winsize(int fd, int rows, int cols)
# endif
if (tty_fd != fd)
close(tty_fd);
}
return retval == 0 ? OK : FAIL;
}
#endif
@ -4362,8 +4361,9 @@ open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **name1, char_u **name2)
*name2 = NULL;
*pty_master_fd = mch_openpty(&tty_name); // open pty
if (*pty_master_fd >= 0)
{
if (*pty_master_fd < 0)
return;
// Leaving out O_NOCTTY may lead to waitpid() always returning
// 0 on Mac OS X 10.7 thereby causing freezes. Let's assume
// adding O_NOCTTY always works when defined.
@ -4384,7 +4384,6 @@ open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **name1, char_u **name2)
if (name2 != NULL)
*name2 = vim_strsave((char_u *)tty_name);
}
}
}
#endif
@ -7250,8 +7249,9 @@ gpm_open(void)
return 0;
#endif
if (!gpm_flag)
{
if (gpm_flag)
return 1; // already open
gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN);
gpm_connect.defaultMask = ~GPM_HARD;
// Default handling for mouse move
@ -7271,8 +7271,6 @@ gpm_open(void)
if (gpm_fd == -2)
Gpm_Close(); // We don't want to talk to xterm via gpm
return 0;
}
return 1; // already open
}
/*
@ -7395,14 +7393,13 @@ sysmouse_open(void)
mouse.operation = MOUSE_MODE;
mouse.u.mode.mode = 0;
mouse.u.mode.signal = SIGUSR2;
if (ioctl(1, CONS_MOUSECTL, &mouse) != -1)
{
if (ioctl(1, CONS_MOUSECTL, &mouse) == -1)
return FAIL;
signal(SIGUSR2, (void (*)())sig_sysmouse);
mouse.operation = MOUSE_SHOW;
ioctl(1, CONS_MOUSECTL, &mouse);
return OK;
}
return FAIL;
}
/*
@ -8243,14 +8240,14 @@ xsmp_init(void)
void
xsmp_close(void)
{
if (xsmp_icefd != -1)
{
if (xsmp_icefd == -1)
return;
SmcCloseConnection(xsmp.smcconn, 0, NULL);
if (xsmp.clientid != NULL)
free(xsmp.clientid);
xsmp.clientid = NULL;
xsmp_icefd = -1;
}
}
#endif // USE_XSMP
@ -8348,11 +8345,11 @@ start_timeout(long msec)
void
delete_timer(void)
{
if (timer_created)
{
if (!timer_created)
return;
timer_delete(timer_id);
timer_created = FALSE;
}
}
# else // HAVE_TIMER_CREATE

View File

@ -278,15 +278,15 @@ get_build_number(void)
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
hNtdll = GetModuleHandle("ntdll.dll");
if (hNtdll != NULL)
{
if (hNtdll == NULL)
return ver;
pRtlGetVersion =
(PfnRtlGetVersion)GetProcAddress(hNtdll, "RtlGetVersion");
pRtlGetVersion(&osver);
ver = MAKE_VER(min(osver.dwMajorVersion, 255),
min(osver.dwMinorVersion, 255),
min(osver.dwBuildNumber, 32767));
}
return ver;
}
@ -478,11 +478,13 @@ get_exe_name(void)
exe_name = FullName_save((char_u *)temp, FALSE);
}
if (exe_path == NULL && exe_name != NULL)
{
if (exe_path != NULL || exe_name == NULL)
return;
exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name);
if (exe_path != NULL)
{
if (exe_path == NULL)
return;
// Append our starting directory to $PATH, so that when doing
// "!xxd" it's found in our starting directory. Needed because
// SearchPath() also looks there.
@ -500,8 +502,6 @@ get_exe_name(void)
STRCAT(temp, exe_path);
vim_setenv((char_u *)"PATH", (char_u *)temp);
}
}
}
}
/*
@ -533,18 +533,21 @@ vimLoadLib(const char *name)
// No need to load any library when registering OLE.
if (found_register_arg)
return dll;
return NULL;
// NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
// vimLoadLib() recursively, which causes a stack overflow.
if (exe_path == NULL)
get_exe_name();
if (exe_path != NULL)
{
if (exe_path == NULL)
return NULL;
WCHAR old_dirw[MAXPATHL];
if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0)
{
if (GetCurrentDirectoryW(MAXPATHL, old_dirw) == 0)
return NULL;
// Change directory to where the executable is, both to make
// sure we find a .dll there and to avoid looking for a .dll
// in the current directory.
@ -552,9 +555,6 @@ vimLoadLib(const char *name)
dll = LoadLibrary(name);
SetCurrentDirectoryW(old_dirw);
return dll;
}
}
return dll;
}
#if defined(VIMDLL) || defined(PROTO)
@ -907,8 +907,9 @@ PlatformId(void)
{
static int done = FALSE;
if (!done)
{
if (done)
return;
OSVERSIONINFO ovi;
ovi.dwOSVersionInfoSize = sizeof(ovi);
@ -931,7 +932,6 @@ PlatformId(void)
win32_enable_privilege(SE_SECURITY_NAME, TRUE);
#endif
done = TRUE;
}
}
#ifdef _MSC_VER
# pragma warning(pop)
@ -3051,8 +3051,9 @@ FitConsoleWindow(
COORD dwWindowSize;
BOOL NeedAdjust = FALSE;
if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
{
if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi))
return FALSE;
/*
* A buffer resize will fail if the current console window does
* not lie completely within that buffer. To avoid this, we might
@ -3082,9 +3083,6 @@ FitConsoleWindow(
return FALSE;
}
return TRUE;
}
return FALSE;
}
typedef struct ConsoleBufferStruct
@ -3674,17 +3672,15 @@ mch_get_host_name(
WCHAR wszHostName[256 + 1];
DWORD wcch = ARRAY_LENGTH(wszHostName);
if (GetComputerNameW(wszHostName, &wcch))
{
char_u *p = utf16_to_enc(wszHostName, NULL);
if (!GetComputerNameW(wszHostName, &wcch))
return;
char_u *p = utf16_to_enc(wszHostName, NULL);
if (p == NULL)
return;
if (p != NULL)
{
vim_strncpy(s, p, len - 1);
vim_free(p);
return;
}
}
}
@ -3732,8 +3728,9 @@ mch_dirname(
* But the Win32s known bug list says that getcwd() doesn't work
* so use the Win32 system call instead. <Negri>
*/
if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
{
if (GetCurrentDirectoryW(_MAX_PATH, wbuf) == 0)
return FAIL;
WCHAR wcbuf[_MAX_PATH + 1];
char_u *p = NULL;
@ -3750,14 +3747,12 @@ mch_dirname(
if (p == NULL)
p = utf16_to_enc(wbuf, NULL);
if (p != NULL)
{
if (p == NULL)
return FAIL;
vim_strncpy(buf, p, len - 1);
vim_free(p);
return OK;
}
}
return FAIL;
}
/*
@ -3974,14 +3969,14 @@ win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info)
NULL); // handle to template file
vim_free(wn);
if (hFile != INVALID_HANDLE_VALUE)
{
if (hFile == INVALID_HANDLE_VALUE)
return FILEINFO_READ_FAIL;
if (GetFileInformationByHandle(hFile, info) != 0)
res = FILEINFO_OK;
else
res = FILEINFO_INFO_FAIL;
CloseHandle(hFile);
}
return res;
}
@ -6170,12 +6165,12 @@ mch_signal_job(job_T *job, char_u *how)
void
mch_clear_job(job_T *job)
{
if (job->jv_status != JOB_FAILED)
{
if (job->jv_status == JOB_FAILED)
return;
if (job->jv_job_object != NULL)
CloseHandle(job->jv_job_object);
CloseHandle(job->jv_proc_info.hProcess);
}
}
#endif
@ -7988,8 +7983,9 @@ load_ntdll(void)
{
static int loaded = -1;
if (loaded == -1)
{
if (loaded != -1)
return (BOOL) loaded;
HMODULE hNtdll = GetModuleHandle("ntdll.dll");
if (hNtdll != NULL)
{
@ -8013,7 +8009,6 @@ load_ntdll(void)
loaded = FALSE;
else
loaded = TRUE;
}
return (BOOL) loaded;
}
@ -8190,11 +8185,11 @@ get_cmd_argsW(char ***argvp)
void
free_cmd_argsW(void)
{
if (ArglistW != NULL)
{
if (ArglistW == NULL)
return;
GlobalFree(ArglistW);
ArglistW = NULL;
}
}
/*
@ -8899,8 +8894,9 @@ resize_console_buf(void)
COORD coord;
SMALL_RECT newsize;
if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
{
if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi))
return;
coord.X = SRWIDTH(csbi.srWindow);
coord.Y = SRHEIGHT(csbi.srWindow);
SetConsoleScreenBufferSize(g_hConOut, coord);
@ -8912,7 +8908,6 @@ resize_console_buf(void)
SetConsoleWindowInfo(g_hConOut, TRUE, &newsize);
SetConsoleScreenBufferSize(g_hConOut, coord);
}
}
#endif
@ -8926,14 +8921,14 @@ GetWin32Error(void)
NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL);
if (oldmsg != NULL)
LocalFree(oldmsg);
if (msg != NULL)
{
if (msg == NULL)
return NULL;
// remove trailing \r\n
char *pcrlf = strstr(msg, "\r\n");
if (pcrlf != NULL)
*pcrlf = '\0';
oldmsg = msg;
}
return msg;
}

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1208,
/**/
1207,
/**/