From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/private/helpers.c | 4 +- src/nvim/autocmd.c | 12 +-- src/nvim/buffer.c | 10 +-- src/nvim/change.c | 4 +- src/nvim/cmdexpand.c | 16 ++-- src/nvim/context.c | 2 +- src/nvim/debugger.c | 8 +- src/nvim/diff.c | 58 +++++++------- src/nvim/drawline.c | 4 +- src/nvim/edit.c | 2 +- src/nvim/eval.c | 8 +- src/nvim/eval/funcs.c | 4 +- src/nvim/eval/userfunc.c | 34 ++++---- src/nvim/eval/vars.c | 6 +- src/nvim/ex_docmd.c | 26 +++---- src/nvim/ex_eval.c | 4 +- src/nvim/ex_getln.c | 42 +++++----- src/nvim/file_search.c | 8 +- src/nvim/fileio.c | 4 +- src/nvim/fold.c | 20 ++--- src/nvim/getchar.c | 2 +- src/nvim/hardcopy.c | 6 +- src/nvim/hashtab.c | 4 +- src/nvim/help.c | 8 +- src/nvim/indent.c | 16 ++-- src/nvim/insexpand.c | 10 +-- src/nvim/mapping.c | 68 ++++++++-------- src/nvim/mbyte.c | 30 ++++---- src/nvim/memline.c | 34 ++++---- src/nvim/menu.c | 26 +++---- src/nvim/message.c | 2 +- src/nvim/normal.c | 2 +- src/nvim/ops.c | 30 ++++---- src/nvim/option.c | 28 +++---- src/nvim/optionstr.c | 6 +- src/nvim/os/env.c | 2 +- src/nvim/os/fs.c | 2 +- src/nvim/profile.c | 2 +- src/nvim/regexp.c | 5 +- src/nvim/regexp_nfa.c | 4 +- src/nvim/runtime.c | 12 +-- src/nvim/screen.c | 32 ++++---- src/nvim/search.c | 64 +++++++-------- src/nvim/shada.c | 2 +- src/nvim/sign.c | 46 +++++------ src/nvim/spell.c | 8 +- src/nvim/spellfile.c | 6 +- src/nvim/spellsuggest.c | 51 ++++++------ src/nvim/syntax.c | 12 +-- src/nvim/tag.c | 171 ++++++++++++++++++++--------------------- src/nvim/textformat.c | 24 +++--- src/nvim/usercmd.c | 12 +-- src/nvim/vim.h | 10 +-- src/nvim/window.c | 6 +- 54 files changed, 510 insertions(+), 509 deletions(-) (limited to 'src') 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 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, "", 12) == 0) { + if (strncmp(*argp, "", 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, "'; } @@ -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 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, "", 8) == 0); + bool islambda = (strncmp(name, "", 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, "", 5) == 0) { + if (strncmp(s, "s:", 2) == 0 || strncmp(s, "", 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, "", 8) == 0) { + if (strncmp(fp->uf_name, "", 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, "", 5) == 0) { + if (strncmp(name, "", 5) == 0) { // Change "" 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, "", 8) == 0) { + || strncmp(fp->uf_name, "", 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, "", 7) != 0) { + if (strncmp(p, "", 7) != 0) { p++; } else { // replace "" 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 , , , ,