diff options
-rw-r--r-- | src/job.c | 100 | ||||
-rw-r--r-- | src/list.c | 222 | ||||
-rw-r--r-- | src/locale.c | 47 | ||||
-rw-r--r-- | src/main.c | 49 | ||||
-rw-r--r-- | src/map.c | 55 | ||||
-rw-r--r-- | src/mark.c | 46 | ||||
-rw-r--r-- | src/match.c | 54 | ||||
-rw-r--r-- | src/mbyte.c | 138 | ||||
-rw-r--r-- | src/memfile.c | 28 | ||||
-rw-r--r-- | src/memline.c | 86 | ||||
-rw-r--r-- | src/menu.c | 106 | ||||
-rw-r--r-- | src/message.c | 136 | ||||
-rw-r--r-- | src/misc1.c | 80 | ||||
-rw-r--r-- | src/misc2.c | 80 | ||||
-rw-r--r-- | src/move.c | 119 | ||||
-rw-r--r-- | src/version.c | 2 |
16 files changed, 675 insertions, 673 deletions
@@ -793,11 +793,11 @@ job_free_job(job_T *job) static void job_free(job_T *job) { - if (!in_free_unref_items) - { - job_free_contents(job); - job_free_job(job); - } + if (in_free_unref_items) + return; + + job_free_contents(job); + job_free_job(job); } static job_T *jobs_to_free = NULL; @@ -1087,28 +1087,28 @@ set_ref_in_job(int copyID) void job_unref(job_T *job) { - if (job != NULL && --job->jv_refcount <= 0) + if (job == NULL || --job->jv_refcount > 0) + return; + + // Do not free the job if there is a channel where the close callback + // may get the job info. + if (job_channel_still_useful(job)) + return; + + // Do not free the job when it has not ended yet and there is a + // "stoponexit" flag or an exit callback. + if (!job_need_end_check(job)) { - // Do not free the job if there is a channel where the close callback - // may get the job info. - if (!job_channel_still_useful(job)) - { - // Do not free the job when it has not ended yet and there is a - // "stoponexit" flag or an exit callback. - if (!job_need_end_check(job)) - { - job_free(job); - } - else if (job->jv_channel != NULL) - { - // Do remove the link to the channel, otherwise it hangs - // around until Vim exits. See job_free() for refcount. - ch_log(job->jv_channel, "detaching channel from job"); - job->jv_channel->ch_job = NULL; - channel_unref(job->jv_channel); - job->jv_channel = NULL; - } - } + job_free(job); + } + else if (job->jv_channel != NULL) + { + // Do remove the link to the channel, otherwise it hangs + // around until Vim exits. See job_free() for refcount. + ch_log(job->jv_channel, "detaching channel from job"); + job->jv_channel->ch_job = NULL; + channel_unref(job->jv_channel); + job->jv_channel = NULL; } } @@ -1157,18 +1157,18 @@ job_alloc(void) job_T *job; job = ALLOC_CLEAR_ONE(job_T); - if (job != NULL) - { - job->jv_refcount = 1; - job->jv_stoponexit = vim_strsave((char_u *)"term"); + if (job == NULL) + return NULL; - if (first_job != NULL) - { - first_job->jv_prev = job; - job->jv_next = first_job; - } - first_job = job; + job->jv_refcount = 1; + job->jv_stoponexit = vim_strsave((char_u *)"term"); + + if (first_job != NULL) + { + first_job->jv_prev = job; + job->jv_next = first_job; } + first_job = job; return job; } @@ -1803,13 +1803,13 @@ f_job_getchannel(typval_T *argvars, typval_T *rettv) return; job = get_job_arg(&argvars[0]); - if (job != NULL) - { - rettv->v_type = VAR_CHANNEL; - rettv->vval.v_channel = job->jv_channel; - if (job->jv_channel != NULL) - ++job->jv_channel->ch_refcount; - } + if (job == NULL) + return; + + rettv->v_type = VAR_CHANNEL; + rettv->vval.v_channel = job->jv_channel; + if (job->jv_channel != NULL) + ++job->jv_channel->ch_refcount; } /* @@ -1855,13 +1855,13 @@ job_info(job_T *job, dict_T *dict) #endif l = list_alloc(); - if (l != NULL) - { - dict_add_list(dict, "cmd", l); - if (job->jv_argv != NULL) - for (i = 0; job->jv_argv[i] != NULL; i++) - list_append_string(l, (char_u *)job->jv_argv[i], -1); - } + if (l == NULL) + return; + + dict_add_list(dict, "cmd", l); + if (job->jv_argv != NULL) + for (i = 0; job->jv_argv[i] != NULL; i++) + list_append_string(l, (char_u *)job->jv_argv[i], -1); } /* diff --git a/src/list.c b/src/list.c index 8f228a1aeb..71184547ef 100644 --- a/src/list.c +++ b/src/list.c @@ -124,27 +124,27 @@ list_alloc_with_items(int count) list_init(l); - if (count > 0) - { - listitem_T *li = (listitem_T *)(l + 1); - int i; + if (count <= 0) + return l; - l->lv_len = count; - l->lv_with_items = count; - l->lv_first = li; - l->lv_u.mat.lv_last = li + count - 1; - for (i = 0; i < count; ++i) - { - if (i == 0) - li->li_prev = NULL; - else - li->li_prev = li - 1; - if (i == count - 1) - li->li_next = NULL; - else - li->li_next = li + 1; - ++li; - } + listitem_T *li = (listitem_T *)(l + 1); + int i; + + l->lv_len = count; + l->lv_with_items = count; + l->lv_first = li; + l->lv_u.mat.lv_last = li + count - 1; + for (i = 0; i < count; ++i) + { + if (i == 0) + li->li_prev = NULL; + else + li->li_prev = li - 1; + if (i == count - 1) + li->li_next = NULL; + else + li->li_next = li + 1; + ++li; } return l; @@ -297,11 +297,11 @@ list_free_items(int copyID) void list_free(list_T *l) { - if (!in_free_unref_items) - { - list_free_contents(l); - list_free_list(l); - } + if (in_free_unref_items) + return; + + list_free_contents(l); + list_free_list(l); } /* @@ -540,13 +540,13 @@ list_find_index(list_T *l, long *idx) { listitem_T *li = list_find(l, *idx); - if (li == NULL) + if (li != NULL) + return li; + + if (*idx < 0) { - if (*idx < 0) - { - *idx = 0; - li = list_find(l, *idx); - } + *idx = 0; + li = list_find(l, *idx); } return li; } @@ -772,21 +772,21 @@ check_range_index_one(list_T *l, long *n1, int can_append, int quiet) long orig_n1 = *n1; listitem_T *li = list_find_index(l, n1); + if (li != NULL) + return li; + + // Vim9: Allow for adding an item at the end. + if (can_append && in_vim9script() + && *n1 == l->lv_len && l->lv_lock == 0) + { + list_append_number(l, 0); + li = list_find_index(l, n1); + } if (li == NULL) { - // Vim9: Allow for adding an item at the end. - if (can_append && in_vim9script() - && *n1 == l->lv_len && l->lv_lock == 0) - { - list_append_number(l, 0); - li = list_find_index(l, n1); - } - if (li == NULL) - { - if (!quiet) - semsg(_(e_list_index_out_of_range_nr), orig_n1); - return NULL; - } + if (!quiet) + semsg(_(e_list_index_out_of_range_nr), orig_n1); + return NULL; } return li; } @@ -1286,45 +1286,45 @@ list_copy(list_T *orig, int deep, int top, int copyID) return NULL; copy = list_alloc(); - if (copy != NULL) + if (copy == NULL) + return NULL; + + if (orig->lv_type == NULL || top || deep) + copy->lv_type = NULL; + else + copy->lv_type = alloc_type(orig->lv_type); + if (copyID != 0) { - if (orig->lv_type == NULL || top || deep) - copy->lv_type = NULL; - else - copy->lv_type = alloc_type(orig->lv_type); - if (copyID != 0) - { - // Do this before adding the items, because one of the items may - // refer back to this list. - orig->lv_copyID = copyID; - orig->lv_copylist = copy; - } - CHECK_LIST_MATERIALIZE(orig); - for (item = orig->lv_first; item != NULL && !got_int; - item = item->li_next) + // Do this before adding the items, because one of the items may + // refer back to this list. + orig->lv_copyID = copyID; + orig->lv_copylist = copy; + } + CHECK_LIST_MATERIALIZE(orig); + for (item = orig->lv_first; item != NULL && !got_int; + item = item->li_next) + { + ni = listitem_alloc(); + if (ni == NULL) + break; + if (deep) { - ni = listitem_alloc(); - if (ni == NULL) - break; - if (deep) + if (item_copy(&item->li_tv, &ni->li_tv, + deep, FALSE, copyID) == FAIL) { - if (item_copy(&item->li_tv, &ni->li_tv, - deep, FALSE, copyID) == FAIL) - { - vim_free(ni); - break; - } + vim_free(ni); + break; } - else - copy_tv(&item->li_tv, &ni->li_tv); - list_append(copy, ni); - } - ++copy->lv_refcount; - if (item != NULL) - { - list_unref(copy); - copy = NULL; } + else + copy_tv(&item->li_tv, &ni->li_tv); + list_append(copy, ni); + } + ++copy->lv_refcount; + if (item != NULL) + { + list_unref(copy); + copy = NULL; } return copy; @@ -1491,17 +1491,17 @@ list_join( retval = list_join_inner(gap, l, sep, echo_style, restore_copyID, copyID, &join_ga); + if (join_ga.ga_data == NULL) + return retval; + // Dispose each item in join_ga. - if (join_ga.ga_data != NULL) + p = (join_T *)join_ga.ga_data; + for (i = 0; i < join_ga.ga_len; ++i) { - p = (join_T *)join_ga.ga_data; - for (i = 0; i < join_ga.ga_len; ++i) - { - vim_free(p->tofree); - ++p; - } - ga_clear(&join_ga); + vim_free(p->tofree); + ++p; } + ga_clear(&join_ga); return retval; } @@ -2560,36 +2560,36 @@ filter_map(typval_T *argvars, typval_T *rettv, filtermap_T filtermap) // message. Avoid a misleading error message for an empty string that // was not passed as argument. expr = &argvars[1]; - if (expr->v_type != VAR_UNKNOWN) - { - typval_T save_val; - typval_T save_key; + if (expr->v_type == VAR_UNKNOWN) + return; + + typval_T save_val; + typval_T save_key; - prepare_vimvar(VV_VAL, &save_val); - prepare_vimvar(VV_KEY, &save_key); + prepare_vimvar(VV_VAL, &save_val); + prepare_vimvar(VV_KEY, &save_key); - // We reset "did_emsg" to be able to detect whether an error - // occurred during evaluation of the expression. - save_did_emsg = did_emsg; - did_emsg = FALSE; + // We reset "did_emsg" to be able to detect whether an error + // occurred during evaluation of the expression. + save_did_emsg = did_emsg; + did_emsg = FALSE; - if (argvars[0].v_type == VAR_DICT) - dict_filter_map(argvars[0].vval.v_dict, filtermap, type, func_name, - arg_errmsg, expr, rettv); - else if (argvars[0].v_type == VAR_BLOB) - blob_filter_map(argvars[0].vval.v_blob, filtermap, expr, rettv); - else if (argvars[0].v_type == VAR_STRING) - string_filter_map(tv_get_string(&argvars[0]), filtermap, expr, - rettv); - else // argvars[0].v_type == VAR_LIST - list_filter_map(argvars[0].vval.v_list, filtermap, type, func_name, - arg_errmsg, expr, rettv); + if (argvars[0].v_type == VAR_DICT) + dict_filter_map(argvars[0].vval.v_dict, filtermap, type, func_name, + arg_errmsg, expr, rettv); + else if (argvars[0].v_type == VAR_BLOB) + blob_filter_map(argvars[0].vval.v_blob, filtermap, expr, rettv); + else if (argvars[0].v_type == VAR_STRING) + string_filter_map(tv_get_string(&argvars[0]), filtermap, expr, + rettv); + else // argvars[0].v_type == VAR_LIST + list_filter_map(argvars[0].vval.v_list, filtermap, type, func_name, + arg_errmsg, expr, rettv); - restore_vimvar(VV_KEY, &save_key); - restore_vimvar(VV_VAL, &save_val); + restore_vimvar(VV_KEY, &save_key); + restore_vimvar(VV_VAL, &save_val); - did_emsg |= save_did_emsg; - } + did_emsg |= save_did_emsg; } /* diff --git a/src/locale.c b/src/locale.c index d0378ffb50..ccdb479a8e 100644 --- a/src/locale.c +++ b/src/locale.c @@ -151,20 +151,20 @@ get_mess_env(void) char_u *p; p = mch_getenv((char_u *)"LC_ALL"); - if (p == NULL || *p == NUL) - { - p = mch_getenv((char_u *)"LC_MESSAGES"); - if (p == NULL || *p == NUL) - { - p = mch_getenv((char_u *)"LANG"); - if (p != NULL && VIM_ISDIGIT(*p)) - p = NULL; // ignore something like "1043" + if (p != NULL && *p != NUL) + return p; + + p = mch_getenv((char_u *)"LC_MESSAGES"); + if (p != NULL && *p != NUL) + return p; + + p = mch_getenv((char_u *)"LANG"); + if (p != NULL && VIM_ISDIGIT(*p)) + p = NULL; // ignore something like "1043" # ifdef HAVE_GET_LOCALE_VAL - if (p == NULL || *p == NUL) - p = get_locale_val(LC_CTYPE); + if (p == NULL || *p == NUL) + p = get_locale_val(LC_CTYPE); # endif - } - } return p; } #endif @@ -504,11 +504,11 @@ find_locales(void) static void init_locales(void) { - if (!did_init_locales) - { - did_init_locales = TRUE; - locales = find_locales(); - } + if (did_init_locales) + return; + + did_init_locales = TRUE; + locales = find_locales(); } # if defined(EXITFREE) || defined(PROTO) @@ -516,12 +516,13 @@ init_locales(void) free_locales(void) { int i; - if (locales != NULL) - { - for (i = 0; locales[i] != NULL; i++) - vim_free(locales[i]); - VIM_CLEAR(locales); - } + + if (locales == NULL) + return; + + for (i = 0; locales[i] != NULL; i++) + vim_free(locales[i]); + VIM_CLEAR(locales); } # endif diff --git a/src/main.c b/src/main.c index 0299c61a79..d1c42ed120 100644 --- a/src/main.c +++ b/src/main.c @@ -3099,23 +3099,23 @@ exe_pre_commands(mparm_T *parmp) int i; ESTACK_CHECK_DECLARATION - if (cnt > 0) - { - curwin->w_cursor.lnum = 0; // just in case.. - estack_push(ETYPE_ARGS, (char_u *)_("pre-vimrc command line"), 0); - ESTACK_CHECK_SETUP + if (cnt <= 0) + return; + + curwin->w_cursor.lnum = 0; // just in case.. + estack_push(ETYPE_ARGS, (char_u *)_("pre-vimrc command line"), 0); + ESTACK_CHECK_SETUP # ifdef FEAT_EVAL current_sctx.sc_sid = SID_CMDARG; # endif for (i = 0; i < cnt; ++i) do_cmdline_cmd(cmds[i]); - ESTACK_CHECK_NOW + ESTACK_CHECK_NOW estack_pop(); # ifdef FEAT_EVAL - current_sctx.sc_sid = 0; + current_sctx.sc_sid = 0; # endif - TIME_MSG("--cmd commands"); - } + TIME_MSG("--cmd commands"); } /* @@ -3369,28 +3369,27 @@ process_env( ESTACK_CHECK_DECLARATION - if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) - { - if (is_viminit) - vimrc_found(NULL, NULL); - estack_push(ETYPE_ENV, env, 0); - ESTACK_CHECK_SETUP + if ((initstr = mch_getenv(env)) == NULL || *initstr == NUL) + return FAIL; + + if (is_viminit) + vimrc_found(NULL, NULL); + estack_push(ETYPE_ENV, env, 0); + ESTACK_CHECK_SETUP save_current_sctx = current_sctx; - current_sctx.sc_version = 1; + current_sctx.sc_version = 1; #ifdef FEAT_EVAL - current_sctx.sc_sid = SID_ENV; - current_sctx.sc_seq = 0; - current_sctx.sc_lnum = 0; + current_sctx.sc_sid = SID_ENV; + current_sctx.sc_seq = 0; + current_sctx.sc_lnum = 0; #endif - do_cmdline_cmd(initstr); + do_cmdline_cmd(initstr); - ESTACK_CHECK_NOW + ESTACK_CHECK_NOW estack_pop(); - current_sctx = save_current_sctx; - return OK; - } - return FAIL; + current_sctx = save_current_sctx; + return OK; } #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN) @@ -67,11 +67,11 @@ is_maphash_valid(void) static void validate_maphash(void) { - if (!maphash_valid) - { - CLEAR_FIELD(maphash); - maphash_valid = TRUE; - } + if (maphash_valid) + return; + + CLEAR_FIELD(maphash); + maphash_valid = TRUE; } /* @@ -581,8 +581,8 @@ do_map( // needs to be freed later (*keys_buf and *arg_buf). // replace_termcodes() also removes CTRL-Vs and sometimes backslashes. // If something like <C-H> is simplified to 0x08 then mark it as simplified - // and also add a n entry with a modifier, which will work when - // modifyOtherKeys is working. + // and also add an entry with a modifier, which will work when using a key + // protocol. if (haskey) { char_u *new_keys; @@ -1843,32 +1843,33 @@ vim_strsave_escape_csi(char_u *p) // illegal utf-8 byte: // 0xc0 -> 0xc3 0x80 -> 0xc3 K_SPECIAL KS_SPECIAL KE_FILLER res = alloc(STRLEN(p) * 4 + 1); - if (res != NULL) + if (res == NULL) + return NULL; + + d = res; + for (s = p; *s != NUL; ) { - d = res; - for (s = p; *s != NUL; ) - { - if ((s[0] == K_SPECIAL + if ((s[0] == K_SPECIAL #ifdef FEAT_GUI || (gui.in_use && s[0] == CSI) #endif - ) && s[1] != NUL && s[2] != NUL) - { - // Copy special key unmodified. - *d++ = *s++; - *d++ = *s++; - *d++ = *s++; - } - else - { - // Add character, possibly multi-byte to destination, escaping - // CSI and K_SPECIAL. Be careful, it can be an illegal byte! - d = add_char2buf(PTR2CHAR(s), d); - s += MB_CPTR2LEN(s); - } + ) && s[1] != NUL && s[2] != NUL) + { + // Copy special key unmodified. + *d++ = *s++; + *d++ = *s++; + *d++ = *s++; + } + else + { + // Add character, possibly multi-byte to destination, escaping + // CSI and K_SPECIAL. Be careful, it can be an illegal byte! + d = add_char2buf(PTR2CHAR(s), d); + s += MB_CPTR2LEN(s); } - *d = NUL; } + *d = NUL; + return res; } diff --git a/src/mark.c b/src/mark.c index 584db033d3..a7592e6077 100644 --- a/src/mark.c +++ b/src/mark.c @@ -485,34 +485,34 @@ fname2fnum(xfmark_T *fm) { char_u *p; - if (fm->fname != NULL) - { - /* - * First expand "~/" in the file name to the home directory. - * Don't expand the whole name, it may contain other '~' chars. - */ - if (fm->fname[0] == '~' && (fm->fname[1] == '/' + if (fm->fname == NULL) + return; + + /* + * First expand "~/" in the file name to the home directory. + * Don't expand the whole name, it may contain other '~' chars. + */ + if (fm->fname[0] == '~' && (fm->fname[1] == '/' #ifdef BACKSLASH_IN_FILENAME - || fm->fname[1] == '\\' + || fm->fname[1] == '\\' #endif - )) - { - int len; + )) + { + int len; - expand_env((char_u *)"~/", NameBuff, MAXPATHL); - len = (int)STRLEN(NameBuff); - vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1); - } - else - vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1); + expand_env((char_u *)"~/", NameBuff, MAXPATHL); + len = (int)STRLEN(NameBuff); + vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1); + } + else + vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1); - // Try to shorten the file name. - mch_dirname(IObuff, IOSIZE); - p = shorten_fname(NameBuff, IObuff); + // Try to shorten the file name. + mch_dirname(IObuff, IOSIZE); + p = shorten_fname(NameBuff, IObuff); - // buflist_new() will call fmarks_check_names() - (void)buflist_new(NameBuff, p, (linenr_T)1, 0); - } + // buflist_new() will call fmarks_check_names() + (void)buflist_new(NameBuff, p, (linenr_T)1, 0); } /* diff --git a/src/match.c b/src/match.c index 6ac6513ca8..f59c2066a1 100644 --- a/src/match.c +++ b/src/match.c @@ -978,14 +978,14 @@ matchadd_dict_arg(typval_T *tv, char_u **conceal_char, win_T **win) if (dict_has_key(tv->vval.v_dict, "conceal")) *conceal_char = dict_get_string(tv->vval.v_dict, "conceal", FALSE); - if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) != NULL) + if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) == NULL) + return OK; + + *win = find_win_by_nr_or_id(&di->di_tv); + if (*win == NULL) { - *win = find_win_by_nr_or_id(&di->di_tv); - if (*win == NULL) - { - emsg(_(e_invalid_window_number)); - return FAIL; - } + emsg(_(e_invalid_window_number)); + return FAIL; } return OK; @@ -1330,32 +1330,32 @@ f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED) void f_matcharg(typval_T *argvars UNUSED, typval_T *rettv) { - if (rettv_list_alloc(rettv) == OK) - { + if (rettv_list_alloc(rettv) != OK) + return; + # ifdef FEAT_SEARCH_EXTRA - int id; - matchitem_T *m; + int id; + matchitem_T *m; - if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) - return; + if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) + return; - id = (int)tv_get_number(&argvars[0]); - if (id >= 1 && id <= 3) + id = (int)tv_get_number(&argvars[0]); + if (id >= 1 && id <= 3) + { + if ((m = get_match(curwin, id)) != NULL) { - if ((m = get_match(curwin, id)) != NULL) - { - list_append_string(rettv->vval.v_list, - syn_id2name(m->mit_hlg_id), -1); - list_append_string(rettv->vval.v_list, m->mit_pattern, -1); - } - else - { - list_append_string(rettv->vval.v_list, NULL, -1); - list_append_string(rettv->vval.v_list, NULL, -1); - } + list_append_string(rettv->vval.v_list, + syn_id2name(m->mit_hlg_id), -1); + list_append_string(rettv->vval.v_list, m->mit_pattern, -1); + } + else + { + list_append_string(rettv->vval.v_list, NULL, -1); + list_append_string(rettv->vval.v_list, NULL, -1); } -# endif } +# endif } /* diff --git a/src/mbyte.c b/src/mbyte.c index 1570cef231..07cd9c6e64 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -809,17 +809,17 @@ bomb_size(void) void remove_bom(char_u *s) { - if (enc_utf8) - { - char_u *p = s; + if (!enc_utf8) + return; - while ((p = vim_strbyte(p, 0xef)) != NULL) - { - if (p[1] == 0xbb && p[2] == 0xbf) - STRMOVE(p, p + 3); - else - ++p; - } + char_u *p = s; + + while ((p = vim_strbyte(p, 0xef)) != NULL) + { + if (p[1] == 0xbb && p[2] == 0xbf) + STRMOVE(p, p + 3); + else + ++p; } } #endif @@ -4590,56 +4590,56 @@ enc_canonize(char_u *enc) // copy "enc" to allocated memory, with room for two '-' r = alloc(STRLEN(enc) + 3); - if (r != NULL) + if (r == NULL) + return NULL; + + // Make it all lower case and replace '_' with '-'. + p = r; + for (s = enc; *s != NUL; ++s) { - // Make it all lower case and replace '_' with '-'. - p = r; - for (s = enc; *s != NUL; ++s) - { - if (*s == '_') - *p++ = '-'; - else - *p++ = TOLOWER_ASC(*s); - } - *p = NUL; + if (*s == '_') + *p++ = '-'; + else + *p++ = TOLOWER_ASC(*s); + } + *p = NUL; - // Skip "2byte-" and "8bit-". - p = enc_skip(r); + // Skip "2byte-" and "8bit-". + p = enc_skip(r); - // Change "microsoft-cp" to "cp". Used in some spell files. - if (STRNCMP(p, "microsoft-cp", 12) == 0) - STRMOVE(p, p + 10); + // Change "microsoft-cp" to "cp". Used in some spell files. + if (STRNCMP(p, "microsoft-cp", 12) == 0) + STRMOVE(p, p + 10); - // "iso8859" -> "iso-8859" - if (STRNCMP(p, "iso8859", 7) == 0) - { - STRMOVE(p + 4, p + 3); - p[3] = '-'; - } + // "iso8859" -> "iso-8859" + if (STRNCMP(p, "iso8859", 7) == 0) + { + STRMOVE(p + 4, p + 3); + p[3] = '-'; + } - // "iso-8859n" -> "iso-8859-n" - if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8])) - { - STRMOVE(p + 9, p + 8); - p[8] = '-'; - } + // "iso-8859n" -> "iso-8859-n" + if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8])) + { + STRMOVE(p + 9, p + 8); + p[8] = '-'; + } - // "latin-N" -> "latinN" - if (STRNCMP(p, "latin-", 6) == 0) - STRMOVE(p + 5, p + 6); + // "latin-N" -> "latinN" + if (STRNCMP(p, "latin-", 6) == 0) + STRMOVE(p + 5, p + 6); - if (enc_canon_search(p) >= 0) - { - // canonical name can be used unmodified - if (p != r) - STRMOVE(r, p); - } - else if ((i = enc_alias_search(p)) >= 0) - { - // alias recognized, get canonical name - vim_free(r); - r = vim_strsave((char_u *)enc_canon_table[i].name); - } + if (enc_canon_search(p) >= 0) + { + // canonical name can be used unmodified + if (p != r) + STRMOVE(r, p); + } + else if ((i = enc_alias_search(p)) >= 0) + { + // alias recognized, get canonical name + vim_free(r); + r = vim_strsave((char_u *)enc_canon_table[i].name); } return r; } @@ -5269,26 +5269,26 @@ convert_input_safe( d = string_convert_ext(&input_conv, ptr, &dlen, restp == NULL ? NULL : &unconvertlen); - if (d != NULL) + if (d == NULL) + return dlen; + + if (dlen <= maxlen) { - if (dlen <= maxlen) + if (unconvertlen > 0) { - if (unconvertlen > 0) - { - // Move the unconverted characters to allocated memory. - *restp = alloc(unconvertlen); - if (*restp != NULL) - mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); - *restlenp = unconvertlen; - } - mch_memmove(ptr, d, dlen); + // Move the unconverted characters to allocated memory. + *restp = alloc(unconvertlen); + if (*restp != NULL) + mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); + *restlenp = unconvertlen; } - else - // result is too long, keep the unconverted text (the caller must - // have done something wrong!) - dlen = len; - vim_free(d); + mch_memmove(ptr, d, dlen); } + else + // result is too long, keep the unconverted text (the caller must + // have done something wrong!) + dlen = len; + vim_free(d); return dlen; } diff --git a/src/memfile.c b/src/memfile.c index 0d816f36d3..e8cbe31696 100644 --- a/src/memfile.c +++ b/src/memfile.c @@ -879,16 +879,16 @@ mf_alloc_bhdr(memfile_T *mfp, int page_count) { bhdr_T *hp; - if ((hp = ALLOC_ONE(bhdr_T)) != NULL) + if ((hp = ALLOC_ONE(bhdr_T)) == NULL) + return NULL; + + if ((hp->bh_data = alloc((size_t)mfp->mf_page_size * page_count)) + == NULL) { - if ((hp->bh_data = alloc((size_t)mfp->mf_page_size * page_count)) - == NULL) - { - vim_free(hp); // not enough memory - return NULL; - } - hp->bh_page_count = page_count; + vim_free(hp); // not enough memory + return NULL; } + hp->bh_page_count = page_count; return hp; } @@ -1209,12 +1209,12 @@ mf_set_ffname(memfile_T *mfp) void mf_fullname(memfile_T *mfp) { - if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) - { - vim_free(mfp->mf_fname); - mfp->mf_fname = mfp->mf_ffname; - mfp->mf_ffname = NULL; - } + if (mfp == NULL || mfp->mf_fname == NULL || mfp->mf_ffname == NULL) + return; + + vim_free(mfp->mf_fname); + mfp->mf_fname = mfp->mf_ffname; + mfp->mf_ffname = NULL; } /* diff --git a/src/memline.c b/src/memline.c index 48b17f5589..7cbe559e65 100644 --- a/src/memline.c +++ b/src/memline.c @@ -422,21 +422,21 @@ error: static void ml_set_mfp_crypt(buf_T *buf) { - if (*buf->b_p_key != NUL) - { - int method_nr = crypt_get_method_nr(buf); + if (*buf->b_p_key == NUL) + return; - if (method_nr > CRYPT_M_ZIP && method_nr < CRYPT_M_SOD) - { - // Generate a seed and store it in the memfile. - sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0); - } -#ifdef FEAT_SODIUM - else if (method_nr == CRYPT_M_SOD) - crypt_sodium_randombytes_buf(buf->b_ml.ml_mfp->mf_seed, - MF_SEED_LEN); - #endif + int method_nr = crypt_get_method_nr(buf); + + if (method_nr > CRYPT_M_ZIP && method_nr < CRYPT_M_SOD) + { + // Generate a seed and store it in the memfile. + sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0); } +#ifdef FEAT_SODIUM + else if (method_nr == CRYPT_M_SOD) + crypt_sodium_randombytes_buf(buf->b_ml.ml_mfp->mf_seed, + MF_SEED_LEN); +#endif } /* @@ -2090,22 +2090,22 @@ make_percent_swname(char_u *dir, char_u *name) char_u *d = NULL, *s, *f; f = fix_fname(name != NULL ? name : (char_u *)""); - if (f != NULL) - { - s = alloc(STRLEN(f) + 1); - if (s != NULL) - { - STRCPY(s, f); - for (d = s; *d != NUL; MB_PTR_ADV(d)) - if (vim_ispathsep(*d)) - *d = '%'; + if (f == NULL) + return NULL; - dir[STRLEN(dir) - 1] = NUL; // remove one trailing slash - d = concat_fnames(dir, s, TRUE); - vim_free(s); - } - vim_free(f); + s = alloc(STRLEN(f) + 1); + if (s != NULL) + { + STRCPY(s, f); + for (d = s; *d != NUL; MB_PTR_ADV(d)) + if (vim_ispathsep(*d)) + *d = '%'; + + dir[STRLEN(dir) - 1] = NUL; // remove one trailing slash + d = concat_fnames(dir, s, TRUE); + vim_free(s); } + vim_free(f); return d; } #endif @@ -5473,24 +5473,24 @@ ml_decrypt_data( int text_len; cryptstate_T *state; - if (dp->db_id == DATA_ID) - { - head_end = (char_u *)(&dp->db_index[dp->db_line_count]); - text_start = (char_u *)dp + dp->db_txt_start; - text_len = dp->db_txt_end - dp->db_txt_start; + if (dp->db_id != DATA_ID) + return; + + head_end = (char_u *)(&dp->db_index[dp->db_line_count]); + text_start = (char_u *)dp + dp->db_txt_start; + text_len = dp->db_txt_end - dp->db_txt_start; - if (head_end > text_start || dp->db_txt_start > size - || dp->db_txt_end > size) - return; // data was messed up + if (head_end > text_start || dp->db_txt_start > size + || dp->db_txt_end > size) + return; // data was messed up - state = ml_crypt_prepare(mfp, offset, TRUE); - if (state != NULL) - { - // Decry |