diff options
author | dundargoc <gocdundar@gmail.com> | 2022-11-26 18:57:46 +0100 |
---|---|---|
committer | dundargoc <gocdundar@gmail.com> | 2022-11-28 14:53:35 +0100 |
commit | 3b96ccf7d35be90e49029dec76344d3d92ad91dc (patch) | |
tree | f4768eb7d7be52402ccd55e3e4e04aecceab3e42 | |
parent | b2bb3973d9c7f25acfead2718d74fcf5b1e4551e (diff) | |
download | rneovim-3b96ccf7d35be90e49029dec76344d3d92ad91dc.tar.gz rneovim-3b96ccf7d35be90e49029dec76344d3d92ad91dc.tar.bz2 rneovim-3b96ccf7d35be90e49029dec76344d3d92ad91dc.zip |
refactor: replace char_u with char
Work on https://github.com/neovim/neovim/issues/459
54 files changed, 510 insertions, 509 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index ca8ad16cbf..4ff600618d 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -391,13 +391,13 @@ String cbuf_to_string(const char *buf, size_t size) String cstrn_to_string(const char *str, size_t maxsize) FUNC_ATTR_NONNULL_ALL { - return cbuf_to_string(str, STRNLEN(str, maxsize)); + return cbuf_to_string(str, strnlen(str, maxsize)); } String cstrn_as_string(char *str, size_t maxsize) FUNC_ATTR_NONNULL_ALL { - return cbuf_as_string(str, STRNLEN(str, maxsize)); + return cbuf_as_string(str, strnlen(str, maxsize)); } /// Creates a String using the given C string. Unlike diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 426899c581..57b5adca53 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -304,7 +304,7 @@ static void au_show_for_event(int group, event_T event, char *pat) // all buffer-local patterns. if ((group == AUGROUP_ALL || ap->group == group) && ap->patlen == patlen - && STRNCMP(pat, ap->pat, patlen) == 0) { + && strncmp(pat, ap->pat, (size_t)patlen) == 0) { // Show autocmd's for this autopat, or buflocals <buffer=X> aupat_show(ap, event, previous_group); previous_group = ap->group; @@ -1002,7 +1002,7 @@ int do_autocmd_event(event_T event, char *pat, bool once, int nested, char *cmd, // all buffer-local patterns. if (ap->group == findgroup && ap->patlen == patlen - && STRNCMP(pat, ap->pat, patlen) == 0) { + && strncmp(pat, ap->pat, (size_t)patlen) == 0) { // Remove existing autocommands. // If adding any new autocmd's for this AutoPat, don't // delete the pattern from the autopat list, append to @@ -1086,7 +1086,7 @@ int autocmd_register(int64_t id, event_T event, char *pat, int patlen, int group // all buffer-local patterns. if (ap->group == findgroup && ap->patlen == patlen - && STRNCMP(pat, ap->pat, patlen) == 0) { + && strncmp(pat, ap->pat, (size_t)patlen) == 0) { if (ap->next == NULL) { // Add autocmd to this autopat, if it's the last one. break; @@ -1349,7 +1349,7 @@ void ex_doautoall(exarg_T *eap) bool check_nomodeline(char **argp) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - if (STRNCMP(*argp, "<nomodeline>", 12) == 0) { + if (strncmp(*argp, "<nomodeline>", 12) == 0) { *argp = skipwhite(*argp + 12); return false; } @@ -2459,7 +2459,7 @@ bool aupat_is_buflocal(char *pat, int patlen) FUNC_ATTR_PURE { return patlen >= 8 - && STRNCMP(pat, "<buffer", 7) == 0 + && strncmp(pat, "<buffer", 7) == 0 && (pat)[patlen - 1] == '>'; } @@ -2665,7 +2665,7 @@ static int arg_augroup_get(char **argp) /// Handles grabbing arguments from `:autocmd` such as ++once and ++nested static bool arg_autocmd_flag_get(bool *flag, char **cmd_ptr, char *pattern, int len) { - if (STRNCMP(*cmd_ptr, pattern, len) == 0 && ascii_iswhite((*cmd_ptr)[len])) { + if (strncmp(*cmd_ptr, pattern, (size_t)len) == 0 && ascii_iswhite((*cmd_ptr)[len])) { if (*flag) { semsg(_(e_duparg2), pattern); return true; diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 485a6669ef..67c3307e50 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3735,8 +3735,8 @@ static int chk_modeline(linenr_T lnum, int flags) prev = -1; for (s = ml_get(lnum); *s != NUL; s++) { if (prev == -1 || ascii_isspace(prev)) { - if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) - || STRNCMP(s, "vi:", (size_t)3) == 0) { + if ((prev != -1 && strncmp(s, "ex:", (size_t)3) == 0) + || strncmp(s, "vi:", (size_t)3) == 0) { break; } // Accept both "vim" and "Vim". @@ -3752,7 +3752,7 @@ static int chk_modeline(linenr_T lnum, int flags) if (*e == ':' && (s[0] != 'V' - || STRNCMP(skipwhite((char *)e + 1), "set", 3) == 0) + || strncmp(skipwhite(e + 1), "set", 3) == 0) && (s[3] == ':' || (VIM_VERSION_100 >= vers && isdigit(s[3])) || (VIM_VERSION_100 < vers && s[3] == '<') @@ -3801,8 +3801,8 @@ static int chk_modeline(linenr_T lnum, int flags) // "vi:set opt opt opt: foo" -- foo not interpreted // "vi:opt opt opt: foo" -- foo interpreted // Accept "se" for compatibility with Elvis. - if (STRNCMP(s, "set ", (size_t)4) == 0 - || STRNCMP(s, "se ", (size_t)3) == 0) { + if (strncmp(s, "set ", (size_t)4) == 0 + || strncmp(s, "se ", (size_t)3) == 0) { if (*e != ':') { // no terminating ':'? break; } diff --git a/src/nvim/change.c b/src/nvim/change.c index d4c94a5b13..959dce6e98 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1342,7 +1342,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // the comment leader. if (dir == FORWARD) { for (p = saved_line + lead_len; *p; p++) { - if (STRNCMP(p, lead_end, n) == 0) { + if (strncmp(p, lead_end, n) == 0) { comment_end = p; lead_len = 0; break; @@ -2217,7 +2217,7 @@ int get_last_leader_offset(char *line, char **flags) // beginning the com_leader. for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) { off--; - if (!STRNCMP(string + off, com_leader, len2 - off)) { + if (!strncmp(string + off, com_leader, (size_t)(len2 - off))) { if (i - off < lower_check_bound) { lower_check_bound = i - off; } diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 037d5b4060..f1231908c7 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -457,7 +457,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m s += skip_wildmenu_char(xp, s); clen += ptr2cells((char *)s); if ((l = utfc_ptr2len((char *)s)) > 1) { - STRNCPY(buf + len, s, l); // NOLINT(runtime/printf) + strncpy((char *)buf + len, (char *)s, (size_t)l); // NOLINT(runtime/printf) s += l - 1; len += l; } else { @@ -1715,7 +1715,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons } else if (context == EXPAND_COMMANDS) { return arg; } else if (context == EXPAND_MAPPINGS) { - return (const char *)set_context_in_map_cmd(xp, "map", (char_u *)arg, forceit, + return (const char *)set_context_in_map_cmd(xp, "map", (char *)arg, forceit, false, false, CMD_map); } @@ -1754,7 +1754,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons case CMD_snoremap: case CMD_xmap: case CMD_xnoremap: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char_u *)arg, forceit, false, + return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, false, false, cmdidx); case CMD_unmap: case CMD_nunmap: @@ -1765,7 +1765,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons case CMD_lunmap: case CMD_sunmap: case CMD_xunmap: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char_u *)arg, forceit, false, + return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, false, true, cmdidx); case CMD_mapclear: case CMD_nmapclear: @@ -1786,12 +1786,12 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons case CMD_cnoreabbrev: case CMD_iabbrev: case CMD_inoreabbrev: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char_u *)arg, forceit, true, + return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, true, false, cmdidx); case CMD_unabbreviate: case CMD_cunabbrev: case CMD_iunabbrev: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char_u *)arg, forceit, true, + return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, true, true, cmdidx); case CMD_menu: case CMD_noremenu: @@ -2445,7 +2445,7 @@ static int ExpandFromContext(expand_T *xp, char *pat, int *num_file, char ***fil // When expanding a function name starting with s:, match the <SNR>nr_ // prefix. char *tofree = NULL; - if (xp->xp_context == EXPAND_USER_FUNC && STRNCMP(pat, "^s:", 3) == 0) { + if (xp->xp_context == EXPAND_USER_FUNC && strncmp(pat, "^s:", 3) == 0) { const size_t len = strlen(pat) + 20; tofree = xmalloc(len); @@ -2628,7 +2628,7 @@ static void expand_shellcmd(char *filepat, int *num_file, char ***file, int flag // Find directories in the current directory, path is empty. did_curdir = true; flags |= EW_DIR; - } else if (STRNCMP(s, ".", e - s) == 0) { + } else if (strncmp(s, ".", (size_t)(e - s)) == 0) { did_curdir = true; flags |= EW_DIR; } else { diff --git a/src/nvim/context.c b/src/nvim/context.c index 47e60373bf..b064a92b74 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -264,7 +264,7 @@ static inline void ctx_save_funcs(Context *ctx, bool scriptonly) HASHTAB_ITER(func_tbl_get(), hi, { const char *const name = hi->hi_key; - bool islambda = (STRNCMP(name, "<lambda>", 8) == 0); + bool islambda = (strncmp(name, "<lambda>", 8) == 0); bool isscript = ((uint8_t)name[0] == K_SPECIAL); if (!islambda && (!scriptonly || isscript)) { diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index aa9e2a9a82..fadb014604 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -515,18 +515,18 @@ static int dbg_parsearg(char *arg, garray_T *gap) struct debuggy *bp = &DEBUGGY(gap, gap->ga_len); // Find "func" or "file". - if (STRNCMP(p, "func", 4) == 0) { + if (strncmp(p, "func", 4) == 0) { bp->dbg_type = DBG_FUNC; - } else if (STRNCMP(p, "file", 4) == 0) { + } else if (strncmp(p, "file", 4) == 0) { bp->dbg_type = DBG_FILE; - } else if (gap != &prof_ga && STRNCMP(p, "here", 4) == 0) { + } else if (gap != &prof_ga && strncmp(p, "here", 4) == 0) { if (curbuf->b_ffname == NULL) { emsg(_(e_noname)); return FAIL; } bp->dbg_type = DBG_FILE; here = true; - } else if (gap != &prof_ga && STRNCMP(p, "expr", 4) == 0) { + } else if (gap != &prof_ga && strncmp(p, "expr", 4) == 0) { bp->dbg_type = DBG_EXPR; } else { semsg(_(e_invarg2), p); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index c28eecc76a..1ae0e91cda 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1047,8 +1047,8 @@ static int check_external_diff(diffio_T *diffio) break; } - if (STRNCMP(linebuf, "1c1", 3) == 0 - || STRNCMP(linebuf, "@@ -1 +1 @@", 11) == 0) { + if (strncmp(linebuf, "1c1", 3) == 0 + || strncmp(linebuf, "@@ -1 +1 @@", 11) == 0) { ok = kTrue; } } @@ -1573,13 +1573,13 @@ static bool extract_hunk(FILE *fd, diffhunk_T *hunk, diffstyle_T *diffstyle) // @@ -1,3 +1,5 @@ if (isdigit(*line)) { *diffstyle = DIFF_ED; - } else if ((STRNCMP(line, "@@ ", 3) == 0)) { + } else if ((strncmp(line, "@@ ", 3) == 0)) { *diffstyle = DIFF_UNIFIED; - } else if ((STRNCMP(line, "--- ", 4) == 0) // -V501 + } else if ((strncmp(line, "--- ", 4) == 0) // -V501 && (vim_fgets(line, LBUFLEN, fd) == 0) // -V501 - && (STRNCMP(line, "+++ ", 4) == 0) + && (strncmp(line, "+++ ", 4) == 0) && (vim_fgets(line, LBUFLEN, fd) == 0) // -V501 - && (STRNCMP(line, "@@ ", 3) == 0)) { + && (strncmp(line, "@@ ", 3) == 0)) { *diffstyle = DIFF_UNIFIED; } else { // Format not recognized yet, skip over this line. Cygwin diff @@ -1597,7 +1597,7 @@ static bool extract_hunk(FILE *fd, diffhunk_T *hunk, diffstyle_T *diffstyle) } } else { assert(*diffstyle == DIFF_UNIFIED); - if (STRNCMP(line, "@@ ", 3) != 0) { + if (strncmp(line, "@@ ", 3) != 0) { continue; // not the start of a diff block } if (parse_diff_unified(line, hunk) == FAIL) { @@ -2263,7 +2263,7 @@ static bool diff_equal_char(const char *const p1, const char *const p2, int *con return false; } if (l > 1) { - if (STRNCMP(p1, p2, l) != 0 + if (strncmp(p1, p2, (size_t)l) != 0 && (!(diff_flags & DIFF_ICASE) || utf_fold(utf_ptr2char(p1)) != utf_fold(utf_ptr2char(p2)))) { return false; @@ -2466,69 +2466,69 @@ int diffopt_changed(void) char *p = p_dip; while (*p != NUL) { - if (STRNCMP(p, "filler", 6) == 0) { + if (strncmp(p, "filler", 6) == 0) { p += 6; diff_flags_new |= DIFF_FILLER; - } else if ((STRNCMP(p, "context:", 8) == 0) && ascii_isdigit(p[8])) { + } else if ((strncmp(p, "context:", 8) == 0) && ascii_isdigit(p[8])) { p += 8; diff_context_new = getdigits_int(&p, false, diff_context_new); - } else if (STRNCMP(p, "iblank", 6) == 0) { + } else if (strncmp(p, "iblank", 6) == 0) { p += 6; diff_flags_new |= DIFF_IBLANK; - } else if (STRNCMP(p, "icase", 5) == 0) { + } else if (strncmp(p, "icase", 5) == 0) { p += 5; diff_flags_new |= DIFF_ICASE; - } else if (STRNCMP(p, "iwhiteall", 9) == 0) { + } else if (strncmp(p, "iwhiteall", 9) == 0) { p += 9; diff_flags_new |= DIFF_IWHITEALL; - } else if (STRNCMP(p, "iwhiteeol", 9) == 0) { + } else if (strncmp(p, "iwhiteeol", 9) == 0) { p += 9; diff_flags_new |= DIFF_IWHITEEOL; - } else if (STRNCMP(p, "iwhite", 6) == 0) { + } else if (strncmp(p, "iwhite", 6) == 0) { p += 6; diff_flags_new |= DIFF_IWHITE; - } else if (STRNCMP(p, "horizontal", 10) == 0) { + } else if (strncmp(p, "horizontal", 10) == 0) { p += 10; diff_flags_new |= DIFF_HORIZONTAL; - } else if (STRNCMP(p, "vertical", 8) == 0) { + } else if (strncmp(p, "vertical", 8) == 0) { p += 8; diff_flags_new |= DIFF_VERTICAL; - } else if ((STRNCMP(p, "foldcolumn:", 11) == 0) && ascii_isdigit(p[11])) { + } else if ((strncmp(p, "foldcolumn:", 11) == 0) && ascii_isdigit(p[11])) { p += 11; diff_foldcolumn_new = getdigits_int(&p, false, diff_foldcolumn_new); - } else if (STRNCMP(p, "hiddenoff", 9) == 0) { + } else if (strncmp(p, "hiddenoff", 9) == 0) { p += 9; diff_flags_new |= DIFF_HIDDEN_OFF; - } else if (STRNCMP(p, "closeoff", 8) == 0) { + } else if (strncmp(p, "closeoff", 8) == 0) { p += 8; diff_flags_new |= DIFF_CLOSE_OFF; - } else if (STRNCMP(p, "followwrap", 10) == 0) { + } else if (strncmp(p, "followwrap", 10) == 0) { p += 10; diff_flags_new |= DIFF_FOLLOWWRAP; - } else if (STRNCMP(p, "indent-heuristic", 16) == 0) { + } else if (strncmp(p, "indent-heuristic", 16) == 0) { p += 16; diff_indent_heuristic = XDF_INDENT_HEURISTIC; - } else if (STRNCMP(p, "internal", 8) == 0) { + } else if (strncmp(p, "internal", 8) == 0) { p += 8; diff_flags_new |= DIFF_INTERNAL; - } else if (STRNCMP(p, "algorithm:", 10) == 0) { + } else if (strncmp(p, "algorithm:", 10) == 0) { p += 10; - if (STRNCMP(p, "myers", 5) == 0) { + if (strncmp(p, "myers", 5) == 0) { p += 5; diff_algorithm_new = 0; - } else if (STRNCMP(p, "minimal", 7) == 0) { + } else if (strncmp(p, "minimal", 7) == 0) { p += 7; diff_algorithm_new = XDF_NEED_MINIMAL; - } else if (STRNCMP(p, "patience", 8) == 0) { + } else if (strncmp(p, "patience", 8) == 0) { p += 8; diff_algorithm_new = XDF_PATIENCE_DIFF; - } else if (STRNCMP(p, "histogram", 9) == 0) { + } else if (strncmp(p, "histogram", 9) == 0) { p += 9; diff_algorithm_new = XDF_HISTOGRAM_DIFF; } else { return FAIL; } - } else if ((STRNCMP(p, "linematch:", 10) == 0) && ascii_isdigit(p[10])) { + } else if ((strncmp(p, "linematch:", 10) == 0) && ascii_isdigit(p[10])) { p += 10; linematch_lines_new = getdigits_int(&p, false, linematch_lines_new); diff_flags_new |= DIFF_LINEMATCH; diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index b5704897ad..b5119ca8a2 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -2098,7 +2098,9 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, c = (uint8_t)(*p_extra); p = xmalloc((size_t)n_extra + 1); memset(p, ' ', (size_t)n_extra); - STRNCPY(p, p_extra + 1, strlen(p_extra) - 1); // NOLINT(runtime/printf) + strncpy((char *)p, // NOLINT(runtime/printf) + p_extra + 1, + (size_t)strlen(p_extra) - 1); p[n_extra] = NUL; xfree(p_extra_free); p_extra_free = p_extra = (char *)p; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 6a5f55ad79..ac2973ba68 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1469,7 +1469,7 @@ static void init_prompt(int cmdchar_todo) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; text = get_cursor_line_ptr(); - if (STRNCMP(text, prompt, strlen(prompt)) != 0) { + if (strncmp(text, prompt, strlen(prompt)) != 0) { // prompt is missing, insert it or append a line with it if (*text == NUL) { ml_replace(curbuf->b_ml.ml_line_count, prompt, true); diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 005207718b..89fda1d8f5 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2084,7 +2084,7 @@ void del_menutrans_vars(void) { hash_lock(&globvarht); HASHTAB_ITER(&globvarht, hi, { - if (STRNCMP(hi->hi_key, "menutrans_", 10) == 0) { + if (strncmp(hi->hi_key, "menutrans_", 10) == 0) { delete_var(&globvarht, hi); } }); @@ -2142,7 +2142,7 @@ char *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { hi++; } - if (STRNCMP("g:", xp->xp_pattern, 2) == 0) { + if (strncmp("g:", xp->xp_pattern, 2) == 0) { return cat_prefix_varname('g', hi->hi_key); } return hi->hi_key; @@ -3323,7 +3323,7 @@ static int eval_method(char **const arg, typval_T *const rettv, const bool evalu int len; char *name = *arg; char *lua_funcname = NULL; - if (STRNCMP(name, "v:lua.", 6) == 0) { + if (strncmp(name, "v:lua.", 6) == 0) { lua_funcname = name + 6; *arg = (char *)skip_luafunc_name((const char *)lua_funcname); *arg = skipwhite(*arg); // to detect trailing whitespace later @@ -5041,7 +5041,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) int dict_idx = 0; int arg_idx = 0; list_T *list = NULL; - if (STRNCMP(s, "s:", 2) == 0 || STRNCMP(s, "<SID>", 5) == 0) { + if (strncmp(s, "s:", 2) == 0 || strncmp(s, "<SID>", 5) == 0) { char sid_buf[25]; int off = *s == 's' ? 2 : 5; diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 67da5803d9..ebe7e0325b 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -173,7 +173,7 @@ char *get_function_name(expand_T *xp, int idx) char_u *name = (char_u *)get_user_func_name(xp, idx); if (name != NULL) { if (*name != NUL && *name != '<' - && STRNCMP("g:", xp->xp_pattern, 2) == 0) { + && strncmp("g:", xp->xp_pattern, 2) == 0) { return cat_prefix_varname('g', (char *)name); } return (char *)name; @@ -9476,7 +9476,7 @@ static void f_tr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) int fromlen; for (const char *p = fromstr; *p != NUL; p += fromlen) { fromlen = utfc_ptr2len(p); - if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) { + if (fromlen == inlen && strncmp(in_str, p, (size_t)inlen) == 0) { int tolen; for (p = tostr; *p != NUL; p += tolen) { tolen = utfc_ptr2len(p); diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 7f0ac06f60..359ce08554 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -118,8 +118,8 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int p++; } if (arg == p || isdigit(*arg) - || (p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0) - || (p - arg == 8 && STRNCMP(arg, "lastline", 8) == 0)) { + || (p - arg == 9 && strncmp(arg, "firstline", 9) == 0) + || (p - arg == 8 && strncmp(arg, "lastline", 8) == 0)) { if (!skip) { semsg(_("E125: Illegal argument: %s"), arg); } @@ -887,7 +887,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett ga_init(&fc->fc_funcs, sizeof(ufunc_T *), 1); func_ptr_ref(fp); - if (STRNCMP(fp->uf_name, "<lambda>", 8) == 0) { + if (strncmp(fp->uf_name, "<lambda>", 8) == 0) { islambda = true; } @@ -1846,7 +1846,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa if (name != NULL) { name = xstrdup(name); *pp = (char *)end; - if (STRNCMP(name, "<SNR>", 5) == 0) { + if (strncmp(name, "<SNR>", 5) == 0) { // Change "<SNR>" to the byte sequence. name[0] = (char)K_SPECIAL; name[1] = (char)KS_EXTRA; @@ -2187,16 +2187,16 @@ void ex_function(exarg_T *eap) // find extra arguments "range", "dict", "abort" and "closure" for (;;) { p = skipwhite(p); - if (STRNCMP(p, "range", 5) == 0) { + if (strncmp(p, "range", 5) == 0) { flags |= FC_RANGE; p += 5; - } else if (STRNCMP(p, "dict", 4) == 0) { + } else if (strncmp(p, "dict", 4) == 0) { flags |= FC_DICT; p += 4; - } else if (STRNCMP(p, "abort", 5) == 0) { + } else if (strncmp(p, "abort", 5) == 0) { flags |= FC_ABORT; p += 5; - } else if (STRNCMP(p, "closure", 7) == 0) { + } else if (strncmp(p, "closure", 7) == 0) { flags |= FC_CLOSURE; p += 7; if (current_funccal == NULL) { @@ -2298,7 +2298,7 @@ void ex_function(exarg_T *eap) // * ":let {var-name} =<< [trim] {marker}" and "{marker}" if (heredoc_trimmed == NULL || (is_heredoc && skipwhite(theline) == theline) - || STRNCMP(theline, heredoc_trimmed, + || strncmp(theline, heredoc_trimmed, strlen(heredoc_trimmed)) == 0) { if (heredoc_trimmed == NULL) { p = theline; @@ -2348,12 +2348,12 @@ void ex_function(exarg_T *eap) // Increase indent inside "if", "while", "for" and "try", decrease // at "end". - if (indent > 2 && STRNCMP(p, "end", 3) == 0) { + if (indent > 2 && strncmp(p, "end", 3) == 0) { indent -= 2; - } else if (STRNCMP(p, "if", 2) == 0 - || STRNCMP(p, "wh", 2) == 0 - || STRNCMP(p, "for", 3) == 0 - || STRNCMP(p, "try", 3) == 0) { + } else if (strncmp(p, "if", 2) == 0 + || strncmp(p, "wh", 2) == 0 + || strncmp(p, "for", 3) == 0 + || strncmp(p, "try", 3) == 0) { indent += 2; } @@ -2381,7 +2381,7 @@ void ex_function(exarg_T *eap) && (!ASCII_ISALPHA(p[1]) || (p[1] == 'h' && (!ASCII_ISALPHA(p[2]) || (p[2] == 'a' - && (STRNCMP(&p[3], "nge", 3) != 0 + && (strncmp(&p[3], "nge", 3) != 0 || !ASCII_ISALPHA(p[6]))))))) || (p[0] == 'i' && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n' @@ -2432,7 +2432,7 @@ void ex_function(exarg_T *eap) && (!ASCII_ISALNUM(p[2]) || (p[2] == 't' && !ASCII_ISALNUM(p[3]))))) { p = skipwhite(arg + 3); - if (STRNCMP(p, "trim", 4) == 0) { + if (strncmp(p, "trim", 4) == 0) { // Ignore leading white space. p = skipwhite(p + 4); heredoc_trimmed = xstrnsave(theline, (size_t)(skipwhite(theline) - theline)); @@ -2714,7 +2714,7 @@ char *get_user_func_name(expand_T *xp, int idx) fp = HI2UF(hi); if ((fp->uf_flags & FC_DICT) - || STRNCMP(fp->uf_name, "<lambda>", 8) == 0) { + || strncmp(fp->uf_name, "<lambda>", 8) == 0) { return ""; // don't show dict and lambda functions } diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 2d7df6fde9..a08d37511e 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -80,7 +80,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) // Check for the optional 'trim' word before the marker cmd = skipwhite(cmd); - if (STRNCMP(cmd, "trim", 4) == 0 + if (strncmp(cmd, "trim", 4) == 0 && (cmd[4] == NUL || ascii_iswhite(cmd[4]))) { cmd = skipwhite(cmd + 4); @@ -128,7 +128,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) // with "trim": skip the indent matching the :let line to find the // marker if (marker_indent_len > 0 - && STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0) { + && strncmp(theline, *eap->cmdlinep, (size_t)marker_indent_len) == 0) { mi = marker_indent_len; } if (strcmp(marker, theline + mi) == 0) { @@ -208,7 +208,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) } expr = skipwhite(argend); if (*expr != '=' && !((vim_strchr("+-*/%.", *expr) != NULL - && expr[1] == '=') || STRNCMP(expr, "..=", 3) == 0)) { + && expr[1] == '=') || strncmp(expr, "..=", 3) == 0)) { // ":let" without "=": list variables if (*arg == '[') { emsg(_(e_invarg)); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 85577b8cf3..37396a22ad 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2973,7 +2973,7 @@ char *find_ex_command(exarg_T *eap, int *full) for (; (int)eap->cmdidx < CMD_SIZE; eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) { - if (STRNCMP(cmdnames[(int)eap->cmdidx].cmd_name, eap->cmd, + if (strncmp(cmdnames[(int)eap->cmdidx].cmd_name, eap->cmd, (size_t)len) == 0) { if (full != NULL && cmdnames[(int)eap->cmdidx].cmd_name[len] == NUL) { @@ -4051,7 +4051,7 @@ static int getargopt(exarg_T *eap) int bad_char_idx; // ":edit ++[no]bin[ary] file" - if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) { + if (strncmp(arg, "bin", 3) == 0 || strncmp(arg, "nobin", 5) == 0) { if (*arg == 'n') { arg += 2; eap->force_bin = FORCE_NOBIN; @@ -4066,7 +4066,7 @@ static int getargopt(exarg_T *eap) } // ":read ++edit file" - if (STRNCMP(arg, "edit", 4) == 0) { + if (strncmp(arg, "edit", 4) == 0) { eap->read_edit = true; eap->arg = skipwhite(arg + 4); return OK; @@ -4079,20 +4079,20 @@ static int getargopt(exarg_T *eap) return OK; } - if (STRNCMP(arg, "ff", 2) == 0) { + if (strncmp(arg, "ff", 2) == 0) { arg += 2; pp = &eap->force_ff; - } else if (STRNCMP(arg, "fileformat", 10) == 0) { + } else if (strncmp(arg, "fileformat", 10) == 0) { arg += 10; pp = &eap->force_ff; - } else if (STRNCMP(arg, "enc", 3) == 0) { - if (STRNCMP(arg, "encoding", 8) == 0) { + } else if (strncmp(arg, "enc", 3) == 0) { + if (strncmp(arg, "encoding", 8) == 0) { arg += 8; } else { arg += 3; } pp = &eap->force_enc; - } else if (STRNCMP(arg, "bad", 3) == 0) { + } else if (strncmp(arg, "bad", 3) == 0) { arg += 3; pp = &bad_char_idx; } @@ -6511,7 +6511,7 @@ static void ex_findpat(exarg_T *eap) } } if (!eap->skip) { - find_pattern_in_path((char_u *)eap->arg, 0, strlen(eap->arg), whole, !eap->forceit, + find_pattern_in_path(eap->arg, 0, strlen(eap->arg), whole, !eap->forceit, *eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY, n, action, eap->line1, eap->line2); } @@ -6959,7 +6959,7 @@ char *expand_sfile(char *arg) char *result = xstrdup(arg); for (char *p = result; *p;) { - if (STRNCMP(p, "<sfile>", 7) != 0) { + if (strncmp(p, "<sfile>", 7) != 0) { p++; } else { // replace "<sfile>" with the sourced file name, and do ":" stuff @@ -7065,12 +7065,12 @@ static void ex_filetype(exarg_T *eap) // Accept "plugin" and "indent" in any order. for (;;) { - if (STRNCMP(arg, "plugin", 6) == 0) { + if (strncmp(arg, "plugin", 6) == 0) { plugin = true; arg = skipwhite(arg + 6); continue; } - if (STRNCMP(arg, "indent", 6) == 0) { + if (strncmp(arg, "indent", 6) == 0) { indent = true; arg = skipwhite(arg + 6); continue; @@ -7147,7 +7147,7 @@ static void ex_setfiletype(exarg_T *eap) if (!did_filetype) { char *arg = eap->arg; - if (STRNCMP(arg, "FALLBACK ", 9) == 0) { + if (strncmp(arg, "FALLBACK ", 9) == 0) { arg += 9; } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index db0b20036f..f696ab3900 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -254,7 +254,7 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore) // Skip the extra "Vim " prefix for message "E458". tmsg = elem->msg; - if (STRNCMP(tmsg, "Vim E", 5) == 0 + if (strncmp(tmsg, "Vim E", 5) == 0 && ascii_isdigit(tmsg[5]) && ascii_isdigit(tmsg[6]) && ascii_isdigit(tmsg[7]) @@ -448,7 +448,7 @@ static int throw_exception(void *value, except_type_T type, char *cmdname) // would be treated differently from real interrupt or error exceptions // when no active try block is found, see do_cmdline(). if (type == ET_USER) { - if (STRNCMP((char_u *)value, "Vim", 3) == 0 + if (strncmp(value, "Vim", 3) == 0 && (((char_u *)value)[3] == NUL || ((char_u *)value)[3] == ':' || ((char_u *)value)[3] == '(')) { emsg(_("E608: Cannot :throw exceptions with 'Vim' prefix")); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index fc9559172f..8d4504ca4a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -276,16 +276,16 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s goto theend; } - if (STRNCMP(cmd, "substitute", p - cmd) == 0 - || STRNCMP(cmd, "smagic", p - cmd) == 0 - || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 - || STRNCMP(cmd, "vglobal", p - cmd) == 0) { + if (strncmp(cmd, "substitute", (size_t)(p - cmd)) == 0 + || strncmp(cmd, "smagic", (size_t)(p - cmd)) == 0 + || strncmp(cmd, "snomagic", (size_t)MAX(p - cmd, 3)) == 0 + || strncmp(cmd, "vglobal", (size_t)(p - cmd)) == 0) { if (*cmd == 's' && cmd[1] == 'm') { p_magic = true; } else if (*cmd == 's' && cmd[1] == 'n') { p_magic = false; } - } else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) { + } else if (strncmp(cmd, "sort", (size_t)MAX(p - cmd, 3)) == 0) { // skip over ! and flags if (*p == '!') { p = skipwhite(p + 1); @@ -296,11 +296,11 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s if (*p == NUL) { goto theend; } - } else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 - || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 - || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 - || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 - || STRNCMP(cmd, "global", p - cmd) == 0) { + } else if (strncmp(cmd, "vimgrep", (size_t)MAX(p - cmd, 3)) == 0 + || strncmp(cmd, "vimgrepadd", (size_t)MAX(p - cmd, 8)) == 0 + || strncmp(cmd, "lvimgrep", (size_t)MAX(p - cmd, 2)) == 0 + || strncmp(cmd, "lvimgrepadd", (size_t)MAX(p - cmd, 9)) == 0 + || strncmp(cmd, "global", (size_t)(p - cmd)) == 0) { // skip over "!/". if (*p == '!') { p++; @@ -1456,7 +1456,7 @@ static void command_line_next_histidx(CommandLineState *s, bool next_match) if ((s->c != K_UP && s->c != K_DOWN) || s->hiscnt == s->save_hiscnt - || STRNCMP(get_histentry(s->histype)[s->hiscnt].hisstr, + || strncmp(get_histentry(s->histype)[s->hiscnt].hisstr, s->lookfor, (size_t)j) == 0) { break; } @@ -2573,13 +2573,13 @@ int check_opt_wim(void) if (p[i] != NUL && p[i] != ',' && p[i] != ':') { return FAIL; } - if (i == 7 && STRNCMP(p, "longest", 7) == 0) { + if (i == 7 && strncmp(p, "longest", 7) == 0) { new_wim_flags[idx] |= WIM_LONGEST; - } else if (i == 4 && STRNCMP(p, "full", 4) == 0) { + } else if (i == 4 && strncmp(p, "full", 4) == 0) { new_wim_flags[idx] |= WIM_FULL; - } else if (i == 4 && STRNCMP(p, "list", 4) == 0) { + } else if (i == 4 && strncmp(p, "list", 4) == 0) { new_wim_flags[idx] |= WIM_LIST; - } else if (i == 8 && STRNCMP(p, "lastused", 8) == 0) { + } else if (i == 8 && strncmp(p, "lastused", 8) == 0) { new_wim_flags[idx] |= WIM_BUFLASTUSED; } else { return FAIL; @@ -3580,19 +3580,19 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) // part of the word. p = (char_u *)arg; if (p_is && regname == Ctrl_W) { - char_u *w; + char *w; int len; // Locate start of last word in the cmd buffer. - for (w = (char_u *)ccline.cmdbuff + ccline.cmdpos; w > (char_u *)ccline.cmdbuff;) { - len = utf_head_off(ccline.cmdbuff, (char *)w - 1) + 1; - if (!vim_iswordc(utf_ptr2char((char *)w - len))) { + for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff;) { + len = utf_head_off(ccline.cmdbuff, w - 1) + 1; + if (!vim_iswordc(utf_ptr2char(w - len))) { break; } w -= len; } - len = (int)(((char_u *)ccline.cmdbuff + ccline.cmdpos) - w); - if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) { + len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); + if (p_ic ? STRNICMP(w, arg, len) == 0 : strncmp(w, arg, (size_t)len) == 0) { p += len; } } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 00fbcabc7e..47f2e44c39 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -400,7 +400,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i emsg(_(e_pathtoolong)); break; } - if (STRNCMP(wc_part, "**", 2) == 0) { + if (strncmp(wc_part, "**", 2) == 0) { ff_expand_buffer[len++] = *wc_part++; ff_expand_buffer[len++] = *wc_part++; @@ -463,7 +463,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i if (p > search_ctx->ffsc_fix_path) { // do not add '..' to the path and start upwards searching len = (int)(p - search_ctx->ffsc_fix_path) - 1; - if ((len >= 2 && STRNCMP(search_ctx->ffsc_fix_path, "..", 2) == 0) + if ((len >= 2 && strncmp(search_ctx->ffsc_fix_path, "..", 2) == 0) && (len == 2 || search_ctx->ffsc_fix_path[2] == PATHSEP)) { xfree(buf); goto error_return; @@ -681,7 +681,7 @@ char_u *vim_findfile(void *search_ctx_arg) rest_of_wildcards = stackp->ffs_wc_path; if (*rest_of_wildcards != NUL) { len = strlen(file_path); - if (STRNCMP(rest_of_wildcards, "**", 2) == 0) { + if (strncmp(rest_of_wildcards, "**", 2) == 0) { // pointer to the restrict byte // The restrict byte is not a character! p = rest_of_wildcards + 2; @@ -858,7 +858,7 @@ char_u *vim_findfile(void *search_ctx_arg) // if wildcards contains '**' we have to descent till we reach the // leaves of the directory tree. - if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) { + if (strncmp(stackp->ffs_wc_path, "**", 2) == 0) { for (int i = stackp->ffs_filearray_cur; i < stackp->ffs_filearray_size; i++) { if (path_fnamecmp(stackp->ffs_filearray[i], diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 746788413f..2bff0fa2f9 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1939,7 +1939,7 @@ failed: bool is_dev_fd_file(char *fname) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - return STRNCMP(fname, "/dev/fd/", 8) == 0 + return strncmp(fname, "/dev/fd/", 8) == 0 && ascii_isdigit((uint8_t)fname[8]) && *skipdigits(fname + 9) == NUL && (fname[9] != NUL @@ -4090,7 +4090,7 @@ static int get_fio_flags(const char_u *name) if (*name == NUL) { name = (char_u *)p_enc; } - prop = enc_canon_props(name); + prop = enc_canon_props((char *)name); if (prop & ENC_UNICODE) { if (prop & ENC_2BYTE) { if (prop & ENC_ENDIAN_L) { diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 940c26ad02..1ff39f3654 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1653,7 +1653,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t marker char *cms = buf->b_p_cms; char *line = ml_get_buf(buf, lnum, false); for (char *p = line; *p != NUL; p++) { - if (STRNCMP(p, marker, markerlen) != 0) { + if (strncmp(p, marker, markerlen) != 0) { continue; } // Found the marker, include a digit if it's there. @@ -1665,8 +1665,8 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t marker // Also delete 'commentstring' if it matches. char *cms2 = strstr(cms, "%s"); if (p - line >= cms2 - cms - && STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0 - && STRNCMP(p + len, cms2 + 2, strlen(cms2 + 2)) == 0) { + && strncmp(p - (cms2 - cms), cms, (size_t)(cms2 - cms)) == 0 + && strncmp(p + len, cms2 + 2, strlen(cms2 + 2)) == 0) { p -= cms2 - cms; len += strlen(cms) - 2; } @@ -1829,9 +1829,9 @@ static void foldtext_cleanup(char *str) for (char *s = str; *s != NUL;) { size_t len = 0; - if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0) { + if (strncmp(s, curwin->w_p_fmr, foldstartmarkerlen) == 0) { len = foldstartmarkerlen; - } else if (STRNCMP(s, foldendmarker, foldendmarkerlen) == 0) { + } else if (strncmp(s, foldendmarker, foldendmarkerlen) == 0) { len = foldendmarkerlen; } if (len > 0) { @@ -1844,16 +1844,16 @@ static void foldtext_cleanup(char *str) char *p; for (p = s; p > str && ascii_iswhite(p[-1]); p--) {} if (p >= str + cms_slen - && STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) { + && strncmp(p - cms_slen, cms_start, cms_slen) == 0) { len += (size_t)(s - p) + cms_slen; s = p - cms_slen; } } else if (cms_end != NULL) { - if (!did1 && cms_slen > 0 && STRNCMP(s, cms_start, cms_slen) == 0) { + if (!did1 && cms_slen > 0 && strncmp(s, cms_start, cms_slen) == 0) { len = cms_slen; did1 = true; } else if (!did2 && cms_elen > 0 - && STRNCMP(s, cms_end, cms_elen) == 0) { + && strncmp(s, cms_end, cms_elen) == 0) { len = cms_elen; did2 = true; } @@ -3024,7 +3024,7 @@ static void foldlevelMarker(fline_T *flp) char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); while (*s) { if (*s == cstart - && STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { + && strncmp(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { // found startmarker: set flp->lvl s += foldstartmarkerlen; if (ascii_isdigit(*s)) { @@ -3044,7 +3044,7 @@ static void foldlevelMarker(fline_T *flp) flp->start++; } } else if (*s == cend - && STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) { + && strncmp(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) { // found endmarker: set flp->lvl_next s += foldendmarkerlen; if (ascii_isdigit(*s)) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index bd83624185..680ef2f29b 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2266,7 +2266,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) if (save_m_noremap != REMAP_YES) { noremap = save_m_noremap; - } else if (STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : (char *)mp->m_keys, + } else if (strncmp(map_str, save_m_keys != NULL ? save_m_keys : (char *)mp->m_keys, (size_t)keylen) != 0) { noremap = REMAP_YES; } else { diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 93976542f7..0cfe77b530 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -2090,7 +2090,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) // encoding other than Unicode. This is because a Unicode encoding does not // uniquely identify a CJK character set to use. p_mbenc = NULL; - props = enc_canon_props(p_encoding); + props = enc_canon_props((char *)p_encoding); if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) { p_mbenc_first = NULL; int effective_cmap = 0; @@ -2508,7 +2508,7 @@ bool mch_print_begin(prt_settings_T *psettings) int props; p_encoding = enc_skip(p_enc); - props = enc_canon_props((char_u *)p_encoding); + props = enc_canon_props(p_encoding); if (!(props & ENC_8BIT) || !prt_find_resource(p_encoding, &res_encoding)) { // 8-bit 'encoding' is not supported @@ -2547,7 +2547,7 @@ bool mch_print_begin(prt_settings_T *psettings) } prt_conv.vc_type = CONV_NONE; - if (!(enc_canon_props((char_u *)p_enc) & enc_canon_props((char_u *)p_encoding) & ENC_8BIT)) { + if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { // Set up encoding conversion if required if (convert_setup(&prt_conv, p_enc, p_encoding) == FAIL) { semsg(_("E620: Unable to convert to print encoding \"%s\""), diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index e3a5f40492..31dc6f5bd4 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -140,7 +140,7 @@ hashitem_T *hash_lookup(const hashtab_T *const ht, const char *const key, const if (hi->hi_key == HI_KEY_REMOVED) { freeitem = hi; } else if ((hi->hi_hash == hash) - && (STRNCMP(hi->hi_key, key, key_len) == 0) + && (strncmp(hi->hi_key, key, key_len) == 0) && hi->hi_key[key_len] == NUL) { return hi; } @@ -166,7 +166,7 @@ hashitem_T *hash_lookup(const hashtab_T *const ht, const char *const key, const if ((hi->hi_hash == hash) && (hi->hi_key != HI_KEY_REMOVED) - && (STRNCMP(hi->hi_key, key, key_len) == 0) + && (strncmp(hi->hi_key, key, key_len) == 0) && hi->hi_key[key_len] == NUL) { return hi; } diff --git a/src/nvim/help.c b/src/nvim/help.c index 8930f74e7f..cdd930203f 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -591,7 +591,7 @@ void cleanup_help_tags(int num_file, char **file) for (j = 0; j < num_file; j++) { if (j != i && (int)strlen(file[j]) == len + 3 - && STRNCMP(file[i], file[j], len + 1) == 0) { + && strncmp(file[i], file[j], (size_t)len + 1) == 0) { break; } } @@ -1041,7 +1041,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool // Write the tags into the file. for (int i = 0; i < ga.ga_len; i++) { s = ((char **)ga.ga_data)[i]; - if (STRNCMP(s, "help-tags\t", 10) == 0) { + if (strncmp(s, "help-tags\t", 10) == 0) { // help-tags entry was added in formatted form fputs(s, fd_tags); } else { @@ -1122,7 +1122,7 @@ static void do_helptags(char *dirname, bool add_help_tags, bool ignore_writeerr) // Did we find this language already? for (j = 0; j < ga.ga_len; j += 2) { - if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) { + if (strncmp(lang, ((char *)ga.ga_data) + j, 2) == 0) { break; } } @@ -1170,7 +1170,7 @@ void ex_helptags(exarg_T *eap) bool add_help_tags = false; // Check for ":helptags ++t {dir}". - if (STRNCMP(eap->arg, "++t", 3) == 0 && ascii_iswhite(eap->arg[3])) { + if (strncmp(eap->arg, "++t", 3) == 0 && ascii_iswhite(eap->arg[3])) { add_help_tags = true; eap->arg = skipwhite(eap->arg + 3); } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 062e073156..1905128c3c 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -756,20 +756,20 @@ bool briopt_check(win_T *wp) char *p = wp->w_p_briopt; while (*p != NUL) { - if (STRNCMP(p, "shift:", 6) == 0 + if (strncmp(p, "shift:", 6) == 0 && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) { p += 6; bri_shift = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { + } else if (strncmp(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { p += 4; bri_min = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "sbr", 3) == 0) { + } else if (strncmp(p, "sbr", 3) == 0) { p += 3; bri_sbr = true; - } else if (STRNCMP(p, "list:", 5) == 0) { + } else if (strncmp(p, "list:", 5) == 0) { p += 5; bri_list = (int)getdigits(&p, false, 0); - } else if (STRNCMP(p, "column:", 7) == 0) { + } else if (strncmp(p, "column:", 7) == 0) { p += 7; bri_vcol = (int)getdigits(&p, false, 0); } @@ -1091,7 +1091,7 @@ int get_lisp_indent(void) // (let ((a 1)) instead (let ((a 1)) // (...)) of (...)) if (!vi_lisp && ((*that == '(') || (*that == '[')) - && lisp_match(that + 1)) { + && lisp_match((char *)that + 1)) { amount += 2; } else { if (*that != NUL) { @@ -1169,7 +1169,7 @@ int get_lisp_indent(void) return amount; } -static int lisp_match(char_u *p) +static int lisp_match(char *p) { char buf[LSIZE]; int len; @@ -1179,7 +1179,7 @@ static int lisp_match(char_u *p) (void)copy_option_part(&word, buf, LSIZE, ","); len = (int)strlen(buf); - if ((STRNCMP(buf, p, len) == 0) && ascii_iswhite_or_nul(p[len])) { + if ((strncmp(buf, p, (size_t)len) == 0) && ascii_iswhite_or_nul(p[len])) { return true; } } diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 65380b92fc..625e48258c 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -801,7 +801,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons match = compl_first_match; do { if (!match_at_original_text(match) - && STRNCMP(match->cp_str, str, len) == 0 + && strncmp(match->cp_str, str, (size_t)len) == 0 && ((int)strlen(match->cp_str) <= len || match->cp_str[len] == NUL)) { FREE_CPTEXT(cptext, cptext_allocated); return NOTDONE; @@ -2935,7 +2935,7 @@ done: /// included files. static void get_next_include_file_completion(int compl_type) { - find_pattern_in_path((char_u *)compl_pattern, compl_direction, + find_pattern_in_path(compl_pattern, compl_direction, strlen(compl_pattern), false, false, ((compl_type == CTRL_X_PATH_DEFINES && !(compl_cont_status & CONT_SOL)) @@ -3080,8 +3080,8 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p if (cur_match_pos->lnum < ins_buf->b_ml.ml_line_count) { // Try next line, if any. the new word will be "join" as if the // normal command "J" was used. IOSIZE is always greater than - // compl_length, so the next STRNCPY always works -- Acevedo - STRNCPY(IObuff, ptr, len); // NOLINT(runtime/printf) + // compl_length, so the next strncpy always works -- Acevedo + strncpy(IObuff, ptr, (size_t)len); // NOLINT(runtime/printf) ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); tmp_ptr = ptr = skipwhite(ptr); // Find start of next word. @@ -3159,7 +3159,7 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_ // has added a word that was at the beginning of the line. if (ctrl_x_mode_line_or_eval() || (compl_cont_status & CONT_SOL)) { found_new_match = search_for_exact_line(st->ins_buf, st->cur_match_pos, - compl_direction, (char_u *)compl_pattern); + compl_direction, compl_pattern); } else { found_new_match = searchit(NULL, st->ins_buf, st->cur_match_pos, NULL, compl_direction, (char_u *)compl_pattern, 1L, diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index cc8ebe10cf..07f6a211e4 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -346,51 +346,51 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len /// @return 0 on success, 1 if invalid arguments are detected. static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *mapargs) { - const char_u *to_parse = strargs; - to_parse = (char_u *)skipwhite((char *)to_parse); + const char *to_parse = (char *)strargs; + to_parse = skipwhite((char *)to_parse); CLEAR_POINTER(mapargs); // Accept <buffer>, <nowait>, <silent>, <expr>, <script>, and <unique> in // any order. while (true) { - if (STRNCMP(to_parse, "<buffer>", 8) == 0) { - to_parse = (char_u *)skipwhite((char *)to_parse + 8); + if (strncmp(to_parse, "<buffer>", 8) == 0) { + to_parse = skipwhite((char *)to_parse + 8); mapargs->buffer = true; continue; } - if (STRNCMP(to_parse, "<nowait>", 8) == 0) { - to_parse = (char_u *)skipwhite((char *)to_parse + 8); + if (strncmp(to_parse, "<nowait>", 8) == 0) { + to_parse = skipwhite((char *)to_parse + 8); mapargs->nowait = true; continue; } - if (STRNCMP(to_parse, "<silent>", 8) == 0) { - to_parse = (char_u *)skipwhite((char *)to_parse + 8); + if (strncmp(to_parse, "<silent>", 8) == 0) { + to_parse = skipwhite((char *)to_parse + 8); mapargs->silent = true; continue; } // Ignore obsolete "<special>" modifier. - if (STRNCMP(to_parse, "<special>", 9) == 0) { - to_parse = (char_u *)skipwhite((char *)to_parse + 9); + if (strncmp(to_parse, "<special>", 9) == 0) { + to_parse = skipwhite((char *)to_parse + 9); continue; } - if (STRNCMP(to_parse, "<script>", 8) == 0) { - to_parse = (char_u *)skipwhite((char *)to_parse + 8); + if (strncmp(to_parse, "<script>", 8) == 0) { + to_parse = skipwhite((char *)to_parse + 8); mapargs->script = true; continue; } - if (STRNCMP(to_parse, "<expr>", 6) == 0) { - to_parse = (char_u *)skipwhite((char *)to_parse + 6); + if (strncmp(to_parse, "<expr>", 6) == 0) { + to_parse = skipwhite((char *)to_parse + 6); mapargs->expr = true; continue; } - if (STRNCMP(to_parse, "<unique>", 8) == 0) { - to_parse = (char_u *)skipwhite((char *)to_parse + 8); + if (strncmp(to_parse, "<unique>", 8) == 0) { + to_parse = skipwhite((char *)to_parse + 8); mapargs->unique = true; continue; } @@ -423,7 +423,7 @@ static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *ma // Given {lhs} might be larger than MAXMAPLEN before replace_termcodes // (e.g. "<Space>" is longer than ' '), so first copy into a buffer. - size_t orig_lhs_len = (size_t)((char_u *)lhs_end - to_parse); + size_t orig_lhs_len = (size_t)(lhs_end - to_parse); if (orig_lhs_len >= 256) { return 1; } @@ -1209,7 +1209,7 @@ static char_u *translate_mapping(char_u *str, int cpo_flags) /// @param forceit true if '!' given /// @param isabbrev true if abbreviation /// @param isunmap true if unmap/unabbrev command -char_u *set_context_in_map_cmd(expand_T *xp, char *cmd, char_u *arg, bool forceit, bool isabbrev, +char_u *set_context_in_map_cmd(expand_T *xp, char *cmd, char *arg, bool forceit, bool isabbrev, bool isunmap, cmdidx_T cmdidx) { if (forceit && cmdidx != CMD_map && cmdidx != CMD_unmap) { @@ -1227,38 +1227,38 @@ char_u *set_context_in_map_cmd(expand_T *xp, char *cmd, char_u *arg, bool forcei xp->xp_context = EXPAND_MAPPINGS; expand_buffer = false; for (;;) { - if (STRNCMP(arg, "<buffer>", 8) == 0) { + if (strncmp(arg, "<buffer>", 8) == 0) { expand_buffer = true; - arg = (char_u *)skipwhite((char *)arg + 8); + arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<unique>", 8) == 0) { - arg = (char_u *)skipwhite((char *)arg + 8); + if (strncmp(arg, "<unique>", 8) == 0) { + arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<nowait>", 8) == 0) { - arg = (char_u *)skipwhite((char *)arg + 8); + if (strncmp(arg, "<nowait>", 8) == 0) { + arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<silent>", 8) == 0) { - arg = (char_u *)skipwhite((char *)arg + 8); + if (strncmp(arg, "<silent>", 8) == 0) { + arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<special>", 9) == 0) { - arg = (char_u *)skipwhite((char *)arg + 9); + if (strncmp(arg, "<special>", 9) == 0) { + arg = skipwhite(arg + 9); continue; } - if (STRNCMP(arg, "<script>", 8) == 0) { - arg = (char_u *)skipwhite((char *)arg + 8); + if (strncmp(arg, "<script>", 8) == 0) { + arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<expr>", 6) == 0) { - arg = (char_u *)skipwhite((char *)arg + 6); + if (strncmp(arg, "<expr>", 6) == 0) { + arg = skipwhite(arg + 6); continue; } break; } - xp->xp_pattern = (char *)arg; + xp->xp_pattern = arg; } return NULL; @@ -2548,7 +2548,7 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod } int mode_val; // integer value of the mapping mode, to be passed to do_map() char *p = (mode.size) ? mode.data : "m"; - if (STRNCMP(p, "!", 2) == 0) { + if (strncmp(p, "!", 2) == 0) { mode_val = get_map_mode(&p, true); // mapmode-ic } else { mode_val = get_map_mode(&p, false); diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index c7734e45e7..f48955c904 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -367,15 +367,15 @@ static int enc_canon_search(const char *name) // Find canonical encoding "name" in the list and return its properties. // Returns 0 if not found. -int enc_canon_props(const char_u *name) +int enc_canon_props(const char *name) FUNC_ATTR_PURE { int i = enc_canon_search((char *)name); if (i >= 0) { return enc_canon_table[i].prop; - } else if (STRNCMP(name, "2byte-", 6) == 0) { + } else if (strncmp(name, "2byte-", 6) == 0) { return ENC_DBCS; - } else if (STRNCMP(name, "8bit-", 5) == 0 || STRNCMP(name, "iso-8859-", 9) == 0) { + } else if (strncmp(name, "8bit-", 5) == 0 || strncmp(name, "iso-8859-", 9) == 0) { return ENC_8BIT; } return 0; @@ -395,10 +395,10 @@ int bomb_size(void) if (*curbuf->b_p_fenc == NUL || strcmp(curbuf->b_p_fenc, "utf-8") == 0) { n = 3; - } else if (STRNCMP(curbuf->b_p_fenc, "ucs-2", 5) == 0 - || STRNCMP(curbuf->b_p_fenc, "utf-16", 6) == 0) { + } else if (strncmp(curbuf->b_p_fenc, "ucs-2", 5) == 0 + || strncmp(curbuf->b_p_fenc, "utf-16", 6) == 0) { n = 2; - } else if (STRNCMP(curbuf->b_p_fenc, "ucs-4", 5) == 0) { + } else if (strncmp(curbuf->b_p_fenc, "ucs-4", 5) == 0) { n = 4; } } @@ -1888,7 +1888,7 @@ void utf_find_illegal(void) char_u *tofree = NULL; vimconv.vc_type = CONV_NONE; - if (enc_canon_props((char_u *)curbuf->b_p_fenc) & ENC_8BIT) { + if (enc_canon_props(curbuf->b_p_fenc) & ENC_8BIT) { // 'encoding' is "utf-8" but we are editing a 8-bit encoded file, // possibly a utf-8 file with illegal bytes. Setup for conversion // from utf-8 to 'fileencoding'. @@ -2103,10 +2103,10 @@ const char *mb_unescape(const char **const pp) /// Skip the Vim specific head of a 'encoding' name. char *enc_skip(char *p) { - if (STRNCMP(p, "2byte-", 6) == 0) { + if (strncmp(p, "2byte-", 6) == 0) { return p + 6; } - if (STRNCMP(p, "8bit-", 5) == 0) { + if (strncmp(p, "8bit-", 5) == 0) { return p + 5; } return p; @@ -2143,24 +2143,24 @@ char *enc_canonize(char *enc) p = enc_skip(r); // Change "microsoft-cp" to "cp". Used in some spell files. - if (STRNCMP(p, "microsoft-cp", 12) == 0) { + if (strncmp(p, "microsoft-cp", 12) == 0) { STRMOVE(p, p + 10); } // "iso8859" -> "iso-8859" - if (STRNCMP(p, "iso8859", 7) == 0) { + 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 && p[8] != '-') { + if (strncmp(p, "iso-8859", 8) == 0 && p[8] != '-') { STRMOVE(p + 9, p + 8); p[8] = '-'; } // "latin-N" -> "latinN" - if (STRNCMP(p, "latin-", 6) == 0) { + if (strncmp(p, "latin-", 6) == 0) { STRMOVE(p + 5, p + 6); } @@ -2423,8 +2423,8 @@ int convert_setup_ext(vimconv_T *vcp, char *from, bool from_unicode_is_utf8, cha return OK; } - from_prop = enc_canon_props((char_u *)from); - to_prop = enc_canon_props((char_u *)to); + from_prop = enc_canon_props(from); + to_prop = enc_canon_props(to); if (from_unicode_is_utf8) { from_is_utf8 = from_prop & ENC_UNICODE; } else { diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 3cdeef4f47..cc915f1403 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -179,19 +179,19 @@ enum { // different machines. b0_magic_* is used to check the byte order and size of // variables, because the rest of the swap file is not portable. struct block0 { - char_u b0_id[2]; ///< ID for block 0: BLOCK0_ID0 and BLOCK0_ID1. - char_u b0_version[10]; // Vim version string - char_u b0_page_size[4]; // number of bytes per page - char_u b0_mtime[4]; // last modification time of file - char_u b0_ino[4]; // inode of b0_fname - char_u b0_pid[4]; // process id of creator (or 0) - char_u b0_uname[B0_UNAME_SIZE]; // name of user (uid if no name) - char_u b0_hname[B0_HNAME_SIZE]; // host name (if it has a name) - char b0_fname[B0_FNAME_SIZE_ORG]; // name of file being edited - long b0_magic_long; // check for byte order of long - int b0_magic_int; // check for byte order of int - int16_t b0_magic_short; // check for byte order of short - char_u b0_magic_char; // check for last char + char_u b0_id[2]; ///< ID for block 0: BLOCK0_ID0 and BLOCK0_ID1. + char b0_version[10]; // Vim version string + char_u b0_page_size[4]; // number of bytes per page + char_u b0_mtime[4]; // last modification time of file + char_u b0_ino[4]; // inode of b0_fname + char_u b0_pid[4]; // process id of creator (or 0) + char_u b0_uname[B0_UNAME_SIZE]; // name of user (uid if no name) + char_u b0_hname[B0_HNAME_SIZE]; // host name (if it has a name) + char b0_fname[B0_FNAME_SIZE_ORG]; // name of file being edited + long b0_magic_long; // check for byte order of long + int b0_magic_int; // check for byte order of int + int16_t b0_magic_short; // check for byte order of short + char_u b0_magic_char; // check for last char }; // Note: b0_dirty and b0_flags are put at the end of the file name. For very @@ -297,7 +297,7 @@ int ml_open(buf_T *buf) b0p->b0_magic_int = B0_MAGIC_INT; b0p->b0_magic_short = (int16_t)B0_MAGIC_SHORT; b0p->b0_magic_char = B0_MAGIC_CHAR; - xstrlcpy(xstpcpy((char *)b0p->b0_version, "VIM "), Version, 6); + xstrlcpy(xstpcpy(b0p->b0_version, "VIM "), Version, 6); long_to_char((long)mfp->mf_page_size, b0p->b0_page_size); if (!buf->b_spell) { @@ -828,7 +828,7 @@ void ml_recover(bool checkext) goto theend; } b0p = hp->bh_data; - if (STRNCMP(b0p->b0_version, "VIM 3.0", 7) == 0) { + if (strncmp(b0p->b0_version, "VIM 3.0", 7) == 0) { msg_start(); msg_outtrans_attr(mfp->mf_fname, MSG_HIST); msg_puts_attr(_(" cannot be used with this version of Vim.\n"), @@ -1410,7 +1410,7 @@ void get_b0_dict(const char *fname, dict_T *d) tv_dict_add_str(d, S_LEN("error"), "Magic number mismatch"); } else { // We have swap information. - tv_dict_add_str_len(d, S_LEN("version"), (char *)b0.b0_version, 10); + tv_dict_add_str_len(d, S_LEN("version"), b0.b0_version, 10); tv_dict_add_str_len(d, S_LEN("user"), (char *)b0.b0_uname, B0_UNAME_SIZE); tv_dict_add_str_len(d, S_LEN("host"), (char *)b0.b0_hname, @@ -1469,7 +1469,7 @@ static time_t swapfile_info(char_u *fname) fd = os_open((char *)fname, O_RDONLY, 0); if (fd >= 0) { if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0)) { - if (STRNCMP(b0.b0_version, "VIM 3.0", 7) == 0) { + if (strncmp(b0.b0_version, "VIM 3.0", 7) == 0) { msg_puts(_(" [from Vim version 3.0]")); } else if (ml_check_b0_id(&b0) == FAIL) { msg_puts(_(" [does not look like a Vim swap file]")); diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 7d16ab01d0..e6987d6149 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -56,7 +56,7 @@ static char e_nomenu[] = N_("E329: No menu \"%s\""); static bool menu_is_winbar(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return (STRNCMP(name, "WinBar", 6) == 0); + return (strncmp(name, "WinBar", 6) == 0); } static vimmenu_T **get_root_menu(const char *const name) @@ -88,17 +88,17 @@ void ex_menu(exarg_T *eap) arg = eap->arg; for (;;) { - if (STRNCMP(arg, "<script>", 8) == 0) { + if (strncmp(arg, "<script>", 8) == 0) { noremap = REMAP_SCRIPT; arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<silent>", 8) == 0) { + if (strncmp(arg, "<silent>", 8) == 0) { silent = true; arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<special>", 9) == 0) { + if (strncmp(arg, "<special>", 9) == 0) { // Ignore obsolete "<special>" modifier. arg = skipwhite(arg + 9); continue; @@ -108,7 +108,7 @@ void ex_menu(exarg_T *eap) // Locate an optional "icon=filename" argument // TODO(nvim): Currently this is only parsed. Should expose it to UIs. - if (STRNCMP(arg, "icon=", 5) == 0) { + if (strncmp(arg, "icon=", 5) == 0) { arg += 5; while (*arg != NUL && *arg != ' ') { if (*arg == '\\') { @@ -151,10 +151,10 @@ void ex_menu(exarg_T *eap) pri_tab[MENUDEPTH] = -1; // mark end of the table // Check for "disable" or "enable" argument. - if (STRNCMP(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) { + if (strncmp(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) { enable = kTrue; arg = skipwhite(arg + 6); - } else if (STRNCMP(arg, "disable", 7) == 0 && ascii_iswhite(arg[7])) { + } else if (strncmp(arg, "disable", 7) == 0 && ascii_iswhite(arg[7])) { enable = kFalse; arg = skipwhite(arg + 7); } @@ -916,10 +916,10 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for } if (!ascii_iswhite(*p)) { - if (STRNCMP(arg, "enable", 6) == 0 + if (strncmp(arg, "enable", 6) == 0 && (arg[6] == NUL || ascii_iswhite(arg[6]))) { p = arg + 6; - } else if (STRNCMP(arg, "disable", 7) == 0 + } else if (strncmp(arg, "disable", 7) == 0 && (arg[7] == NUL || ascii_iswhite(arg[7]))) { p = arg + 7; } else { @@ -1361,14 +1361,14 @@ bool menu_is_menubar(const char *const name) bool menu_is_popup(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return STRNCMP(name, "PopUp", 5) == 0; + return strncmp(name, "PopUp", 5) == 0; } // Return true if "name" is a toolbar menu name. bool menu_is_toolbar(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return STRNCMP(name, "ToolBar", 7) == 0; + return strncmp(name, "ToolBar", 7) == 0; } /// Return true if the name is a menu separator identifier: Starts and ends @@ -1443,7 +1443,7 @@ void show_popupmenu(void) vimmenu_T *menu; for (menu = root_menu; menu != NULL; menu = menu->next) { - if (STRNCMP("PopUp", menu->name, 5) == 0 && STRNCMP(menu->name + 5, mode, mode_len) == 0) { + if (strncmp("PopUp", menu->name, 5) == 0 && strncmp(menu->name + 5, mode, mode_len) == 0) { break; } } @@ -1727,7 +1727,7 @@ void ex_menutranslate(exarg_T *eap) } // ":menutrans clear": clear all translations. - if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) { + if (strncmp(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) { GA_DEEP_CLEAR(&menutrans_ga, menutrans_T, FREE_MENUTRANS); // Delete all "menutrans_" global variables. diff --git a/src/nvim/message.c b/src/nvim/message.c index 8116ffa77b..81adca8b1c 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -2150,7 +2150,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) msg_ext_last_attr = attr; } // Concat pieces with the same highlight - size_t len = STRNLEN(str, maxlen); // -V781 + size_t len = strnlen(str, (size_t)maxlen); // -V781 ga_concat_len(&msg_ext_last_chunk, (char *)str, len); msg_ext_cur_len += len; return; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index a0f8a3b667..44df917de6 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4217,7 +4217,7 @@ static void nv_brackets(cmdarg_T *cap) } else { // Make a copy, if the line was changed it will be freed. ptr = xstrnsave(ptr, len); - find_pattern_in_path((char_u *)ptr, 0, len, true, + find_pattern_in_path(ptr, 0, len, true, cap->count0 == 0 ? !isupper(cap->nchar) : false, (((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 0cae0e854f..d2dba41959 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1080,7 +1080,7 @@ static char_u *execreg_line_continuation(char **lines, size_t *idx) /// @return FAIL for failure, OK otherwise int do_execreg(int regname, int colon, int addcr, int silent) { - char_u *p; + char *p; int retval = OK; if (regname == '@') { // repeat previous one @@ -1109,34 +1109,34 @@ int do_execreg(int regname, int colon, int addcr, int silent) // don't keep the cmdline containing @: XFREE_CLEAR(new_last_cmdline); // Escape all control characters with a CTRL-V - p = vim_strsave_escaped_ext((char_u *)last_cmdline, - (char_u *)"\001\002\003\004\005\006\007" - "\010\011\012\013\014\015\016\017" - "\020\021\022\023\024\025\026\027" - "\030\031\032\033\034\035\036\037", - Ctrl_V, false); + p = (char *)vim_strsave_escaped_ext((char_u *)last_cmdline, + (char_u *)"\001\002\003\004\005\006\007" + "\010\011\012\013\014\015\016\017" + "\020\021\022\023\024\025\026\027" + "\030\031\032\033\034\035\036\037", + Ctrl_V, false); // When in Visual mode "'<,'>" will be prepended to the command. // Remove it when it's already there. - if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) { - retval = put_in_typebuf(p + 5, true, true, silent); + if (VIsual_active && strncmp(p, "'<,'>", 5) == 0) { + retval = put_in_typebuf((char_u *)p + 5, true, true, silent); } else { - retval = put_in_typebuf(p, true, true, silent); + retval = put_in_typebuf((char_u *)p, true, true, silent); } xfree(p); } else if (regname == '=') { - p = (char_u *)get_expr_line(); + p = get_expr_line(); if (p == NULL) { return FAIL; } - retval = put_in_typebuf(p, true, colon, silent); + retval = put_in_typebuf((char_u *)p, true, colon, silent); xfree(p); } else if (regname == '.') { // use last inserted text - p = get_last_insert_save(); + p = (char *)get_last_insert_save(); if (p == NULL) { emsg(_(e_noinstext)); return FAIL; } - retval = put_in_typebuf(p, false, colon, silent); + retval = put_in_typebuf((char_u *)p, false, colon, silent); xfree(p); } else { yankreg_T *reg = get_yank_register(regname, YREG_PASTE); @@ -1162,7 +1162,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) char_u *str = (char_u *)reg->y_array[i]; bool free_str = false; if (colon && i > 0) { - p = (char_u *)skipwhite((char *)str); + p = skipwhite((char *)str); if (*p == '\\' || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')) { str = execreg_line_continuation(reg->y_array, &i); free_str = true; diff --git a/src/nvim/option.c b/src/nvim/option.c index efeeac2968..e67bacce61 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -539,7 +539,7 @@ static char *find_dup_item(char *origval, const char *newval, uint32_t flags) const size_t newlen = strlen(newval); for (char *s = origval; *s != NUL; s++) { if ((!(flags & P_COMMA) || s == origval || (s[-1] == ',' && !(bs & 1))) - && STRNCMP(s, newval, newlen) == 0 + && strncmp(s, newval, newlen) == 0 && (!(flags & P_COMMA) || s[newlen] == ',' || s[newlen] == NUL)) { return s; } @@ -1144,7 +1144,7 @@ int do_set(char *arg, int opt_flags) errmsg = NULL; startarg = arg; // remember for error message - if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) + if (strncmp(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) { // ":set all" show all options. // ":set all&" set all options to their default value. @@ -1163,10 +1163,10 @@ int do_set(char *arg, int opt_flags) } } else { prefix = 1; - if (STRNCMP(arg, "no", 2) == 0) { + if (strncmp(arg, "no", 2) == 0) { prefix = 0; arg += 2; - } else if (STRNCMP(arg, "inv", 3) == 0) { + } else if (strncmp(arg, "inv", 3) == 0) { prefix = 2; arg += 3; } @@ -2714,7 +2714,7 @@ int findoption_len(const char *const arg, const size_t len) opt_idx = -1; } else { // Nvim: handle option aliases. - if (STRNCMP(options[opt_idx].fullname, "viminfo", 7) == 0) { + if (strncmp(options[opt_idx].fullname, "viminfo", 7) == 0) { if (strlen(options[opt_idx].fullname) == 7) { return findoption_len("shada", 5); } @@ -4602,11 +4602,11 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) } p--; } - if (STRNCMP(p, "no", 2) == 0) { + if (strncmp(p, "no", 2) == 0) { xp->xp_context = EXPAND_BOOL_SETTINGS; p += 2; } - if (STRNCMP(p, "inv", 3) == 0) { + if (strncmp(p, "inv", 3) == 0) { xp->xp_context = EXPAND_BOOL_SETTINGS; p += 3; } @@ -4734,7 +4734,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) // for 'spellsuggest' start at "file:" if (options[opt_idx].var == (char_u *)&p_sps - && STRNCMP(p, "file:", 5) == 0) { + && strncmp(p, "file:", 5) == 0) { xp->xp_pattern = p + 5; break; } @@ -5116,16 +5116,16 @@ int fill_culopt_flags(char *val, win_T *wp) p = val; } while (*p != NUL) { - if (STRNCMP(p, "line", 4) == 0) { + if (strncmp(p, "line", 4) == 0) { p += 4; culopt_flags_new |= CULOPT_LINE; - } else if (STRNCMP(p, "both", 4) == 0) { + } else if (strncmp(p, "both", 4) == 0) { p += 4; culopt_flags_new |= CULOPT_LINE | CULOPT_NBR; - } else if (STRNCMP(p, "number", 6) == 0) { + } else if (strncmp(p, "number", 6) == 0) { p += 6; culopt_flags_new |= CULOPT_NBR; - } else if (STRNCMP(p, "screenline", 10) == 0) { + } else if (strncmp(p, "screenline", 10) == 0) { p += 10; culopt_flags_new |= CULOPT_SCRLINE; } @@ -5159,8 +5159,8 @@ int option_set_callback_func(char *optval, Callback *optcb) typval_T *tv; if (*optval == '{' - || (STRNCMP(optval, "function(", 9) == 0) - || (STRNCMP(optval, "funcref(", 8) == 0)) { + || (strncmp(optval, "function(", 9) == 0) + || (strncmp(optval, "funcref(", 8) == 0)) { // Lambda expression or a funcref tv = eval_expr(optval); if (tv == NULL) { diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 5b17ec7ca8..61a51532a4 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -550,7 +550,7 @@ static int check_signcolumn(char *val) // check for 'auto:<NUMBER>-<NUMBER>' if (strlen(val) == 8 - && !STRNCMP(val, "auto:", 5) + && !strncmp(val, "auto:", 5) && ascii_isdigit(val[5]) && val[6] == '-' && ascii_isdigit(val[7])) { @@ -1609,7 +1609,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf char *q = curwin->w_s->b_p_spl; // Skip the first name if it is "cjk". - if (STRNCMP(q, "cjk,", 4) == 0) { + if (strncmp(q, "cjk,", 4) == 0) { q += 4; } @@ -1678,7 +1678,7 @@ static int opt_strings_flags(char *val, char **values, unsigned *flagp, bool lis } size_t len = strlen(values[i]); - if (STRNCMP(values[i], val, len) == 0 + if (strncmp(values[i], val, len) == 0 && ((list && val[len] == ',') || val[len] == NUL)) { val += len + (val[len] == ','); assert(i < sizeof(1U) * 8); diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index dac3cae199..29bfbfcfdf 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -760,7 +760,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es if (prefix != NULL && src - prefix_len >= srcp - && STRNCMP(src - prefix_len, prefix, prefix_len) == 0) { + && strncmp(src - prefix_len, prefix, (size_t)prefix_len) == 0) { at_start = true; } } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d694025bc2..8c4fee58b1 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -180,7 +180,7 @@ int os_nodetype(const char *name) // Edge case from Vim os_win32.c: // We can't open a file with a name "\\.\con" or "\\.\prn", trying to read // from it later will cause Vim to hang. Thus return NODE_WRITABLE here. - if (STRNCMP(name, "\\\\.\\", 4) == 0) { + if (strncmp(name, "\\\\.\\", 4) == 0) { return NODE_WRITABLE; } diff --git a/src/nvim/profile.c b/src/nvim/profile.c index b6e2572182..4acd8b3621 100644 --- a/src/nvim/profile.c +++ b/src/nvim/profile.c @@ -297,7 +297,7 @@ void ex_profile(exarg_T *eap) len = (int)(e - eap->arg); e = skipwhite(e); - if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) { + if (len == 5 && strncmp(eap->arg, "start", 5) == 0 && *e != NUL) { xfree(profile_fname); profile_fname = (char *)expand_env_save_opt((char_u *)e, true); do_profiling = PROF_YES; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index d61a185fcc..70584c2a6c 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2164,8 +2164,9 @@ char *reg_submatch(int no) len++; } if (round == 2) { - STRNCPY(retval + len, reg_getline_submatch(lnum), // NOLINT(runtime/printf) - rsm.sm_mmatch->endpos[no].col); + strncpy(retval + len, // NOLINT(runtime/printf) + reg_getline_submatch(lnum), + (size_t)rsm.sm_mmatch->endpos[no].col); } len += rsm.sm_mmatch->endpos[no].col; if (round == 2) { diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 7361b31456..25a99c58ba 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -3332,10 +3332,10 @@ static void nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent) int last = indent->ga_len - 3; char_u save[2]; - STRNCPY(save, &p[last], 2); // NOLINT(runtime/printf) + strncpy(save, &p[last], 2); // NOLINT(runtime/printf) memcpy(&p[last], "+-", 2); fprintf(debugf, " %s", p); - STRNCPY(&p[last], save, 2); // NOLINT(runtime/printf) + strncpy(&p[last], save, 2); // NOLINT(runtime/printf) } else { fprintf(debugf, " %s", p); } diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 659e34f27a..d922a4d303 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -214,19 +214,19 @@ void ex_runtime(exarg_T *eap) { char *arg = eap->arg; char *p = skiptowhite(arg); - ptrdiff_t len = p - arg; + size_t len = (size_t)(p - arg); int flags = eap->forceit ? DIP_ALL : 0; - if (STRNCMP(arg, "START", len) == 0) { + if (strncmp(arg, "START", len) == 0) { flags += DIP_START + DIP_NORTP; arg = skipwhite(arg + len); - } else if (STRNCMP(arg, "OPT", len) == 0) { + } else if (strncmp(arg, "OPT", len) == 0) { flags += DIP_OPT + DIP_NORTP; arg = skipwhite(arg + len); - } else if (STRNCMP(arg, "PACK", len) == 0) { + } else if (strncmp(arg, "PACK", len) == 0) { flags += DIP_START + DIP_OPT + DIP_NORTP; arg = skipwhite(arg + len); - } else if (STRNCMP(arg, "ALL", len) == 0) { + } else if (strncmp(arg, "ALL", len) == 0) { flags += DIP_START + DIP_OPT; arg = skipwhite(arg + len); } @@ -1719,7 +1719,7 @@ static bool concat_continued_line(garray_T *const ga, const int init_growsize, c const char *const line = skipwhite_len((char *)p, len); len -= (size_t)(line - p); // Skip lines starting with '\" ', concat lines starting with '\' - if (len >= 3 && STRNCMP(line, "\"\\ ", 3) == 0) { + if (len >= 3 && strncmp(line, "\"\\ ", 3) == 0) { return true; } else if (len == 0 || line[0] != '\\') { return false; diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 3957cec316..8655206574 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -934,15 +934,15 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) } } } - const char_u *p = value; + const char *p = (char *)value; while (*p) { int i; for (i = 0; i < entries; i++) { const size_t len = strlen(tab[i].name); - if (STRNCMP(p, tab[i].name, len) == 0 + if (strncmp(p, tab[i].name, len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - const char_u *s = p + len + 1; + const char_u *s = (char_u *)p + len + 1; int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; @@ -973,7 +973,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) *(tab[i].cp) = c1; } } - p = s; + p = (char *)s; break; } } @@ -983,13 +983,13 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) const size_t len = strlen("multispace"); const size_t len2 = strlen("leadmultispace"); if (is_listchars - && STRNCMP(p, "multispace", len) == 0 + && strncmp(p, "multispace", len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - const char_u *s = p + len + 1; + const char_u *s = (char_u *)p + len + 1; if (round == 0) { // Get length of lcs-multispace string in the first round - last_multispace = p; + last_multispace = (char_u *)p; multispace_len = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); @@ -1002,25 +1002,25 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) // lcs-multispace cannot be an empty string return e_invarg; } - p = s; + p = (char *)s; } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); - if (p == last_multispace) { + if (p == (char *)last_multispace) { wp->w_p_lcs_chars.multispace[multispace_pos++] = c1; } } - p = s; + p = (char *)s; } } else if (is_listchars - && STRNCMP(p, "leadmultispace", len2) == 0 + && strncmp(p, "leadmultispace", len2) == 0 && p[len2] == ':' && p[len2 + 1] != NUL) { - const char_u *s = p + len2 + 1; + const char_u *s = (char_u *)p + len2 + 1; if (round == 0) { // get length of lcs-leadmultispace string in first round - last_lmultispace = p; + last_lmultispace = (char_u *)p; lead_multispace_len = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); @@ -1033,16 +1033,16 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) // lcs-leadmultispace cannot be an empty string return e_invarg; } - p = s; + p = (char *)s; } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); - if (p == last_lmultispace) { + if (p == (char *)last_lmultispace) { wp->w_p_lcs_chars.leadmultispace[multispace_pos++] = c1; } } - p = s; + p = (char *)s; } } else { return e_invarg; diff --git a/src/nvim/search.c b/src/nvim/search.c index 692e7134e0..c1db0c9232 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -98,7 +98,7 @@ static int last_idx = 0; // index in spats[] for RE_LAST static char_u lastc[2] = { NUL, NUL }; // last character searched for static Direction lastcdir = FORWARD; // last direction of character search static int last_t_cmd = true; // last search t_cmd -static char_u lastc_bytes[MB_MAXBYTES + 1]; +static char lastc_bytes[MB_MAXBYTES + 1]; static int lastc_bytelen = 1; // >1 for multi-byte char // copy of spats[], for keeping the search patterns while executing autocmds @@ -404,7 +404,7 @@ bool pat_has_uppercase(char_u *pat) const char *last_csearch(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - return (const char *)lastc_bytes; + return lastc_bytes; } int last_csearch_forward(void) @@ -1410,11 +1410,11 @@ end_do_search: // contain the position of the match found. Blank lines match only if // ADDING is set. If p_ic is set then the pattern must be in lowercase. // Return OK for success, or FAIL if no line found. -int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) +int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char *pat) { linenr_T start = 0; - char_u *ptr; - char_u *p; + char *ptr; + char *p; if (buf->b_ml.ml_line_count == 0) { return FAIL; @@ -1448,8 +1448,8 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) if (start == 0) { start = pos->lnum; } - ptr = (char_u *)ml_get_buf(buf, pos->lnum, false); - p = (char_u *)skipwhite((char *)ptr); + ptr = ml_get_buf(buf, pos->lnum, false); + p = skipwhite(ptr); pos->col = (colnr_T)(p - ptr); // when adding lines the matching line may be empty but it is not @@ -1461,8 +1461,8 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) } else if (*p != NUL) { // Ignore empty lines. // Expanding lines or words. assert(ins_compl_len() >= 0); - if ((p_ic ? mb_strnicmp((char *)p, (char *)pat, (size_t)ins_compl_len()) - : STRNCMP(p, pat, ins_compl_len())) == 0) { + if ((p_ic ? mb_strnicmp(p, pat, (size_t)ins_compl_len()) + : strncmp(p, pat, (size_t)ins_compl_len())) == 0) { return OK; } } @@ -1492,13 +1492,13 @@ int searchc(cmdarg_T *cap, int t_cmd) *lastc = (char_u)c; set_csearch_direction(dir); set_csearch_until(t_cmd); - lastc_bytelen = utf_char2bytes(c, (char *)lastc_bytes); + lastc_bytelen = utf_char2bytes(c, lastc_bytes); if (cap->ncharC1 != 0) { lastc_bytelen += utf_char2bytes(cap->ncharC1, - (char *)lastc_bytes + lastc_bytelen); + lastc_bytes + lastc_bytelen); if (cap->ncharC2 != 0) { lastc_bytelen += utf_char2bytes(cap->ncharC2, - (char *)lastc_bytes + lastc_bytelen); + lastc_bytes + lastc_bytelen); } } } @@ -1550,7 +1550,7 @@ int searchc(cmdarg_T *cap, int t_cmd) if (p[col] == c && stop) { break; } - } else if (STRNCMP(p + col, lastc_bytes, lastc_bytelen) == 0 && stop) { + } else if (strncmp(p + col, lastc_bytes, (size_t)lastc_bytelen) == 0 && stop) { break; } stop = true; @@ -1621,7 +1621,7 @@ static bool find_rawstring_end(char *linep, pos_T *startpos, pos_T *endpos) break; } if (*p == ')' - && STRNCMP(delim_copy, p + 1, delim_len) == 0 + && strncmp(delim_copy, p + 1, delim_len) == 0 && p[delim_len + 1] == '"') { found = true; break; @@ -1765,9 +1765,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) ptr = skipwhite(linep); if (*ptr == '#' && pos.col <= (colnr_T)(ptr - linep)) { ptr = skipwhite(ptr + 1); - if (STRNCMP(ptr, "if", 2) == 0 - || STRNCMP(ptr, "endif", 5) == 0 - || STRNCMP(ptr, "el", 2) == 0) { + if (strncmp(ptr, "if", 2) == 0 + || strncmp(ptr, "endif", 5) == 0 + || strncmp(ptr, "el", 2) == 0) { hash_dir = 1; } } else if (linep[pos.col] == '/') { // Are we on a comment? @@ -1838,9 +1838,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } if (initc != '#') { ptr = skipwhite(skipwhite(linep) + 1); - if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0) { + if (strncmp(ptr, "if", 2) == 0 || strncmp(ptr, "el", 2) == 0) { hash_dir = 1; - } else if (STRNCMP(ptr, "endif", 5) == 0) { + } else if (strncmp(ptr, "endif", 5) == 0) { hash_dir = -1; } else { return NULL; @@ -1865,29 +1865,29 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) pos.col = (colnr_T)(ptr - linep); ptr = skipwhite(ptr + 1); if (hash_dir > 0) { - if (STRNCMP(ptr, "if", 2) == 0) { + if (strncmp(ptr, "if", 2) == 0) { count++; - } else if (STRNCMP(ptr, "el", 2) == 0) { + } else if (strncmp(ptr, "el", 2) == 0) { if (count == 0) { return &pos; } - } else if (STRNCMP(ptr, "endif", 5) == 0) { + } else if (strncmp(ptr, "endif", 5) == 0) { if (count == 0) { return &pos; } count--; } } else { - if (STRNCMP(ptr, "if", 2) == 0) { + if (strncmp(ptr, "if", 2) == 0) { if (count == 0) { return &pos; } count--; - } else if (initc == '#' && STRNCMP(ptr, "el", 2) == 0) { + } else if (initc == '#' && strncmp(ptr, "el", 2) == 0) { if (count == 0) { return &pos; } - } else if (STRNCMP(ptr, "endif", 5) == 0) { + } else if (strncmp(ptr, "endif", 5) == 0) { count++; } } @@ -3418,7 +3418,7 @@ static char_u *get_line_and_copy(linenr_T lnum, char_u *buf) /// @param action What to do when we find it /// @param start_lnum first line to start searching /// @param end_lnum last line for searching -void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bool skip_comments, +void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool skip_comments, int type, long count, int action, linenr_T start_lnum, linenr_T end_lnum) { SearchedFile *files; // Stack of included files @@ -3699,9 +3699,9 @@ search_line: // compare the first "len" chars from "ptr" startp = skipwhite(p); if (p_ic) { - matched = !mb_strnicmp(startp, (char *)ptr, len); + matched = !mb_strnicmp(startp, ptr, len); } else { - matched = !STRNCMP(startp, ptr, len); + matched = !strncmp(startp, ptr, len); } if (matched && define_matched && whole && vim_iswordc((uint8_t)startp[len])) { @@ -3716,7 +3716,7 @@ search_line: // is not considered to be a comment line. if (skip_comments) { if ((*line != '#' - || STRNCMP(skipwhite((char *)line + 1), "define", 6) != 0) + || strncmp(skipwhite(line + 1), "define", 6) != 0) && get_leader_len(line, NULL, false, true)) { matched = false; } @@ -3769,8 +3769,8 @@ search_line: i = (int)(p - aux); if (compl_status_adding() && i == ins_compl_len()) { - // IOSIZE > compl_length, so the STRNCPY works - STRNCPY(IObuff, aux, i); // NOLINT(runtime/printf) + // IOSIZE > compl_length, so the strncpy works + strncpy(IObuff, aux, (size_t)i); // NOLINT(runtime/printf) // Get the next line: when "depth" < 0 from the current // buffer, otherwise from the included file. Jump to @@ -3808,7 +3808,7 @@ search_line: if (p - aux >= IOSIZE - i) { p = aux + IOSIZE - i - 1; } - STRNCPY(IObuff + i, aux, p - aux); // NOLINT(runtime/printf) + strncpy(IObuff + i, aux, (size_t)(p - aux)); // NOLINT(runtime/printf) i += (int)(p - aux); cont_s_ipos = true; } diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 0f81217b4a..c72d2377aa 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3355,7 +3355,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const error_desc #define CHECK_KEY(key, \ expected) ((key).via.str.size == (sizeof(expected) - 1) \ - && STRNCMP((key).via.str.ptr, expected, (sizeof(expected) - 1)) == 0) + && strncmp((key).via.str.ptr, expected, (sizeof(expected) - 1)) == 0) #define CLEAR_GA_AND_ERROR_OUT(ga) \ do { \ ga_clear(&(ga)); \ diff --git a/src/nvim/sign.c b/src/nvim/sign.c index 2453e6f766..e211b0069e 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -1215,27 +1215,27 @@ static void sign_define_cmd(char *sign_name, char *cmdline) break; } p = skiptowhite_esc(arg); - if (STRNCMP(arg, "icon=", 5) == 0) { + if (strncmp(arg, "icon=", 5) == 0) { arg += 5; XFREE_CLEAR(icon); icon = xstrnsave(arg, (size_t)(p - arg)); - } else if (STRNCMP(arg, "text=", 5) == 0) { + } else if (strncmp(arg, "text=", 5) == 0) { arg += 5; XFREE_CLEAR(text); text = xstrnsave(arg, (size_t)(p - arg)); - } else if (STRNCMP(arg, "linehl=", 7) == 0) { + } else if (strncmp(arg, "linehl=", 7) == 0) { arg += 7; XFREE_CLEAR(linehl); linehl = xstrnsave(arg, (size_t)(p - arg)); - } else if (STRNCMP(arg, "texthl=", 7) == 0) { + } else if (strncmp(arg, "texthl=", 7) == 0) { arg += 7; XFREE_CLEAR(texthl); texthl = xstrnsave(arg, (size_t)(p - arg)); - } else if (STRNCMP(arg, "culhl=", 6) == 0) { + } else if (strncmp(arg, "culhl=", 6) == 0) { arg += 6; XFREE_CLEAR(culhl); culhl = xstrnsave(arg, (size_t)(p - arg)); - } else if (STRNCMP(arg, "numhl=", 6) == 0) { + } else if (strncmp(arg, "numhl=", 6) == 0) { arg += 6; XFREE_CLEAR(numhl); numhl = xstrnsave(arg, (size_t)(p - arg)); @@ -1393,19 +1393,19 @@ static int parse_sign_cmd_args(int cmd, char *arg, char **sign_name, int *signid } while (*arg != NUL) { - if (STRNCMP(arg, "line=", 5) == 0) { + if (strncmp(arg, "line=", 5) == 0) { arg += 5; *lnum = atoi(arg); arg = skiptowhite(arg); lnum_arg = true; - } else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) { + } else if (strncmp(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) { if (*signid != -1) { emsg(_(e_invarg)); return FAIL; } *signid = -2; arg = skiptowhite(arg + 1); - } else if (STRNCMP(arg, "name=", 5) == 0) { + } else if (strncmp(arg, "name=", 5) == 0) { arg += 5; name = arg; arg = skiptowhite(arg); @@ -1416,23 +1416,23 @@ static int parse_sign_cmd_args(int cmd, char *arg, char **sign_name, int *signid name++; } *sign_name = name; - } else if (STRNCMP(arg, "group=", 6) == 0) { + } else if (strncmp(arg, "group=", 6) == 0) { arg += 6; *group = arg; arg = skiptowhite(arg); if (*arg != NUL) { *arg++ = NUL; } - } else if (STRNCMP(arg, "priority=", 9) == 0) { + } else if (strncmp(arg, "priority=", 9) == 0) { arg += 9; *prio = atoi(arg); arg = skiptowhite(arg); - } else if (STRNCMP(arg, "file=", 5) == 0) { + } else if (strncmp(arg, "file=", 5) == 0) { arg += 5; filename = arg; *buf = buflist_findname_exp(arg); break; - } else if (STRNCMP(arg, "buffer=", 7) == 0) { + } else if (strncmp(arg, "buffer=", 7) == 0) { arg += 7; filename = arg; *buf = buflist_findnr(getdigits_int(&arg, true, 0)); @@ -1900,23 +1900,23 @@ void set_context_in_sign_cmd(expand_T *xp, char *arg) xp->xp_pattern = p + 1; switch (cmd_idx) { case SIGNCMD_DEFINE: - if (STRNCMP(last, "texthl", 6) == 0 - || STRNCMP(last, "linehl", 6) == 0 - || STRNCMP(last, "culhl", 5) == 0 - || STRNCMP(last, "numhl", 5) == 0) { + if (strncmp(last, "texthl", 6) == 0 + || strncmp(last, "linehl", 6) == 0 + || strncmp(last, "culhl", 5) == 0 + || strncmp(last, "numhl", 5) == 0) { xp->xp_context = EXPAND_HIGHLIGHT; - } else if (STRNCMP(last, "icon", 4) == 0) { + } else if (strncmp(last, "icon", 4) == 0) { xp->xp_context = EXPAND_FILES; } else { xp->xp_context = EXPAND_NOTHING; } break; case SIGNCMD_PLACE: - if (STRNCMP(last, "name", 4) == 0) { + if (strncmp(last, "name", 4) == 0) { expand_what = EXP_SIGN_NAMES; - } else if (STRNCMP(last, "group", 5) == 0) { + } else if (strncmp(last, "group", 5) == 0) { expand_what = EXP_SIGN_GROUPS; - } else if (STRNCMP(last, "file", 4) == 0) { + } else if (strncmp(last, "file", 4) == 0) { xp->xp_context = EXPAND_BUFFERS; } else { xp->xp_context = EXPAND_NOTHING; @@ -1924,9 +1924,9 @@ void set_context_in_sign_cmd(expand_T *xp, char *arg) break; case SIGNCMD_UNPLACE: case SIGNCMD_JUMP: - if (STRNCMP(last, "group", 5) == 0) { + if (strncmp(last, "group", 5) == 0) { expand_what = EXP_SIGN_GROUPS; - } else if (STRNCMP(last, "file", 4) == 0) { + } else if (strncmp(last, "file", 4) == 0) { xp->xp_context = EXPAND_BUFFERS; } else { xp->xp_context = EXPAND_NOTHING; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index f91ac0f347..13a0526fd2 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2113,7 +2113,7 @@ char *did_set_spelllang(win_T *wp) for (int j = 0; j < ga.ga_len; j++) { lp2 = LANGP_ENTRY(ga, j); if (!GA_EMPTY(&lp2->lp_slang->sl_sal) - && STRNCMP(lp->lp_slang->sl_name, + && strncmp(lp->lp_slang->sl_name, lp2->lp_slang->sl_name, 2) == 0) { lp->lp_sallang = lp2->lp_slang; break; @@ -2130,7 +2130,7 @@ char *did_set_spelllang(win_T *wp) for (int j = 0; j < ga.ga_len; j++) { lp2 = LANGP_ENTRY(ga, j); if (!GA_EMPTY(&lp2->lp_slang->sl_rep) - && STRNCMP(lp->lp_slang->sl_name, + && strncmp(lp->lp_slang->sl_name, lp2->lp_slang->sl_name, 2) == 0) { lp->lp_replang = lp2->lp_slang; break; @@ -2598,7 +2598,7 @@ void ex_spellrepall(exarg_T *eap) // Only replace when the right word isn't there yet. This happens // when changing "etc" to "etc.". char *line = get_cursor_line_ptr(); - if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, + if (addlen <= 0 || strncmp(line + curwin->w_cursor.col, repl_to, strlen(repl_to)) != 0) { char_u *p = xmalloc(strlen(line) + (size_t)addlen + 1); memmove(p, line, (size_t)curwin->w_cursor.col); @@ -3420,7 +3420,7 @@ static void dump_word(slang_T *slang, char *word, char *pat, Direction *dir, int ml_append(lnum, p, (colnr_T)0, false); } else if (((dumpflags & DUMPFLAG_ICASE) ? mb_strnicmp(p, pat, strlen(pat)) == 0 - : STRNCMP(p, pat, strlen(pat)) == 0) + : strncmp(p, pat, strlen(pat)) == 0) && ins_compl_add_infercase((char_u *)p, (int)strlen(p), p_ic, NULL, *dir, false) == OK) { // if dir was BACKWARD then honor it just once diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 48c3cd11e2..69847bfa10 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -3731,7 +3731,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) if (*line == '/') { line++; - if (STRNCMP(line, "encoding=", 9) == 0) { + if (strncmp(line, "encoding=", 9) == 0) { if (spin->si_conv.vc_type != CONV_NONE) { smsg(_("Duplicate /encoding= line ignored in %s line %ld: %s"), fname, lnum, line - 1); @@ -3755,7 +3755,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) continue; } - if (STRNCMP(line, "regions=", 8) == 0) { + if (strncmp(line, "regions=", 8) == 0) { if (spin->si_region_count > 1) { smsg(_("Duplicate /regions= line ignored in %s line %ld: %s"), fname, lnum, line); @@ -4895,7 +4895,7 @@ void ex_mkspell(exarg_T *eap) char *arg = eap->arg; bool ascii = false; - if (STRNCMP(arg, "-ascii", 6) == 0) { + if (strncmp(arg, "-ascii", 6) == 0) { ascii = true; arg = skipwhite(arg + 6); } diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 7b08fec48c..76410e5225 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -412,9 +412,9 @@ int spell_check_sps(void) f = SPS_FAST; } else if (strcmp(buf, "double") == 0) { f = SPS_DOUBLE; - } else if (STRNCMP(buf, "expr:", 5) != 0 - && STRNCMP(buf, "file:", 5) != 0 - && (STRNCMP(buf, "timeout:", 8) != 0 + } else if (strncmp(buf, "expr:", 5) != 0 + && strncmp(buf, "file:", 5) != 0 + && (strncmp(buf, "timeout:", 8) != 0 || (!ascii_isdigit(buf[8]) && !(buf[8] == '-' && ascii_isdigit(buf[9]))))) { f = -1; @@ -546,7 +546,7 @@ void spell_suggest(int count) lines_left = Rows; // avoid more prompt vim_snprintf((char *)IObuff, IOSIZE, _("Change \"%.*s\" to:"), sug.su_badlen, sug.su_badptr); - if (cmdmsg_rl && STRNCMP(IObuff, "Change", 6) == 0) { + if (cmdmsg_rl && strncmp(IObuff, "Change", 6) == 0) { // And now the rabbit from the high hat: Avoid showing the // untranslated message rightleft. vim_snprintf((char *)IObuff, IOSIZE, ":ot \"%.*s\" egnahC", @@ -711,7 +711,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma bool banbadword, bool need_cap, bool interactive) { hlf_T attr = HLF_COUNT; - char_u buf[MAXPATHL]; + char buf[MAXPATHL]; char *p; bool do_combine = false; char *sps_copy; @@ -783,7 +783,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma // for that. c = utf_ptr2char(su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { - make_case_word(su->su_badword, buf, WF_ONECAP); + make_case_word(su->su_badword, (char_u *)buf, WF_ONECAP); add_suggestion(su, &su->su_ga, (char *)buf, su->su_badlen, SCORE_ICASE, 0, true, su->su_sallang, false); } @@ -800,18 +800,18 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma for (p = sps_copy; *p != NUL;) { copy_option_part(&p, (char *)buf, MAXPATHL, ","); - if (STRNCMP(buf, "expr:", 5) == 0) { + if (strncmp(buf, "expr:", 5) == 0) { // Evaluate an expression. Skip this when called recursively, // when using spellsuggest() in the expression. if (!expr_busy) { expr_busy = true; - spell_suggest_expr(su, buf + 5); + spell_suggest_expr(su, (char_u *)buf + 5); expr_busy = false; } - } else if (STRNCMP(buf, "file:", 5) == 0) { + } else if (strncmp(buf, "file:", 5) == 0) { // Use list of suggestions in a file. - spell_suggest_file(su, buf + 5); - } else if (STRNCMP(buf, "timeout:", 8) == 0) { + spell_suggest_file(su, (char_u *)buf + 5); + } else if (strncmp(buf, "timeout:", 8) == 0) { // Limit the time searching for suggestions. spell_suggest_timeout = atol((char *)buf + 8); } else if (!did_intern) { @@ -1428,8 +1428,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff); } else if (flags & WF_KEEPCAP) { // Must find the word in the keep-case tree. - find_keepcap_word(slang, tword + sp->ts_splitoff, - (char_u *)preword + sp->ts_prewordlen); + find_keepcap_word(slang, (char *)tword + sp->ts_splitoff, preword + sp->ts_prewordlen); } else { // Include badflags: If the badword is onecap or allcap // use that for the goodword too. But if the badword is @@ -2376,9 +2375,9 @@ static void go_deeper(trystate_T *stack, int depth, int score_add) /// words and put it in "kword". /// Theoretically there could be several keep-case words that result in the /// same case-folded word, but we only find one... -static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) +static void find_keepcap_word(slang_T *slang, char *fword, char *kword) { - char_u uword[MAXWLEN]; // "fword" in upper-case + char uword[MAXWLEN]; // "fword" in upper-case int depth; idx_T tryidx; @@ -2405,7 +2404,7 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) } // Make an all-cap version of "fword". - allcap_copy(fword, uword); + allcap_copy((char_u *)fword, (char_u *)uword); // Each character needs to be tried both case-folded and upper-case. // All this gets very complicated if we keep in mind that changing case @@ -2434,13 +2433,13 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) } else { // round[depth] == 1: Try using the folded-case character. // round[depth] == 2: Try using the upper-case character. - flen = utf_ptr2len((char *)fword + fwordidx[depth]); + flen = utf_ptr2len(fword + fwordidx[depth]); ulen = utf_ptr2len((char *)uword + uwordidx[depth]); if (round[depth] == 1) { - p = fword + fwordidx[depth]; + p = (char_u *)fword + fwordidx[depth]; l = flen; } else { - p = uword + uwordidx[depth]; + p = (char_u *)uword + uwordidx[depth]; l = ulen; } @@ -2475,12 +2474,14 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) // Found the matching char. Copy it to "kword" and go a // level deeper. if (round[depth] == 1) { - STRNCPY(kword + kwordlen[depth], fword + fwordidx[depth], // NOLINT(runtime/printf) - flen); + strncpy(kword + kwordlen[depth], // NOLINT(runtime/printf) + fword + fwordidx[depth], + (size_t)flen); kwordlen[depth + 1] = kwordlen[depth] + flen; } else { - STRNCPY(kword + kwordlen[depth], uword + uwordidx[depth], // NOLINT(runtime/printf) - ulen); + strncpy(kword + kwordlen[depth], // NOLINT(runtime/printf) + uword + uwordidx[depth], + (size_t)ulen); kwordlen[depth + 1] = kwordlen[depth] + ulen; } fwordidx[depth + 1] = fwordidx[depth] + flen; @@ -2897,7 +2898,7 @@ badword: if (flags & WF_KEEPCAP) { // Must find the word in the keep-case tree. - find_keepcap_word(slang, theword, cword); + find_keepcap_word(slang, (char *)theword, (char *)cword); p = cword; } else { flags |= su->su_badflags; @@ -3134,7 +3135,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i for (i = gap->ga_len; --i >= 0; stp++) { if (stp->st_wordlen == goodlen && stp->st_orglen == badlen - && STRNCMP(stp->st_word, goodword, goodlen) == 0) { + && strncmp(stp->st_word, goodword, (size_t)goodlen) == 0) { // Found it. Remember the word with the lowest score. if (stp->st_slang == NULL) { stp->st_slang = slang; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6af39d06d3..0b92757fd9 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4328,7 +4328,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) if (item == ITEM_MATCHGROUP) { p = skiptowhite(rest); - if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) { + if ((p - rest == 4 && strncmp(rest, "NONE", 4) == 0) || eap->skip) { matchgroup_id = 0; } else { matchgroup_id = syn_check_group(rest, (size_t)(p - rest)); @@ -4765,7 +4765,7 @@ static char *get_syn_pattern(char *arg, synpat_T *ci) end++; do { for (idx = SPO_COUNT; --idx >= 0;) { - if (STRNCMP(end, spo_name_tab[idx], 3) == 0) { + if (strncmp(end, spo_name_tab[idx], 3) == 0) { break; } } @@ -4854,10 +4854,10 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } else if (!eap->skip) { curwin->w_s->b_syn_sync_id = (int16_t)syn_name2id("Comment"); } - } else if (STRNCMP(key, "LINES", 5) == 0 - || STRNCMP(key, "MINLINES", 8) == 0 - || STRNCMP(key, "MAXLINES", 8) == 0 - || STRNCMP(key, "LINEBREAKS", 10) == 0) { + } else if (strncmp(key, "LINES", 5) == 0 + || strncmp(key, "MINLINES", 8) == 0 + || strncmp(key, "MAXLINES", 8) == 0 + || strncmp(key, "LINEBREAKS", 10) == 0) { if (key[4] == 'S') { arg_end = key + 6; } else if (key[0] == 'L') { diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 71164726eb..e99ac894dc 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -63,14 +63,14 @@ // Structure to hold pointers to various items in a tag line. typedef struct tag_pointers { // filled in by parse_tag_line(): - char *tagname; // start of tag name (skip "file:") + char *tagname; // start of tag name (skip "file:") char_u *tagname_end; // char after tag name - char_u *fname; // first char of file name - char_u *fname_end; // char after file name - char_u *command; // first char of command + char_u *fname; // first char of file name + char_u *fname_end; // char after file name + char *command; // first char of command // filled in by parse_match(): char_u *command_end; // first char after command - char *tag_fname; // file name of the tags file. This is used + char *tag_fname; // file name of the tags file. This is used // when 'tr' is set. char_u *tagkind; // "kind:" value char_u *tagkind_end; // end of tagkind @@ -81,11 +81,11 @@ typedef struct tag_pointers { // Structure to hold info about the tag pattern being used. typedef struct { - char_u *pat; // the pattern - int len; // length of pat[] - char_u *head; // start of pattern head - int headlen; // length of head[] - regmatch_T regmatch; // regexp program, may be NULL + char *pat; // the pattern + int len; // length of pat[] + char *head; // start of pattern head + int headlen; // length of head[] + regmatch_T regmatch; // regexp program, may be NULL } pat_T; // The matching tags are first stored in one of the hash tables. In @@ -800,7 +800,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char taggy_T *tagstack = curwin->w_tagstack; int tagstackidx = curwin->w_tagstackidx; int i; - char_u *p; + char *p; char_u *command_end; tagptrs_T tagp; int taglen; @@ -853,9 +853,9 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char // Find out the actual file name. If it is long, truncate // it and put "..." in the middle - p = tag_full_fname(&tagp); + p = (char *)tag_full_fname(&tagp); if (p != NULL) { - msg_outtrans_attr((char *)p, HL_ATTR(HLF_D)); + msg_outtrans_attr(p, HL_ATTR(HLF_D)); XFREE_CLEAR(p); } if (msg_col > 0) { @@ -869,35 +869,35 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char // print any extra fields command_end = tagp.command_end; if (command_end != NULL) { - p = command_end + 3; + p = (char *)command_end + 3; while (*p && *p != '\r' && *p != '\n') { while (*p == TAB) { p++; } // skip "file:" without a value (static tag) - if (STRNCMP(p, "file:", 5) == 0 && ascii_isspace(p[5])) { + if (strncmp(p, "file:", 5) == 0 && ascii_isspace(p[5])) { p += 5; continue; } // skip "kind:<kind>" and "<kind>" - if (p == tagp.tagkind - || (p + 5 == tagp.tagkind - && STRNCMP(p, "kind:", 5) == 0)) { - p = tagp.tagkind_end; + if (p == (char *)tagp.tagkind + || (p + 5 == (char *)tagp.tagkind + && strncmp(p, "kind:", 5) == 0)) { + p = (char *)tagp.tagkind_end; continue; } // print all other extra fields attr = HL_ATTR(HLF_CM); while (*p && *p != '\r' && *p != '\n') { - if (msg_col + ptr2cells((char *)p) >= Columns) { + if (msg_col + ptr2cells(p) >= Columns) { msg_putchar('\n'); if (got_int) { break; } msg_advance(15); } - p = (char_u *)msg_outtrans_one((char *)p, attr); + p = msg_outtrans_one(p, attr); if (*p == TAB) { msg_puts_attr(" ", attr); break; @@ -918,7 +918,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char for (p = tagp.command; *p && *p != '\r' && *p != '\n'; p++) {} - command_end = p; + command_end = (char_u *)p; } // Put the info (in several lines) at column 15. @@ -931,12 +931,12 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char } } // Remove leading whitespace from pattern - while (p != command_end && ascii_isspace(*p)) { + while (p != (char *)command_end && ascii_isspace(*p)) { p++; } - while (p != command_end) { - if (msg_col + (*p == TAB ? 1 : ptr2cells((char *)p)) > Columns) { + while (p != (char *)command_end) { + if (msg_col + (*p == TAB ? 1 : ptr2cells(p)) > Columns) { msg_putchar('\n'); } if (got_int) { @@ -955,16 +955,16 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char msg_putchar(' '); p++; } else { - p = (char_u *)msg_outtrans_one((char *)p, 0); + p = msg_outtrans_one(p, 0); } // don't display the "$/;\"" and "$?;\"" - if (p == command_end - 2 && *p == '$' + if (p == (char *)command_end - 2 && *p == '$' && *(p + 1) == *tagp.command) { break; } // don't display matching '/' or '?' - if (p == command_end - 1 && *p == *tagp.command + if (p == (char *)command_end - 1 && *p == *tagp.command && (*p == '/' || *p == '?')) { break; } @@ -1023,17 +1023,17 @@ static int add_llist_tags(char_u *tag, int num_matches, char **matches) lnum = 0; if (isdigit(*tagp.command)) { // Line number is used to locate the tag - lnum = atol((char *)tagp.command); + lnum = atol(tagp.command); } else { char_u *cmd_start, *cmd_end; // Search pattern is used to locate the tag // Locate the end of the command - cmd_start = tagp.command; + cmd_start = (char_u *)tagp.command; cmd_end = tagp.command_end; if (cmd_end == NULL) { - for (p = tagp.command; + for (p = (char_u *)tagp.command; *p && *p != '\r' && *p != '\n'; p++) {} cmd_end = p; } @@ -1211,7 +1211,7 @@ static void prepare_pats(pat_T *pats, int has_re) } if (has_re) { - pats->regmatch.regprog = vim_regcomp((char *)pats->pat, p_magic ? RE_MAGIC : 0); + pats->regmatch.regprog = vim_regcomp(pats->pat, p_magic ? RE_MAGIC : 0); } else { pats->regmatch.regprog = NULL; } @@ -1435,7 +1435,7 @@ static void findtags_state_init(findtags_state_T *st, char *pat, int flags, int st->tag_fname = xmalloc(MAXPATHL + 1); st->fp = NULL; st->orgpat = xmalloc(sizeof(pat_T)); - st->orgpat->pat = (char_u *)pat; + st->orgpat->pat = pat; st->orgpat->len = (int)strlen(pat); st->orgpat->regmatch.regprog = NULL; st->flags = flags; @@ -1777,10 +1777,10 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta // Compare the current tag with the searched tag. if (margs->sortic) { - tagcmp = tag_strnicmp((char_u *)tagpp->tagname, st->orgpat->head, + tagcmp = tag_strnicmp((char_u *)tagpp->tagname, (char_u *)st->orgpat->head, (size_t)cmplen); } else { - tagcmp = STRNCMP(tagpp->tagname, st->orgpat->head, cmplen); + tagcmp = strncmp(tagpp->tagname, st->orgpat->head, (size_t)cmplen); } // A match with a shorter tag means to search forward. @@ -1826,7 +1826,7 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta return TAG_MATCH_STOP; } else if (st->state == TS_SKIP_BACK) { assert(cmplen >= 0); - if (mb_strnicmp(tagpp->tagname, (char *)st->orgpat->head, (size_t)cmplen) != 0) { + if (mb_strnicmp(tagpp->tagname, st->orgpat->head, (size_t)cmplen) != 0) { st->state = TS_STEP_FORWARD; } else { // Have to skip back more. Restore the curr_offset @@ -1836,7 +1836,7 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta return TAG_MATCH_NEXT; } else if (st->state == TS_STEP_FORWARD) { assert(cmplen >= 0); - if (mb_strnicmp(tagpp->tagname, (char *)st->orgpat->head, (size_t)cmplen) != 0) { + if (mb_strnicmp(tagpp->tagname, st->orgpat->head, (size_t)cmplen) != 0) { if ((off_T)vim_ftell(st->fp) > sinfo_p->match_offset) { return TAG_MATCH_STOP; // past last match } else { @@ -1846,7 +1846,7 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta } else { // skip this match if it can't match assert(cmplen >= 0); - if (mb_strnicmp(tagpp->tagname, (char *)st->orgpat->head, (size_t)cmplen) != 0) { + if (mb_strnicmp(tagpp->tagname, st->orgpat->head, (size_t)cmplen) != 0) { return TAG_MATCH_NEXT; } } @@ -1857,7 +1857,7 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta if (tagpp->fname_end == NULL) { status = FAIL; } else { - tagpp->command = tagpp->fname_end + 1; + tagpp->command = (char *)tagpp->fname_end + 1; status = OK; } } else { @@ -1902,12 +1902,12 @@ static bool findtags_match_tag(findtags_state_T *st, tagptrs_T *tagpp, findtags_ } else { if (st->orgpat->regmatch.rm_ic) { assert(cmplen >= 0); - match = mb_strnicmp(tagpp->tagname, (char *)st->orgpat->pat, (size_t)cmplen) == 0; + match = mb_strnicmp(tagpp->tagname, st->orgpat->pat, (size_t)cmplen) == 0; if (match) { - margs->match_no_ic = STRNCMP(tagpp->tagname, st->orgpat->pat, cmplen) == 0; + margs->match_no_ic = strncmp(tagpp->tagname, st->orgpat->pat, (size_t)cmplen) == 0; } } else { - match = STRNCMP(tagpp->tagname, st->orgpat->pat, cmplen) == 0; + match = strncmp(tagpp->tagname, st->orgpat->pat, (size_t)cmplen) == 0; } } @@ -2020,7 +2020,7 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_ *tagpp->tagname_end = TAB; } else if (name_only) { if (st->get_searchpat) { - char_u *temp_end = tagpp->command; + char_u *temp_end = (char_u *)tagpp->command; if (*temp_end == '/') { while (*temp_end && *temp_end != '\r' @@ -2030,8 +2030,8 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_ } } - if (tagpp->command + 2 < temp_end) { - len = (size_t)(temp_end - tagpp->command - 2); + if (tagpp->command + 2 < (char *)temp_end) { + len = (size_t)(temp_end - (char_u *)tagpp->command - 2); mfp = xmalloc(len + 2); STRLCPY(mfp, tagpp->command + 2, len + 1); } else { @@ -2386,7 +2386,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc && ASCII_ISALPHA(pat[st.orgpat->len - 1])) { saved_pat = xstrnsave(pat, (size_t)st.orgpat->len - 3); st.help_lang_find = &pat[st.orgpat->len - 2]; - st.orgpat->pat = (char_u *)saved_pat; + st.orgpat->pat = saved_pat; st.orgpat->len -= 3; } } @@ -2665,7 +2665,7 @@ static int parse_tag_line(char_u *lbuf, tagptrs_T *tagp) if (*p == NUL) { return FAIL; } - tagp->command = p; + tagp->command = (char *)p; return OK; } @@ -2684,13 +2684,13 @@ static int parse_tag_line(char_u *lbuf, tagptrs_T *tagp) // Return false if it is not a static tag. static bool test_for_static(tagptrs_T *tagp) { - char_u *p; + char *p; // Check for new style static tag ":...<Tab>file:[<Tab>...]" p = tagp->command; - while ((p = (char_u *)vim_strchr((char *)p, '\t')) != NULL) { + while ((p = vim_strchr(p, '\t')) != NULL) { p++; - if (STRNCMP(p, "file:", 5) == 0) { + if (strncmp(p, "file:", 5) == 0) { return true; } } @@ -2738,10 +2738,10 @@ static int parse_match(char *lbuf, tagptrs_T *tagp) if (retval == OK) { // Try to find a kind field: "kind:<kind>" or just "<kind>" - p = (char *)tagp->command; - if (find_extra((char_u **)&p) == OK) { + p = tagp->command; + if (find_extra(&p) == OK) { tagp->command_end = (char_u *)p; - if (p > (char *)tagp->command && p[-1] == '|') { + if (p > tagp->command && p[-1] == '|') { tagp->command_end = (char_u *)p - 1; // drop trailing bar } p += 2; // skip ";\"" @@ -2749,11 +2749,11 @@ static int parse_match(char *lbuf, tagptrs_T *tagp) // Accept ASCII alphabetic kind characters and any multi-byte // character. while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) { - if (STRNCMP(p, "kind:", 5) == 0) { + if (strncmp(p, "kind:", 5) == 0) { tagp->tagkind = (char_u *)p + 5; - } else if (STRNCMP(p, "user_data:", 10) == 0) { + } else if (strncmp(p, "user_data:", 10) == 0) { tagp->user_data = p + 10; - } else if (STRNCMP(p, "line:", 5) == 0) { + } else if (strncmp(p, "line:", 5) == 0) { tagp->tagline = atoi(p + 5); } if (tagp->tagkind != NULL && tagp->user_data != NULL) { @@ -2816,9 +2816,9 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) bool save_p_ws; int save_p_scs, save_p_ic; linenr_T save_lnum; - char_u *str; - char_u *pbuf; // search pattern buffer - char_u *pbuf_end; + char *str; + char *pbuf; // search pattern buffer + char *pbuf_end; char_u *tofree_fname = NULL; char *fname; tagptrs_T tagp; @@ -2977,7 +2977,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) // anything following. str = pbuf; if (pbuf[0] == '/' || pbuf[0] == '?') { - str = (char_u *)skip_regexp((char *)pbuf + 1, pbuf[0], false) + 1; + str = skip_regexp(pbuf + 1, pbuf[0], false) + 1; } if (str > pbuf_end - 1) { // search command with nothing following save_p_ws = p_ws; @@ -2994,7 +2994,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) // start search before first line curwin->w_cursor.lnum = 0; } - if (do_search(NULL, pbuf[0], pbuf[0], (char *)pbuf + 1, (long)1, + if (do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1, search_options, NULL)) { retval = OK; } else { @@ -3003,20 +3003,19 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) // try again, ignore case now p_ic = true; - if (!do_search(NULL, pbuf[0], pbuf[0], (char *)pbuf + 1, (long)1, + if (!do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1, search_options, NULL)) { // Failed to find pattern, take a guess: "^func (" found = 2; (void)test_for_static(&tagp); cc = *tagp.tagname_end; *tagp.tagname_end = NUL; - snprintf((char *)pbuf, LSIZE, "^%s\\s\\*(", tagp.tagname); - if (!do_search(NULL, '/', '/', (char *)pbuf, (long)1, search_options, NULL)) { + snprintf(pbuf, LSIZE, "^%s\\s\\*(", tagp.tagname); + if (!do_search(NULL, '/', '/', pbuf, (long)1, search_options, NULL)) { // Guess again: "^char * \<func (" - snprintf((char *)pbuf, LSIZE, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(", + snprintf(pbuf, LSIZE, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(", tagp.tagname); - if (!do_search(NULL, '/', '/', (char *)pbuf, (long)1, - search_options, NULL)) { + if (!do_search(NULL, '/', '/', pbuf, (long)1, search_options, NULL)) { found = 0; } } @@ -3052,7 +3051,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) secure = 1; sandbox++; curwin->w_cursor.lnum = 1; // start command in line 1 - do_cmdline_cmd((char *)pbuf); + do_cmdline_cmd(pbuf); retval = OK; // When the command has done something that is not allowed make sure @@ -3180,17 +3179,17 @@ static int test_for_current(char *fname, char *fname_end, char *tag_fname, char // Find the end of the tagaddress. // Return OK if ";\"" is following, FAIL otherwise. -static int find_extra(char_u **pp) +static int find_extra(char **pp) { - char_u *str = *pp; - char_u first_char = **pp; + char *str = *pp; + char first_char = **pp; // Repeat for addresses separated with ';' for (;;) { if (ascii_isdigit(*str)) { - str = (char_u *)skipdigits((char *)str + 1); + str = skipdigits(str + 1); } else if (*str == '/' || *str == '?') { - str = (char_u *)skip_regexp((char *)str + 1, *str, false); + str = skip_regexp(str + 1, *str, false); if (*str != first_char) { str = NULL; } else { @@ -3198,7 +3197,7 @@ static int find_extra(char_u **pp) } } else { // not a line number or search string, look for terminator. - str = (char_u *)strstr((char *)str, "|;\""); + str = strstr(str, "|;\""); if (str != NULL) { str++; break; @@ -3212,7 +3211,7 @@ static int find_extra(char_u **pp) first_char = *str; } - if (str != NULL && STRNCMP(str, ";\"", 2) == 0) { + if (str != NULL && strncmp(str, ";\"", 2) == 0) { *pp = str; return OK; } @@ -3349,7 +3348,7 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) is_static = test_for_static(&tp); // Skip pseudo-tag lines. - if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0) { + if (strncmp(tp.tagname, "!_TAG_", 6) == 0) { xfree(matches[i]); continue; } @@ -3360,7 +3359,7 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) full_fname = tag_full_fname(&tp); if (add_tag_field(dict, "name", tp.tagname, (char *)tp.tagname_end) == FAIL || add_tag_field(dict, "filename", (char *)full_fname, NULL) == FAIL - || add_tag_field(dict, "cmd", (char *)tp.command, (char *)tp.command_end) == FAIL + || add_tag_field(dict, "cmd", tp.command, (char *)tp.command_end) == FAIL || add_tag_field(dict, "kind", (char *)tp.tagkind, tp.tagkind ? (char *)tp.tagkind_end : NULL) == FAIL || tv_dict_add_nr(dict, S_LEN("static"), is_static) == FAIL) { @@ -3370,18 +3369,18 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) xfree(full_fname); if (tp.command_end != NULL) { - for (char_u *p = tp.command_end + 3; + for (char *p = (char *)tp.command_end + 3; *p != NUL && *p != '\n' && *p != '\r'; MB_PTR_ADV(p)) { - if (p == tp.tagkind - || (p + 5 == tp.tagkind && STRNCMP(p, "kind:", 5) == 0)) { + if (p == (char *)tp.tagkind + || (p + 5 == (char *)tp.tagkind && strncmp(p, "kind:", 5) == 0)) { // skip "kind:<kind>" and "<kind>" - p = tp.tagkind_end - 1; - } else if (STRNCMP(p, "file:", 5) == 0) { + p = (char *)tp.tagkind_end - 1; + } else if (strncmp(p, "file:", 5) == 0) { // skip "file:" (static tag) p += 4; } else if (!ascii_iswhite(*p)) { - char_u *s, *n; + char *s, *n; int len; // Add extra field as a dict entry. Fields are @@ -3393,17 +3392,17 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) len = (int)(p - n); if (*p == ':' && len > 0) { s = ++p; - while (*p != NUL && *p >= ' ') { + while (*p != NUL && (uint8_t)(*p) >= ' ') { p++; } n[len] = NUL; - if (add_tag_field(dict, (char *)n, (char *)s, (char *)p) == FAIL) { + if (add_tag_field(dict, n, s, p) == FAIL) { ret = FAIL; } n[len] = ':'; } else { // Skip field without colon. - while (*p != NUL && *p >= ' ') { + while (*p != NUL && (uint8_t)(*p) >= ' ') { p++; } } diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 56efd4cc45..4af629d091 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -475,21 +475,21 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on /// ('e' in comment flags), so that this line is skipped, and not joined to the /// previous line. A new paragraph starts after a blank line, or when the /// comment leader changes. -static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, bool do_comments) +static int fmt_check_par(linenr_T lnum, int *leader_len, char **leader_flags, bool do_comments) { char_u *flags = NULL; // init for GCC char_u *ptr; ptr = (char_u *)ml_get(lnum); if (do_comments) { - *leader_len = get_leader_len((char *)ptr, (char **)leader_flags, false, true); + *leader_len = get_leader_len((char *)ptr, leader_flags, false, true); } else { *leader_len = 0; } if (*leader_len > 0) { // Search for 'e' flag in comment leader flags. - flags = *leader_flags; + flags = (char_u *)(*leader_flags); while (*flags && *flags != ':' && *flags != COM_END) { flags++; } @@ -589,9 +589,9 @@ static bool paragraph_start(linenr_T lnum) { char_u *p; int leader_len = 0; // leader len of current line - char_u *leader_flags = NULL; // flags for leader of current line + char *leader_flags = NULL; // flags for leader of current line int next_leader_len = 0; // leader len of next line - char_u *next_leader_flags = NULL; // flags for leader of next line + char *next_leader_flags = NULL; // flags for leader of next line if (lnum <= 1) { return true; // start of the file @@ -615,8 +615,8 @@ static bool paragraph_start(linenr_T lnum) if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) { return true; // numbered item starts in "lnum". } - if (!same_leader(lnum - 1, leader_len, (char *)leader_flags, - next_leader_len, (char *)next_leader_flags)) { + if (!same_leader(lnum - 1, leader_len, leader_flags, + next_leader_len, next_leader_flags)) { return true; // change of comment leader. } return false; @@ -924,8 +924,8 @@ void format_lines(linenr_T line_count, bool avoid_fex) bool next_is_start_par = false; int leader_len = 0; // leader len of current line int next_leader_len; // leader len of next line - char_u *leader_flags = NULL; // flags for leader of current line - char_u *next_leader_flags = NULL; // flags for leader of next line + char *leader_flags = NULL; // flags for leader of current line + char *next_leader_flags = NULL; // flags for leader of next line bool advance = true; int second_indent = -1; // indent for second line (comment aware) bool first_par_line = true; @@ -1028,14 +1028,14 @@ void format_lines(linenr_T line_count, bool avoid_fex) // When the comment leader changes, it's the end of the paragraph. if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count || !same_leader(curwin->w_cursor.lnum, - leader_len, (char *)leader_flags, + leader_len, leader_flags, next_leader_len, - (char *)next_leader_flags)) { + next_leader_flags)) { // Special case: If the next line starts with a line comment // and this line has a line comment after some text, the // paragraph doesn't really end. if (next_leader_flags == NULL - || STRNCMP(next_leader_flags, "://", 3) != 0 + || strncmp(next_leader_flags, "://", 3) != 0 || check_linecomment(get_cursor_line_ptr()) == MAXCOL) { is_end_par = true; } diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index ebb7c9d6ca..ca5307fe24 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -406,7 +406,7 @@ static void uc_list(char *name, size_t name_len) // Skip commands which don't match the requested prefix and // commands filtered out. - if (STRNCMP(name, cmd->uc_name, name_len) != 0 + if (strncmp(name, cmd->uc_name, name_len) != 0 || message_filtered(cmd->uc_name)) { continue; } @@ -570,7 +570,7 @@ int parse_addr_type_arg(char *value, int vallen, cmd_addr_T *addr_type_arg) for (i = 0; addr_type_complete[i].expand != ADDR_NONE; i++) { a = (int)strlen(addr_type_complete[i].name) == vallen; - b = STRNCMP(value, addr_type_complete[i].name, vallen) == 0; + b = strncmp(value, addr_type_complete[i].name, (size_t)vallen) == 0; if (a && b) { *addr_type_arg = addr_type_complete[i].expand; break; @@ -618,7 +618,7 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt, continue; } if ((int)strlen(command_complete[i]) == valend - && STRNCMP(value, command_complete[i], valend) == 0) { + && strncmp(value, command_complete[i], (size_t)valend) == 0) { *complp = i; if (i == EXPAND_BUFFERS) { *argt |= EX_BUFNAME; @@ -848,7 +848,7 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, cmd = USER_CMD_GA(gap, i); len = strlen(cmd->uc_name); - cmp = STRNCMP(name, cmd->uc_name, name_len); + cmp = strncmp(name, cmd->uc_name, name_len); if (cmp == 0) { if (name_len < len) { cmp = -1; @@ -964,7 +964,7 @@ void ex_command(exarg_T *eap) uc_list(name, name_len); } else if (!ASCII_ISUPPER(*name)) { emsg(_("E183: User defined commands must start with an uppercase letter")); - } else if (name_len <= 4 && STRNCMP(name, "Next", name_len) == 0) { + } else if (name_len <= 4 && strncmp(name, "Next", name_len) == 0) { emsg(_("E841: Reserved name, cannot be used for user defined command")); } else if (compl > 0 && (argt & EX_EXTRA) == 0) { emsg(_(e_complete_used_without_allowing_arguments)); @@ -1007,7 +1007,7 @@ void ex_delcommand(exarg_T *eap) const char *arg = eap->arg; bool buffer_only = false; - if (STRNCMP(arg, "-buffer", 7) == 0 && ascii_iswhite(arg[7])) { + if (strncmp(arg, "-buffer", 7) == 0 && ascii_iswhite(arg[7])) { buffer_only = true; arg = skipwhite(arg + 7); } diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 50b186c750..3a927d6a55 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -195,13 +195,11 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext() // defines to avoid typecasts from (char_u *) to (char *) and back // (vim_strchr() is now in strings.c) -#ifdef HAVE_STRNLEN -# define STRNLEN(s, n) strnlen((char *)(s), (size_t)(n)) -#else -# define STRNLEN(s, n) xstrnlen((char *)(s), (size_t)(n)) +#ifndef HAVE_STRNLEN +# define strnlen xstrnlen // Older versions of SunOS may not have strnlen #endif -#define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) -#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s), (size_t)(n)) + +#define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) // NOLINT(runtime/printf) #define STRLCPY(d, s, n) xstrlcpy((char *)(d), (char *)(s), (size_t)(n)) #define STRNCMP(d, s, n) strncmp((char *)(d), (char *)(s), (size_t)(n)) #ifdef HAVE_STRCASECMP diff --git a/src/nvim/window.c b/src/nvim/window.c index aacf30712a..3d10f89a2c 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -543,7 +543,7 @@ wingotofile: // Make a copy, if the line was changed it will be freed. ptr = xstrnsave(ptr, len); - find_pattern_in_path((char_u *)ptr, 0, len, true, Prenum == 0, + find_pattern_in_path(ptr, 0, len, true, Prenum == 0, type, Prenum1, ACTION_SPLIT, 1, MAXLNUM); xfree(ptr); curwin->w_set_curswant = true; @@ -6799,9 +6799,9 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u // Also accept " line 999" with and without the same translation as // used in last_set_msg(). char *p = ptr + len; - if (STRNCMP(p, line_english, strlen(line_english)) == 0) { + if (strncmp(p, line_english, strlen(line_english)) == 0) { p += strlen(line_english); - } else if (STRNCMP(p, line_transl, strlen(line_transl)) == 0) { + } else if (strncmp(p, line_transl, strlen(line_transl)) == 0) { p += strlen(line_transl); } else { p = skipwhite(p); |