From 0344bfad0fc87d2e256ea2b80de7abd069ba1dd2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:17:40 +0100 Subject: refactor: replace char_u with char 22 (#21786) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/buffer.c | 2 +- src/nvim/charset.c | 14 +++---- src/nvim/cmdexpand.c | 10 ++--- src/nvim/cmdhist.c | 18 ++++----- src/nvim/diff.c | 4 +- src/nvim/digraph.c | 4 +- src/nvim/drawline.c | 38 +++++++++--------- src/nvim/edit.c | 4 +- src/nvim/eval.c | 12 +++--- src/nvim/eval/executor.c | 2 +- src/nvim/eval/funcs.c | 20 +++++----- src/nvim/eval/userfunc.c | 12 +++--- src/nvim/eval/vars.c | 20 +++++----- src/nvim/ex_cmds.c | 14 +++---- src/nvim/ex_docmd.c | 56 +++++++++++++-------------- src/nvim/ex_eval.c | 7 ++-- src/nvim/ex_getln.c | 20 +++++----- src/nvim/fileio.c | 93 ++++++++++++++++++++++---------------------- src/nvim/fold.c | 2 +- src/nvim/garray.c | 4 +- src/nvim/getchar.c | 6 +-- src/nvim/help.c | 10 ++--- src/nvim/highlight_group.c | 6 +-- src/nvim/indent_c.c | 2 +- src/nvim/insexpand.c | 12 +++--- src/nvim/lua/spell.c | 2 +- src/nvim/mbyte.c | 14 +++---- src/nvim/memline.c | 4 +- src/nvim/mouse.c | 54 +++++++++++++------------- src/nvim/normal.c | 4 +- src/nvim/ops.c | 78 ++++++++++++++++++------------------- src/nvim/option.c | 24 ++++++------ src/nvim/optionstr.c | 10 ++--- src/nvim/os/env.c | 4 +- src/nvim/os/fs.c | 7 ++-- src/nvim/os/shell.c | 6 +-- src/nvim/path.c | 88 +++++++++++++++++++++--------------------- src/nvim/quickfix.c | 22 +++++------ src/nvim/regexp.c | 14 +++---- src/nvim/regexp_bt.c | 6 +-- src/nvim/regexp_nfa.c | 4 +- src/nvim/screen.c | 22 +++++------ src/nvim/search.c | 56 +++++++++++++-------------- src/nvim/spell.c | 94 ++++++++++++++++++++++----------------------- src/nvim/spellfile.c | 96 +++++++++++++++++++++++----------------------- src/nvim/spellsuggest.c | 12 +++--- src/nvim/statusline.c | 4 +- src/nvim/strings.c | 4 +- src/nvim/syntax.c | 4 +- src/nvim/tag.c | 4 +- src/nvim/testing.c | 8 ++-- src/nvim/undo.c | 4 +- src/nvim/usercmd.c | 2 +- src/nvim/window.c | 24 ++++++------ 54 files changed, 532 insertions(+), 535 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 3f93d85624..bc0bd9e004 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3829,7 +3829,7 @@ static int chk_modeline(linenr_T lnum, int flags) && (s[0] != 'V' || strncmp(skipwhite(e + 1), "set", 3) == 0) && (s[3] == ':' - || (VIM_VERSION_100 >= vers && isdigit(s[3])) + || (VIM_VERSION_100 >= vers && isdigit((uint8_t)s[3])) || (VIM_VERSION_100 < vers && s[3] == '<') || (VIM_VERSION_100 > vers && s[3] == '>') || (VIM_VERSION_100 == vers && s[3] == '='))) { diff --git a/src/nvim/charset.c b/src/nvim/charset.c index aa2d845728..fa9aa27774 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -146,19 +146,19 @@ int buf_init_chartab(buf_T *buf, int global) // options Each option is a list of characters, character numbers or // ranges, separated by commas, e.g.: "200-210,x,#-178,-" for (i = global ? 0 : 3; i <= 3; i++) { - const char_u *p; + const char *p; if (i == 0) { // first round: 'isident' - p = (char_u *)p_isi; + p = p_isi; } else if (i == 1) { // second round: 'isprint' - p = (char_u *)p_isp; + p = p_isp; } else if (i == 2) { // third round: 'isfname' - p = (char_u *)p_isf; + p = p_isf; } else { // i == 3 // fourth round: 'iskeyword' - p = (char_u *)buf->b_p_isk; + p = buf->b_p_isk; } while (*p) { @@ -254,8 +254,8 @@ int buf_init_chartab(buf_T *buf, int global) c++; } - c = *p; - p = (char_u *)skip_to_option_part((char *)p); + c = (uint8_t)(*p); + p = skip_to_option_part(p); if ((c == ',') && (*p == NUL)) { // Trailing comma is not allowed. diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index b5956d75ab..59891e9899 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1174,7 +1174,7 @@ static bool expand_showtail(expand_T *xp) // separator, on DOS the '*' "path\*\file" must not be skipped. if (rem_backslash(s)) { s++; - } else if (vim_strchr("*?[", *s) != NULL) { + } else if (vim_strchr("*?[", (uint8_t)(*s)) != NULL) { return false; } } @@ -1405,7 +1405,7 @@ static const char *set_cmd_index(const char *cmd, exarg_T *eap, expand_T *xp, in } } // check for non-alpha command - if (p == cmd && vim_strchr("@*!=><&~#", *p) != NULL) { + if (p == cmd && vim_strchr("@*!=><&~#", (uint8_t)(*p)) != NULL) { p++; } len = (size_t)(p - cmd); @@ -1435,7 +1435,7 @@ static const char *set_cmd_index(const char *cmd, exarg_T *eap, expand_T *xp, in } if (eap->cmdidx == CMD_SIZE) { - if (*cmd == 's' && vim_strchr("cgriI", cmd[1]) != NULL) { + if (*cmd == 's' && vim_strchr("cgriI", (uint8_t)cmd[1]) != NULL) { eap->cmdidx = CMD_substitute; p = cmd + 1; } else if (cmd[0] >= 'A' && cmd[0] <= 'Z') { @@ -2171,7 +2171,7 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) // 1. skip comment lines and leading space, colons or bars const char *cmd; - for (cmd = buff; vim_strchr(" \t:|", *cmd) != NULL; cmd++) {} + for (cmd = buff; vim_strchr(" \t:|", (uint8_t)(*cmd)) != NULL; cmd++) {} xp->xp_pattern = (char *)cmd; if (*cmd == NUL) { @@ -2967,7 +2967,7 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int path = "."; } else { // For an absolute name we don't use $PATH. - if (!path_is_absolute((char_u *)pat)) { + if (!path_is_absolute(pat)) { path = vim_getenv("PATH"); } if (path == NULL) { diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index d12ac87bbb..2df82d9355 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -280,7 +280,7 @@ static HistoryType get_histtype(const char *const name, const size_t len, const } } - if (vim_strchr(":=@>?/", name[0]) != NULL && len == 1) { + if (vim_strchr(":=@>?/", (uint8_t)name[0]) != NULL && len == 1) { return hist_char2type(name[0]); } @@ -437,7 +437,7 @@ int clr_history(const int histype) /// Remove all entries matching {str} from a history. /// /// @param histype may be one of the HIST_ values. -static int del_history_entry(int histype, char_u *str) +static int del_history_entry(int histype, char *str) { if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL || hisidx[histype] < 0) { @@ -446,7 +446,7 @@ static int del_history_entry(int histype, char_u *str) const int idx = hisidx[histype]; regmatch_T regmatch; - regmatch.regprog = vim_regcomp((char *)str, RE_MAGIC + RE_STRING); + regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING); if (regmatch.regprog == NULL) { return false; } @@ -560,7 +560,7 @@ void f_histdel(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // string given: remove all matching entries char buf[NUMBUFLEN]; n = del_history_entry(get_histtype(str, strlen(str), false), - (char_u *)tv_get_string_buf(&argvars[1], buf)); + (char *)tv_get_string_buf(&argvars[1], buf)); } rettv->vval.v_number = n; } @@ -611,7 +611,7 @@ void ex_history(exarg_T *eap) int idx; int i, j, k; char *end; - char_u *arg = (char_u *)eap->arg; + char *arg = eap->arg; if (hislen == 0) { msg(_("'history' option is zero")); @@ -619,12 +619,12 @@ void ex_history(exarg_T *eap) } if (!(ascii_isdigit(*arg) || *arg == '-' || *arg == ',')) { - end = (char *)arg; + end = arg; while (ASCII_ISALPHA(*end) - || vim_strchr(":=@>/?", *end) != NULL) { + || vim_strchr(":=@>/?", (uint8_t)(*end)) != NULL) { end++; } - histype1 = get_histtype((const char *)arg, (size_t)(end - (char *)arg), false); + histype1 = get_histtype(arg, (size_t)(end - arg), false); if (histype1 == HIST_INVALID) { if (STRNICMP(arg, "all", end - (char *)arg) == 0) { histype1 = 0; @@ -637,7 +637,7 @@ void ex_history(exarg_T *eap) histype2 = histype1; } } else { - end = (char *)arg; + end = arg; } if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) { semsg(_(e_trailing_arg), end); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 45f00cb41e..40be6b1abc 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1575,7 +1575,7 @@ static bool extract_hunk(FILE *fd, diffhunk_T *hunk, diffstyle_T *diffstyle) // --- file1 2018-03-20 13:23:35.783153140 +0100 // +++ file2 2018-03-20 13:23:41.183156066 +0100 // @@ -1,3 +1,5 @@ - if (isdigit(*line)) { + if (isdigit((uint8_t)(*line))) { *diffstyle = DIFF_ED; } else if ((strncmp(line, "@@ ", 3) == 0)) { *diffstyle = DIFF_UNIFIED; @@ -1593,7 +1593,7 @@ static bool extract_hunk(FILE *fd, diffhunk_T *hunk, diffstyle_T *diffstyle) } if (*diffstyle == DIFF_ED) { - if (!isdigit(*line)) { + if (!isdigit((uint8_t)(*line))) { continue; // not the start of a diff block } if (parse_diff_ed(line, hunk) == FAIL) { diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 33038dfb9f..144817fe2b 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1885,7 +1885,7 @@ static int get_digraph_chars(const typval_T *arg, int *char1, int *char2) { char buf_chars[NUMBUFLEN]; const char *chars = tv_get_string_buf_chk(arg, buf_chars); - const char_u *p = (const char_u *)chars; + const char *p = chars; if (p != NULL) { if (*p != NUL) { @@ -1917,7 +1917,7 @@ static bool digraph_set_common(const typval_T *argchars, const typval_T *argdigr if (digraph == NULL) { return false; } - const char_u *p = (const char_u *)digraph; + const char *p = digraph; int n = mb_cptr2char_adv(&p); if (*p != NUL) { semsg(_(e_digraph_argument_must_be_one_character_str), digraph); diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index ae3e5698b2..9287fdb460 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -513,7 +513,7 @@ static bool use_cursor_line_nr(win_T *wp, linenr_T lnum, int row, int startrow, && (wp->w_p_culopt_flags & CULOPT_LINE))); } -static inline void get_line_number_str(win_T *wp, linenr_T lnum, char_u *buf, size_t buf_len) +static inline void get_line_number_str(win_T *wp, linenr_T lnum, char *buf, size_t buf_len) { long num; char *fmt = "%*ld "; @@ -531,7 +531,7 @@ static inline void get_line_number_str(win_T *wp, linenr_T lnum, char_u *buf, si } } - snprintf((char *)buf, buf_len, fmt, number_width(wp), num); + snprintf(buf, buf_len, fmt, number_width(wp), num); } static int get_line_number_attr(win_T *wp, linenr_T lnum, int row, int startrow, int filler_lines) @@ -612,7 +612,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, int row; // row in the window, excl w_winrow ScreenGrid *grid = &wp->w_grid; // grid specific to the window - char_u extra[57]; // sign, line number and 'fdc' must + char extra[57]; // sign, line number and 'fdc' must // fit in here int n_extra = 0; // number of extra chars char *p_extra = NULL; // string of extra chars, plus NUL @@ -806,7 +806,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, nextline[SPWORDLEN] = NUL; if (lnum < wp->w_buffer->b_ml.ml_line_count) { line = ml_get_buf(wp->w_buffer, lnum + 1, false); - spell_cat_line(nextline + SPWORDLEN, (char_u *)line, SPWORDLEN); + spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); } // When a word wrapped from the previous line the start of the current @@ -1132,7 +1132,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // no bad word found at line start, don't check until end of a // word spell_hlf = HLF_COUNT; - word_end = (int)(spell_to_word_end((char_u *)ptr, wp) - (char_u *)line + 1); + word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); } else { // bad word found, use attributes until end of word assert(len <= INT_MAX); @@ -1278,7 +1278,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (wp->w_scwidth > 0) { get_sign_display_info(false, wp, lnum, sattrs, row, startrow, filler_lines, filler_todo, - &c_extra, &c_final, (char *)extra, sizeof(extra), + &c_extra, &c_final, extra, sizeof(extra), &p_extra, &n_extra, &char_attr, sign_idx, sign_cul_attr); sign_idx++; @@ -1303,29 +1303,29 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u' && num_signs > 0) { get_sign_display_info(true, wp, lnum, sattrs, row, startrow, filler_lines, filler_todo, - &c_extra, &c_final, (char *)extra, sizeof(extra), + &c_extra, &c_final, extra, sizeof(extra), &p_extra, &n_extra, &char_attr, sign_idx, sign_cul_attr); } else { // Draw the line number (empty space after wrapping). if (row == startrow + filler_lines) { - get_line_number_str(wp, lnum, (char_u *)extra, sizeof(extra)); + get_line_number_str(wp, lnum, extra, sizeof(extra)); if (wp->w_skipcol > 0) { - for (p_extra = (char *)extra; *p_extra == ' '; p_extra++) { + for (p_extra = extra; *p_extra == ' '; p_extra++) { *p_extra = '-'; } } if (wp->w_p_rl) { // reverse line numbers // like rl_mirror(), but keep the space at the end - char *p2 = skipwhite((char *)extra); + char *p2 = skipwhite(extra); p2 = skiptowhite(p2) - 1; - for (char *p1 = skipwhite((char *)extra); p1 < p2; p1++, p2--) { + for (char *p1 = skipwhite(extra); p1 < p2; p1++, p2--) { const char t = *p1; *p1 = *p2; *p2 = t; } } - p_extra = (char *)extra; + p_extra = extra; c_extra = NUL; } else { c_extra = ' '; @@ -1729,14 +1729,14 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, || (mb_l > 1 && (!vim_isprintc(mb_c)))) { // Illegal UTF-8 byte: display as . // Non-BMP character : display as ? or fullwidth ?. - transchar_hex((char *)extra, mb_c); + transchar_hex(extra, mb_c); if (wp->w_p_rl) { // reverse - rl_mirror((char *)extra); + rl_mirror(extra); } - p_extra = (char *)extra; + p_extra = extra; c = (uint8_t)(*p_extra); - mb_c = mb_ptr2char_adv((const char_u **)&p_extra); + mb_c = mb_ptr2char_adv((const char **)&p_extra); mb_utf8 = (c >= 0x80); n_extra = (int)strlen(p_extra); c_extra = NUL; @@ -1909,7 +1909,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, p = prev_ptr; } cap_col -= (int)(prev_ptr - line); - size_t tmplen = spell_check(wp, (char_u *)p, &spell_hlf, &cap_col, nochange); + size_t tmplen = spell_check(wp, p, &spell_hlf, &cap_col, nochange); assert(tmplen <= INT_MAX); len = (int)tmplen; word_end = (int)v + len; @@ -2075,12 +2075,12 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (c == TAB && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { int tab_len = 0; long vcol_adjusted = vcol; // removed showbreak length - char_u *const sbr = get_showbreak_value(wp); + char *const sbr = (char *)get_showbreak_value(wp); // Only adjust the tab_len, when at the first column after the // showbreak value was drawn. if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) { - vcol_adjusted = vcol - mb_charlen((char *)sbr); + vcol_adjusted = vcol - mb_charlen(sbr); } // tab amount depends on current column tab_len = tabstop_padding((colnr_T)vcol_adjusted, diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 6102f05abd..9b82d50012 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3127,7 +3127,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) // make up some named keys , , , <0>, <>>, <<>, <*>, // <:> and so that people can re-indent on o, O, e, 0, <, // >, *, : and ! keys if they really really want to. - if (vim_strchr("<>!*oOe0:", look[1]) != NULL + if (vim_strchr("<>!*oOe0:", (uint8_t)look[1]) != NULL && keytyped == look[1]) { return true; } @@ -3182,7 +3182,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) // TODO(@brammool): multi-byte if (keytyped == (int)(uint8_t)p[-1] || (icase && keytyped < 256 - && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1]))) { + && TOLOWER_LOC(keytyped) == TOLOWER_LOC((uint8_t)p[-1]))) { line = get_cursor_pos_ptr(); assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX); if ((curwin->w_cursor.col == (colnr_T)(p - look) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6d32b71016..b0805aecff 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2185,7 +2185,7 @@ int pattern_match(const char *pat, const char *text, bool ic) regmatch.regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { regmatch.rm_ic = ic; - matches = vim_regexec_nl(®match, (char_u *)text, (colnr_T)0); + matches = vim_regexec_nl(®match, (char *)text, (colnr_T)0); vim_regfree(regmatch.regprog); } p_cpo = save_cpo; @@ -2543,7 +2543,7 @@ static int eval4(char **arg, typval_T *rettv, int evaluate) if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') { len = 5; } - if (!isalnum(p[len]) && p[len] != '_') { + if (!isalnum((uint8_t)p[len]) && p[len] != '_') { type = len == 2 ? EXPR_IS : EXPR_ISNOT; } } @@ -3777,7 +3777,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) case 'U': if (ascii_isxdigit(p[1])) { int n, nr; - int c = toupper(*p); + int c = toupper((uint8_t)(*p)); if (c == 'X') { n = 2; @@ -6302,7 +6302,7 @@ int get_id_len(const char **const arg) // slice "[n:]". Also "xx:" is not a namespace. len = (int)(p - *arg); if (len > 1 - || (len == 1 && vim_strchr(namespace_char, **arg) == NULL)) { + || (len == 1 && vim_strchr(namespace_char, (uint8_t)(**arg)) == NULL)) { break; } } @@ -6430,7 +6430,7 @@ const char *find_name_end(const char *arg, const char **expr_start, const char * // slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. len = (int)(p - arg); if ((len > 1 && p[-1] != '}') - || (len == 1 && vim_strchr(namespace_char, *arg) == NULL)) { + || (len == 1 && vim_strchr(namespace_char, (uint8_t)(*arg)) == NULL)) { break; } } @@ -8081,7 +8081,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, const char if (regmatch.regprog != NULL) { char *tail = str; char *end = str + strlen(str); - while (vim_regexec_nl(®match, (char_u *)str, (colnr_T)(tail - str))) { + while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) { // Skip empty match except for first match. if (regmatch.startp[0] == regmatch.endp[0]) { if (zero_width == regmatch.startp[0]) { diff --git a/src/nvim/eval/executor.c b/src/nvim/eval/executor.c index 86d6063b01..831c468288 100644 --- a/src/nvim/eval/executor.c +++ b/src/nvim/eval/executor.c @@ -69,7 +69,7 @@ int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2, const char *cons if (tv2->v_type == VAR_LIST) { break; } - if (vim_strchr("+-*/%", *op) != NULL) { + if (vim_strchr("+-*/%", (uint8_t)(*op)) != NULL) { // nr += nr or nr -= nr, nr *= nr, nr /= nr, nr %= nr varnumber_T n = tv_get_number(tv1); if (tv2->v_type == VAR_FLOAT) { diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index d6b9ca20fc..25e026706c 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1770,7 +1770,7 @@ static void f_expand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } size_t len; char *errormsg = NULL; - char *result = (char *)eval_vars((char_u *)s, (char_u *)s, &len, NULL, &errormsg, NULL, false); + char *result = (char *)eval_vars((char *)s, (char_u *)s, &len, NULL, &errormsg, NULL, false); if (p_verbose == 0) { emsg_off--; } else if (errormsg != NULL) { @@ -4488,7 +4488,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, } } - match = vim_regexec_nl(®match, (char_u *)str, startcol); + match = vim_regexec_nl(®match, str, startcol); if (match && --nth <= 0) { break; @@ -5885,7 +5885,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) q[-1] = NUL; q = path_tail(p); } - if (q > p && !path_is_absolute((const char_u *)buf)) { + if (q > p && !path_is_absolute(buf)) { // Symlink is relative to directory of argument. Replace the // symlink with the resolved name in the same directory. const size_t p_len = strlen(p); @@ -6228,7 +6228,7 @@ static int search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp) // Repeat until {skip} returns false. for (;;) { subpatnum - = searchit(curwin, curbuf, &pos, NULL, dir, (char_u *)pat, 1, options, RE_SEARCH, &sia); + = searchit(curwin, curbuf, &pos, NULL, dir, (char *)pat, 1, options, RE_SEARCH, &sia); // finding the first match again means there is no match where {skip} // evaluates to zero. if (firstpos.lnum != 0 && equalpos(pos, firstpos)) { @@ -6810,7 +6810,7 @@ long do_searchpair(const char *spat, const char *mpat, const char *epat, int dir .sa_tm = &tm, }; - int n = searchit(curwin, curbuf, &pos, NULL, dir, (char_u *)pat, 1L, + int n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L, options, RE_SEARCH, &sia); if (n == FAIL || (firstpos.lnum != 0 && equalpos(pos, firstpos))) { // didn't find it or found the first match again: FAIL @@ -7073,7 +7073,7 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt if (csearch != NULL) { int pcc[MAX_MCO]; const int c = utfc_ptr2char((char *)csearch, pcc); - set_last_csearch(c, csearch, utfc_ptr2len((char *)csearch)); + set_last_csearch(c, (char *)csearch, utfc_ptr2len((char *)csearch)); } dictitem_T *di = tv_dict_find(d, S_LEN("forward")); @@ -7553,7 +7553,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv, EvalFuncData fptr if (str != NULL) { // Check the argument for spelling. while (*str != NUL) { - len = spell_check(curwin, (char_u *)str, &attr, &capcol, false); + len = spell_check(curwin, (char *)str, &attr, &capcol, false); if (attr != HLF_COUNT) { word = str; break; @@ -7668,7 +7668,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (*str == NUL) { match = false; // Empty item at the end. } else { - match = vim_regexec_nl(®match, (char_u *)str, col); + match = vim_regexec_nl(®match, (char *)str, col); } const char *end; if (match) { @@ -7930,11 +7930,11 @@ static void strchar_common(typval_T *argvars, typval_T *rettv, bool skipcc) { const char *s = tv_get_string(&argvars[0]); varnumber_T len = 0; - int (*func_mb_ptr2char_adv)(const char_u **pp); + int (*func_mb_ptr2char_adv)(const char **pp); func_mb_ptr2char_adv = skipcc ? mb_ptr2char_adv : mb_cptr2char_adv; while (*s != NUL) { - func_mb_ptr2char_adv((const char_u **)&s); + func_mb_ptr2char_adv(&s); len++; } rettv->vval.v_number = len; diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 1a3fd13fe3..5d3b70b414 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -118,7 +118,7 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int while (ASCII_ISALNUM(*p) || *p == '_') { p++; } - if (arg == p || isdigit(*arg) + if (arg == p || isdigit((uint8_t)(*arg)) || (p - arg == 9 && strncmp(arg, "firstline", 9) == 0) || (p - arg == 8 && strncmp(arg, "lastline", 8) == 0)) { if (!skip) { @@ -1228,7 +1228,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett /// looked up by name. static bool func_name_refcount(const char_u *name) { - return isdigit(*name) || *name == '<'; + return isdigit((uint8_t)(*name)) || *name == '<'; } /// Call a user function after checking the arguments. @@ -2002,7 +2002,7 @@ static void list_functions(regmatch_T *regmatch) && (regmatch == NULL ? (!message_filtered((char *)fp->uf_name) && !func_name_refcount((char_u *)fp->uf_name)) - : (!isdigit(*fp->uf_name) + : (!isdigit((uint8_t)(*fp->uf_name)) && vim_regexec(regmatch, (char *)fp->uf_name, 0)))) { list_func_head(fp, false, false); if (changed != func_hashtab.ht_changed) { @@ -2792,7 +2792,7 @@ void ex_delfunction(exarg_T *eap) *p = NUL; } - if (isdigit(*name) && fudi.fd_dict == NULL) { + if (isdigit((uint8_t)(*name)) && fudi.fd_dict == NULL) { if (!eap->skip) { semsg(_(e_invarg2), eap->arg); } @@ -2858,7 +2858,7 @@ void func_unref(char_u *name) } fp = find_func(name); - if (fp == NULL && isdigit(*name)) { + if (fp == NULL && isdigit((uint8_t)(*name))) { #ifdef EXITFREE if (!entered_free_all_mem) { internal_error("func_unref()"); @@ -2901,7 +2901,7 @@ void func_ref(char_u *name) fp = find_func(name); if (fp != NULL) { (fp->uf_refcount)++; - } else if (isdigit(*name)) { + } else if (isdigit((uint8_t)(*name))) { // Only give an error for a numbered function. // Fail silently, when named or lambda function isn't found. internal_error("func_ref()"); diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 206df03381..75af99fbd5 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -106,7 +106,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) return NULL; } *p = NUL; - if (islower(*marker)) { + if (islower((uint8_t)(*marker))) { emsg(_("E221: Marker cannot start with lower case letter")); return NULL; } @@ -208,7 +208,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) argend--; } expr = skipwhite(argend); - if (*expr != '=' && !((vim_strchr("+-*/%.", *expr) != NULL + if (*expr != '=' && !((vim_strchr("+-*/%.", (uint8_t)(*expr)) != NULL && expr[1] == '=') || strncmp(expr, "..=", 3) == 0)) { // ":let" without "=": list variables if (*arg == '[') { @@ -244,7 +244,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) op[0] = '='; op[1] = NUL; if (*expr != '=') { - if (vim_strchr("+-*/%.", *expr) != NULL) { + if (vim_strchr("+-*/%.", (uint8_t)(*expr)) != NULL) { op[0] = *expr; // +=, -=, *=, /=, %= or .= if (expr[0] == '.' && expr[1] == '.') { // ..= expr++; @@ -590,10 +590,10 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo if (len == 0) { semsg(_(e_invarg2), name - 1); } else { - if (op != NULL && vim_strchr("+-*/%", *op) != NULL) { + if (op != NULL && vim_strchr("+-*/%", (uint8_t)(*op)) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg)) == NULL) { + && vim_strchr(endchars, (uint8_t)(*skipwhite(arg))) == NULL) { emsg(_(e_letunexp)); } else if (!check_secure()) { char *tofree = NULL; @@ -629,7 +629,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *const p = (char *)find_option_end((const char **)&arg, &scope); if (p == NULL || (endchars != NULL - && vim_strchr(endchars, *skipwhite(p)) == NULL)) { + && vim_strchr(endchars, (uint8_t)(*skipwhite(p))) == NULL)) { emsg(_(e_letunexp)); } else { varnumber_T n = 0; @@ -716,10 +716,10 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo return NULL; } arg++; - if (op != NULL && vim_strchr("+-*/%", *op) != NULL) { + if (op != NULL && vim_strchr("+-*/%", (uint8_t)(*op)) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) { + && vim_strchr(endchars, (uint8_t)(*skipwhite(arg + 1))) == NULL) { emsg(_(e_letunexp)); } else { char *s; @@ -747,7 +747,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START); if (p != NULL && lv.ll_name != NULL) { - if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) { + if (endchars != NULL && vim_strchr(endchars, (uint8_t)(*skipwhite(p))) == NULL) { emsg(_(e_letunexp)); } else { set_var_lval(&lv, p, tv, copy, is_const, op); @@ -1464,7 +1464,7 @@ bool var_wrong_func_name(const char *const name, const bool new_var) { // Allow for w: b: s: and t:. // Allow autoload variable. - if (!(vim_strchr("wbst", name[0]) != NULL && name[1] == ':') + if (!(vim_strchr("wbst", (uint8_t)name[0]) != NULL && name[1] == ':') && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') ? name[2] : name[0]) && vim_strchr(name, '#') == NULL) { semsg(_("E704: Funcref variable name must start with a capital: %s"), name); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c2af0e6986..4ea11dd32a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -528,7 +528,7 @@ void ex_sort(exarg_T *eap) emsg(_(e_noprevre)); goto sortend; } - regmatch.regprog = vim_regcomp((char *)last_search_pat(), RE_MAGIC); + regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); } else { regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); } @@ -3332,7 +3332,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T } // new pattern and substitution if (eap->cmd[0] == 's' && *cmd != NUL && !ascii_iswhite(*cmd) - && vim_strchr("0123456789cegriIp|\"", *cmd) == NULL) { + && vim_strchr("0123456789cegriIp|\"", (uint8_t)(*cmd)) == NULL) { // don't accept alphanumeric for separator if (check_regexp_delim(*cmd) == FAIL) { return 0; @@ -3343,7 +3343,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // //sub/r). "\&sub&" use last substitute pattern (like //sub/). if (*cmd == '\\') { cmd++; - if (vim_strchr("/?&", *cmd) == NULL) { + if (vim_strchr("/?&", (uint8_t)(*cmd)) == NULL) { emsg(_(e_backslash)); return 0; } @@ -3443,7 +3443,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T return 0; } - if (search_regcomp((char_u *)pat, NULL, RE_SUBST, which_pat, + if (search_regcomp(pat, NULL, RE_SUBST, which_pat, (cmdpreview ? 0 : SEARCH_HIS), ®match) == FAIL) { if (subflags.do_error) { emsg(_(e_invcmd)); @@ -4372,7 +4372,7 @@ void ex_global(exarg_T *eap) // "\&": use previous substitute pattern. if (*cmd == '\\') { cmd++; - if (vim_strchr("/?&", *cmd) == NULL) { + if (vim_strchr("/?&", (uint8_t)(*cmd)) == NULL) { emsg(_(e_backslash)); return; } @@ -4398,8 +4398,8 @@ void ex_global(exarg_T *eap) } } - char_u *used_pat; - if (search_regcomp((char_u *)pat, &used_pat, RE_BOTH, which_pat, + char *used_pat; + if (search_regcomp(pat, &used_pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) { emsg(_(e_invcmd)); return; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 511251f0b5..896130debf 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2852,7 +2852,7 @@ bool checkforcmd(char **pp, const char *cmd, int len) break; } } - if (i >= len && !isalpha((*pp)[i])) { + if (i >= len && !isalpha((uint8_t)(*pp)[i])) { *pp = skipwhite(*pp + i); return true; } @@ -2877,7 +2877,7 @@ static void append_command(char *cmd) STRCAT(IObuff, ": "); d = IObuff + strlen(IObuff); while (*s != NUL && d - IObuff + 5 < IOSIZE) { - if ((char_u)s[0] == 0xc2 && (char_u)s[1] == 0xa0) { + if ((uint8_t)s[0] == 0xc2 && (uint8_t)s[1] == 0xa0) { s += 2; STRCPY(d, ""); d += 4; @@ -2942,7 +2942,7 @@ char *find_ex_command(exarg_T *eap, int *full) } // check for non-alpha command - if (p == eap->cmd && vim_strchr("@!=><&~#", *p) != NULL) { + if (p == eap->cmd && vim_strchr("@!=><&~#", (uint8_t)(*p)) != NULL) { p++; } int len = (int)(p - eap->cmd); @@ -2967,7 +2967,7 @@ char *find_ex_command(exarg_T *eap, int *full) } if (ASCII_ISLOWER(eap->cmd[0])) { - const int c1 = (char_u)eap->cmd[0]; + const int c1 = (uint8_t)eap->cmd[0]; const int c2 = len == 1 ? NUL : eap->cmd[1]; if (command_count != CMD_SIZE) { @@ -3172,7 +3172,7 @@ uint32_t excmd_get_argt(cmdidx_T idx) /// @return the "cmd" pointer advanced to beyond the range. char *skip_range(const char *cmd, int *ctx) { - while (vim_strchr(" \t0123456789.$%'/?-+,;\\", *cmd) != NULL) { + while (vim_strchr(" \t0123456789.$%'/?-+,;\\", (uint8_t)(*cmd)) != NULL) { if (*cmd == '\\') { if (cmd[1] == '?' || cmd[1] == '/' || cmd[1] == '&') { cmd++; @@ -3361,7 +3361,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int case '/': case '?': // '/' or '?' - search - c = (char_u)(*cmd++); + c = (uint8_t)(*cmd++); if (addr_type != ADDR_LINES) { addr_error(addr_type); cmd = NULL; @@ -3434,7 +3434,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int pos.coladd = 0; if (searchit(curwin, curbuf, &pos, NULL, *cmd == '?' ? BACKWARD : FORWARD, - (char_u *)"", 1L, SEARCH_MSG, i, NULL) != FAIL) { + "", 1L, SEARCH_MSG, i, NULL) != FAIL) { lnum = pos.lnum; } else { cmd = NULL; @@ -3495,7 +3495,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int if (ascii_isdigit(*cmd)) { i = '+'; // "number" is same as "+number" } else { - i = (char_u)(*cmd++); + i = (uint8_t)(*cmd++); } if (!ascii_isdigit(*cmd)) { // '+' is '+1' n = 1; @@ -3542,7 +3542,7 @@ error: /// Get flags from an Ex command argument. static void get_flags(exarg_T *eap) { - while (vim_strchr("lp#", *eap->arg) != NULL) { + while (vim_strchr("lp#", (uint8_t)(*eap->arg)) != NULL) { if (*eap->arg == 'l') { eap->flags |= EXFLAG_LIST; } else if (*eap->arg == 'p') { @@ -3759,7 +3759,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) } // Quick check if this cannot be the start of a special string. // Also removes backslash before '%', '#' and '<'. - if (vim_strchr("%#<", *p) == NULL) { + if (vim_strchr("%#<", (uint8_t)(*p)) == NULL) { p++; continue; } @@ -3767,7 +3767,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) // Try to find a match at this position. size_t srclen; int escaped; - char *repl = (char *)eval_vars((char_u *)p, (char_u *)eap->arg, &srclen, &(eap->do_ecmd_lnum), + char *repl = (char *)eval_vars(p, (char_u *)eap->arg, &srclen, &(eap->do_ecmd_lnum), errormsgp, &escaped, true); if (*errormsgp != NULL) { // error detected return FAIL; @@ -3812,7 +3812,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) #endif for (l = repl; *l; l++) { - if (vim_strchr((char *)ESCAPE_CHARS, *l) != NULL) { + if (vim_strchr((char *)ESCAPE_CHARS, (uint8_t)(*l)) != NULL) { l = vim_strsave_escaped(repl, (char *)ESCAPE_CHARS); xfree(repl); repl = l; @@ -4044,15 +4044,15 @@ char *skip_cmd_arg(char *p, int rembs) return p; } -int get_bad_opt(const char_u *p, exarg_T *eap) +int get_bad_opt(const char *p, exarg_T *eap) FUNC_ATTR_NONNULL_ALL { if (STRICMP(p, "keep") == 0) { eap->bad_char = BAD_KEEP; } else if (STRICMP(p, "drop") == 0) { eap->bad_char = BAD_DROP; - } else if (MB_BYTE2LEN(*p) == 1 && p[1] == NUL) { - eap->bad_char = *p; + } else if (MB_BYTE2LEN((uint8_t)(*p)) == 1 && p[1] == NUL) { + eap->bad_char = (uint8_t)(*p); } else { return FAIL; } @@ -4129,7 +4129,7 @@ static int getargopt(exarg_T *eap) if (check_ff_value(eap->cmd + eap->force_ff) == FAIL) { return FAIL; } - eap->force_ff = (char_u)eap->cmd[eap->force_ff]; + eap->force_ff = (uint8_t)eap->cmd[eap->force_ff]; } else if (pp == &eap->force_enc) { // Make 'fileencoding' lower case. for (char *p = eap->cmd + eap->force_enc; *p != NUL; p++) { @@ -4138,7 +4138,7 @@ static int getargopt(exarg_T *eap) } else { // Check ++bad= argument. Must be a single-byte character, "keep" or // "drop". - if (get_bad_opt((char_u *)eap->cmd + bad_char_idx, eap) == FAIL) { + if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) { return FAIL; } } @@ -6002,7 +6002,7 @@ static void ex_later(exarg_T *eap) if (*p == NUL) { count = 1; - } else if (isdigit(*p)) { + } else if (isdigit((uint8_t)(*p))) { count = getdigits_long(&p, false, 0); switch (*p) { case 's': @@ -6060,7 +6060,7 @@ static void ex_redir(exarg_T *eap) close_redir(); arg++; if (valid_yank_reg(*arg, true) && *arg != '_') { - redir_reg = (char_u)(*arg++); + redir_reg = (uint8_t)(*arg++); if (*arg == '>' && arg[1] == '>') { // append arg += 2; } else { @@ -6725,7 +6725,7 @@ ssize_t find_cmdline_var(const char *src, size_t *usedlen) /// @return an allocated string if a valid match was found. /// Returns NULL if no match was found. "usedlen" then still contains the /// number of characters to skip. -char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T *lnump, +char_u *eval_vars(char *src, const char_u *srcstart, size_t *usedlen, linenr_T *lnump, char **errormsg, int *escaped, bool empty_is_error) { char *result; @@ -6742,7 +6742,7 @@ char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T } // Check if there is something to do. - ssize_t spec_idx = find_cmdline_var((char *)src, usedlen); + ssize_t spec_idx = find_cmdline_var(src, usedlen); if (spec_idx < 0) { // no match *usedlen = 1; return NULL; @@ -6750,7 +6750,7 @@ char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T // Skip when preceded with a backslash "\%" and "\#". // Note: In "\\%" the % is also not recognized! - if (src > srcstart && src[-1] == '\\') { + if ((char_u *)src > srcstart && src[-1] == '\\') { *usedlen = 0; STRMOVE(src - 1, (char *)src); // remove backslash return NULL; @@ -6800,16 +6800,16 @@ char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T skip_mod = true; break; } - char *s = (char *)src + 1; + char *s = src + 1; if (*s == '<') { // "#<99" uses v:oldfiles. s++; } int i = getdigits_int(&s, false, 0); - if ((char_u *)s == src + 2 && src[1] == '-') { + if (s == src + 2 && src[1] == '-') { // just a minus sign, don't skip over it s--; } - *usedlen = (size_t)((char_u *)s - src); // length of what we expand + *usedlen = (size_t)(s - src); // length of what we expand if (src[1] == '<' && i != 0) { if (*usedlen < 2) { @@ -6855,7 +6855,7 @@ char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T case SPEC_AFILE: // file name for autocommand if (autocmd_fname != NULL - && !path_is_absolute((char_u *)autocmd_fname) + && !path_is_absolute(autocmd_fname) // For CmdlineEnter and related events, is not a path! #9348 && !strequal("/", autocmd_fname)) { // Still need to turn the fname into a full path. It was @@ -6962,7 +6962,7 @@ char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T resultlen = (size_t)(s - result); } } else if (!skip_mod) { - valid |= modify_fname((char *)src, tilde_file, usedlen, &result, + valid |= modify_fname(src, tilde_file, usedlen, &result, &resultbuf, &resultlen); if (result == NULL) { *errormsg = ""; @@ -7002,7 +7002,7 @@ char *expand_sfile(char *arg) // replace "" with the sourced file name, and do ":" stuff size_t srclen; char *errormsg; - char *repl = (char *)eval_vars((char_u *)p, (char_u *)result, &srclen, NULL, &errormsg, NULL, + char *repl = (char *)eval_vars(p, (char_u *)result, &srclen, NULL, &errormsg, NULL, true); if (errormsg != NULL) { if (*errormsg) { diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 6450892e39..bfbb6f89b5 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -449,8 +449,8 @@ static int throw_exception(void *value, except_type_T type, char *cmdname) // when no active try block is found, see do_cmdline(). if (type == ET_USER) { if (strncmp(value, "Vim", 3) == 0 - && (((char_u *)value)[3] == NUL || ((char_u *)value)[3] == ':' - || ((char_u *)value)[3] == '(')) { + && (((char *)value)[3] == NUL || ((char *)value)[3] == ':' + || ((char *)value)[3] == '(')) { emsg(_("E608: Cannot :throw exceptions with 'Vim' prefix")); goto fail; } @@ -1372,8 +1372,7 @@ void ex_catch(exarg_T *eap) // prev_got_int = got_int; got_int = false; - caught = vim_regexec_nl(®match, (char_u *)current_exception->value, - (colnr_T)0); + caught = vim_regexec_nl(®match, current_exception->value, (colnr_T)0); got_int |= prev_got_int; vim_regfree(regmatch.regprog); } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 47ee1c00ce..0a1d6b2857 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -274,7 +274,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s parse_command_modifiers(&ea, &dummy, &dummy_cmdmod, true); cmd = skip_range(ea.cmd, NULL); - if (vim_strchr("sgvl", *cmd) == NULL) { + if (vim_strchr("sgvl", (uint8_t)(*cmd)) == NULL) { goto theend; } @@ -558,7 +558,7 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s) // command line has no uppercase characters, convert // the character to lowercase if (p_ic && p_scs - && !pat_has_uppercase((char_u *)ccline.cmdbuff + skiplen)) { + && !pat_has_uppercase(ccline.cmdbuff + skiplen)) { *c = mb_tolower(*c); } if (*c == search_delim @@ -1379,7 +1379,7 @@ static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_ char save; if (search_delim == ccline.cmdbuff[skiplen]) { - pat = (char *)last_search_pattern(); + pat = last_search_pattern(); if (pat == NULL) { restore_last_search_pattern(); return FAIL; @@ -1409,7 +1409,7 @@ static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_ pat[patlen] = NUL; int found = searchit(curwin, curbuf, &t, NULL, next_match ? FORWARD : BACKWARD, - (char_u *)pat, count, search_flags, + pat, count, search_flags, RE_SEARCH, NULL); emsg_off--; pat[patlen] = save; @@ -2165,7 +2165,7 @@ static bool empty_pattern_magic(char *p, size_t len, magic_T magic_val) { // remove trailing \v and the like while (len >= 2 && p[len - 2] == '\\' - && vim_strchr("mMvVcCZ", p[len - 1]) != NULL) { + && vim_strchr("mMvVcCZ", (uint8_t)p[len - 1]) != NULL) { len -= 2; } @@ -3733,7 +3733,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) } } - cmdline_paste_str(p, literally); + cmdline_paste_str((char *)p, literally); if (allocated) { xfree(arg); } @@ -3747,19 +3747,19 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) // When "literally" is true, insert literally. // When "literally" is false, insert as typed, but don't leave the command // line. -void cmdline_paste_str(char_u *s, int literally) +void cmdline_paste_str(char *s, int literally) { int c, cv; if (literally) { - put_on_cmdline((char *)s, -1, true); + put_on_cmdline(s, -1, true); } else { while (*s != NUL) { - cv = *s; + cv = (uint8_t)(*s); if (cv == Ctrl_V && s[1]) { s++; } - c = mb_cptr2char_adv((const char_u **)&s); + c = mb_cptr2char_adv((const char **)&s); if (cv == Ctrl_V || c == ESC || c == Ctrl_C || c == CAR || c == NL || c == Ctrl_L || (c == Ctrl_BSL && *s == Ctrl_N)) { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 0ee547d124..3a7db22d2f 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -278,7 +278,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, && fname != NULL && vim_strchr(p_cpo, CPO_FNAMER) != NULL && !(flags & READ_DUMMY)) { - if (set_rw_fname((char_u *)fname, (char_u *)sfname) == FAIL) { + if (set_rw_fname(fname, sfname) == FAIL) { return FAIL; } } @@ -860,7 +860,7 @@ retry: // Skip conversion when it's already done (retry for wrong // "fileformat"). if (tmpname == NULL) { - tmpname = (char *)readfile_charconvert((char_u *)fname, (char_u *)fenc, &fd); + tmpname = readfile_charconvert(fname, fenc, &fd); if (tmpname == NULL) { // Conversion failed. Try another one. advance_fenc = true; @@ -1175,7 +1175,7 @@ retry: goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, (char_u *)ptr, (char_u *)top); + conv_error = readfile_linenr(linecnt, ptr, top); } // Deal with a bad byte and continue with the next. @@ -1287,7 +1287,7 @@ retry: goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); + conv_error = readfile_linenr(linecnt, ptr, (char *)p); } if (bad_char_behavior == BAD_DROP) { continue; @@ -1315,7 +1315,7 @@ retry: goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); + conv_error = readfile_linenr(linecnt, ptr, (char *)p); } if (bad_char_behavior == BAD_DROP) { continue; @@ -1356,7 +1356,7 @@ retry: goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); + conv_error = readfile_linenr(linecnt, ptr, (char *)p); } if (bad_char_behavior == BAD_DROP) { continue; @@ -1423,12 +1423,12 @@ retry: #ifdef HAVE_ICONV // When we did a conversion report an error. if (iconv_fd != (iconv_t)-1 && conv_error == 0) { - conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); + conv_error = readfile_linenr(linecnt, ptr, (char *)p); } #endif // Remember the first linenr with an illegal byte if (conv_error == 0 && illegal_byte == 0) { - illegal_byte = readfile_linenr(linecnt, (char_u *)ptr, p); + illegal_byte = readfile_linenr(linecnt, ptr, (char *)p); } // Drop, keep or replace the bad byte. @@ -1887,7 +1887,7 @@ failed: char_u hash[UNDO_HASH_SIZE]; sha256_finish(&sha_ctx, hash); - u_read_undo(NULL, hash, (char_u *)fname); + u_read_undo(NULL, hash, fname); } if (!read_stdin && !read_fifo && (!read_buffer || sfname != NULL)) { @@ -1958,9 +1958,9 @@ bool is_dev_fd_file(char *fname) /// @param linecnt line count before reading more bytes /// @param p start of more bytes read /// @param endp end of more bytes read -static linenr_T readfile_linenr(linenr_T linecnt, char_u *p, const char_u *endp) +static linenr_T readfile_linenr(linenr_T linecnt, char *p, const char *endp) { - char_u *s; + char *s; linenr_T lnum; lnum = curbuf->b_ml.ml_line_count - linecnt + 1; @@ -2040,7 +2040,7 @@ static char *next_fenc(char **pp, bool *alloced) *pp = NULL; return ""; } - p = vim_strchr((*pp), ','); + p = vim_strchr(*pp, ','); if (p == NULL) { r = enc_canonize(*pp); *pp += strlen(*pp); @@ -2065,22 +2065,22 @@ static char *next_fenc(char **pp, bool *alloced) /// /// @return name of the resulting converted file (the caller should delete it after reading it). /// Returns NULL if the conversion failed ("*fdp" is not set) . -static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp) +static char *readfile_charconvert(char *fname, char *fenc, int *fdp) { - char_u *tmpname; + char *tmpname; char *errmsg = NULL; - tmpname = (char_u *)vim_tempname(); + tmpname = vim_tempname(); if (tmpname == NULL) { errmsg = _("Can't find temp file for conversion"); } else { close(*fdp); // close the input file, ignore errors *fdp = -1; - if (eval_charconvert((char *)fenc, "utf-8", - (char *)fname, (char *)tmpname) == FAIL) { + if (eval_charconvert(fenc, "utf-8", + fname, tmpname) == FAIL) { errmsg = _("Conversion with 'charconvert' failed"); } - if (errmsg == NULL && (*fdp = os_open((char *)tmpname, O_RDONLY, 0)) < 0) { + if (errmsg == NULL && (*fdp = os_open(tmpname, O_RDONLY, 0)) < 0) { errmsg = _("can't read output of 'charconvert'"); } } @@ -2090,14 +2090,14 @@ static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp) // another type of conversion might still work. msg(errmsg); if (tmpname != NULL) { - os_remove((char *)tmpname); // delete converted file + os_remove(tmpname); // delete converted file XFREE_CLEAR(tmpname); } } // If the input file is closed, open it (caller should check for error). if (*fdp < 0) { - *fdp = os_open((char *)fname, O_RDONLY, 0); + *fdp = os_open(fname, O_RDONLY, 0); } return tmpname; @@ -2254,7 +2254,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en && !filtering && (!append || vim_strchr(p_cpo, CPO_FNAMEAPP) != NULL) && vim_strchr(p_cpo, CPO_FNAMEW) != NULL) { - if (set_rw_fname((char_u *)fname, (char_u *)sfname) == FAIL) { + if (set_rw_fname(fname, sfname) == FAIL) { return FAIL; } buf = curbuf; // just in case autocmds made "buf" invalid @@ -2572,7 +2572,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en // If 'backupskip' is not empty, don't make a backup for some files. dobackup = (p_wb || p_bk || *p_pm != NUL); - if (dobackup && *p_bsk != NUL && match_file_list(p_bsk, (char_u *)sfname, (char_u *)ffname)) { + if (dobackup && *p_bsk != NUL && match_file_list((char *)p_bsk, sfname, ffname)) { dobackup = false; } @@ -3652,7 +3652,7 @@ nofail: /// Set the name of the current buffer. Use when the buffer doesn't have a /// name and a ":r" or ":w" command with a file name is used. -static int set_rw_fname(char_u *fname, char_u *sfname) +static int set_rw_fname(char *fname, char *sfname) { buf_T *buf = curbuf; @@ -3670,7 +3670,7 @@ static int set_rw_fname(char_u *fname, char_u *sfname) return FAIL; } - if (setfname(curbuf, (char *)fname, (char *)sfname, false) == OK) { + if (setfname(curbuf, fname, sfname, false) == OK) { curbuf->b_flags |= BF_NOTEDITED; } @@ -4205,7 +4205,7 @@ static int make_bom(char_u *buf, char_u *name) /// /// For buffers that have buftype "nofile" or "scratch": never change the file /// name. -void shorten_buf_fname(buf_T *buf, char_u *dirname, int force) +void shorten_buf_fname(buf_T *buf, char *dirname, int force) { char *p; @@ -4214,11 +4214,11 @@ void shorten_buf_fname(buf_T *buf, char_u *dirname, int force) && !path_with_url(buf->b_fname) && (force || buf->b_sfname == NULL - || path_is_absolute((char_u *)buf->b_sfname))) { + || path_is_absolute(buf->b_sfname))) { if (buf->b_sfname != buf->b_ffname) { XFREE_CLEAR(buf->b_sfname); } - p = path_shorten_fname(buf->b_ffname, (char *)dirname); + p = path_shorten_fname(buf->b_ffname, dirname); if (p != NULL) { buf->b_sfname = xstrdup(p); buf->b_fname = buf->b_sfname; @@ -4236,7 +4236,7 @@ void shorten_fnames(int force) os_dirname((char *)dirname, MAXPATHL); FOR_ALL_BUFFERS(buf) { - shorten_buf_fname(buf, dirname, force); + shorten_buf_fname(buf, (char *)dirname, force); // Always make the swap file name a full path, a "nofile" buffer may // also have a swap file. @@ -4552,7 +4552,7 @@ int vim_rename(const char *from, const char *to) } if (use_tmp_file) { - char_u tempname[MAXPATHL + 1]; + char tempname[MAXPATHL + 1]; // Find a name that doesn't exist and is in the same directory. // Rename "from" to "tempname" and then rename "tempname" to "to". @@ -4561,17 +4561,17 @@ int vim_rename(const char *from, const char *to) } STRCPY(tempname, from); for (n = 123; n < 99999; n++) { - char *tail = path_tail((char *)tempname); - snprintf(tail, (size_t)((MAXPATHL + 1) - (tail - (char *)tempname - 1)), "%d", n); + char *tail = path_tail(tempname); + snprintf(tail, (size_t)((MAXPATHL + 1) - (tail - tempname - 1)), "%d", n); - if (!os_path_exists((char *)tempname)) { - if (os_rename((char_u *)from, tempname) == OK) { - if (os_rename(tempname, (char_u *)to) == OK) { + if (!os_path_exists(tempname)) { + if (os_rename(from, tempname) == OK) { + if (os_rename(tempname, to) == OK) { return 0; } // Strange, the second step failed. Try moving the // file back and return failure. - (void)os_rename(tempname, (char_u *)from); + (void)os_rename(tempname, from); return -1; } // If it fails for one temp name it will most likely fail @@ -4589,7 +4589,7 @@ int vim_rename(const char *from, const char *to) os_remove((char *)to); // First try a normal rename, return if it works. - if (os_rename((char_u *)from, (char_u *)to) == OK) { + if (os_rename(from, to) == OK) { return 0; } @@ -5317,7 +5317,7 @@ int delete_recursive(const char *name) garray_T ga; if (readdir_core(&ga, exp, NULL, NULL) == OK) { for (int i = 0; i < ga.ga_len; i++) { - vim_snprintf(NameBuff, MAXPATHL, "%s/%s", exp, ((char_u **)ga.ga_data)[i]); + vim_snprintf(NameBuff, MAXPATHL, "%s/%s", exp, ((char **)ga.ga_data)[i]); if (delete_recursive((const char *)NameBuff) != 0) { // Remember the failure but continue deleting any further // entries. @@ -5505,28 +5505,27 @@ bool match_file_pat(char *pattern, regprog_T **prog, char *fname, char *sfname, /// @param ffname full file name /// /// @return true if there was a match -bool match_file_list(char_u *list, char_u *sfname, char_u *ffname) +bool match_file_list(char *list, char *sfname, char *ffname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 3) { - char_u buf[100]; - char_u *tail; - char_u *regpat; + char buf[100]; + char *tail; + char *regpat; char allow_dirs; bool match; char *p; - tail = (char_u *)path_tail((char *)sfname); + tail = path_tail(sfname); // try all patterns in 'wildignore' - p = (char *)list; + p = list; while (*p) { - copy_option_part(&p, (char *)buf, ARRAY_SIZE(buf), ","); - regpat = (char_u *)file_pat_to_reg_pat((char *)buf, NULL, &allow_dirs, false); + copy_option_part(&p, buf, ARRAY_SIZE(buf), ","); + regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, false); if (regpat == NULL) { break; } - match = match_file_pat((char *)regpat, NULL, (char *)ffname, (char *)sfname, (char *)tail, - (int)allow_dirs); + match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs); xfree(regpat); if (match) { return true; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 6cb9e5c38d..7306131574 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -2873,7 +2873,7 @@ static void foldlevelIndent(fline_T *flp) // empty line or lines starting with a character in 'foldignore': level // depends on surrounding lines - if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, *s) != NULL) { + if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, (uint8_t)(*s)) != NULL) { // first and last line can't be undefined, use level 0 if (lnum == 1 || lnum == buf->b_ml.ml_line_count) { flp->lvl = 0; diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 0f11868031..f75210bacb 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -173,9 +173,9 @@ char *ga_concat_strings_sep(const garray_T *gap, const char *sep) /// @param gap /// /// @returns the concatenated strings -char_u *ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET +char *ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET { - return (char_u *)ga_concat_strings_sep(gap, ","); + return ga_concat_strings_sep(gap, ","); } /// Concatenate a string to a growarray which contains characters. diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b9e3b6b902..842b0b10b6 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -538,7 +538,7 @@ void AppendToRedobuffLit(const char *str, int len) // Handle a special or multibyte character. // Composing chars separately are handled separately. - const int c = mb_cptr2char_adv((const char_u **)&s); + const int c = mb_cptr2char_adv(&s); if (c < ' ' || c == DEL || (*s == NUL && (c == '0' || c == '^'))) { add_char_buff(&redobuff, Ctrl_V); } @@ -599,7 +599,7 @@ void stuffReadbuffSpec(const char *s) stuffReadbuffLen(s, 3); s += 3; } else { - int c = mb_cptr2char_adv((const char_u **)&s); + int c = mb_cptr2char_adv(&s); if (c == CAR || c == NL || c == ESC) { c = ' '; } @@ -640,7 +640,7 @@ void stuffescaped(const char *arg, bool literally) // stuff a single special character if (*arg != NUL) { - const int c = mb_cptr2char_adv((const char_u **)&arg); + const int c = mb_cptr2char_adv(&arg); if (literally && ((c < ' ' && c != TAB) || c == DEL)) { stuffcharReadbuff(Ctrl_V); } diff --git a/src/nvim/help.c b/src/nvim/help.c index 0a695a0aa7..91fda60859 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -412,7 +412,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep // And also "\_$" and "\_^". if (arg[0] == '\\' && ((arg[1] != NUL && arg[2] == NUL) - || (vim_strchr("%_z@", arg[1]) != NULL + || (vim_strchr("%_z@", (uint8_t)arg[1]) != NULL && arg[2] != NUL))) { vim_snprintf(d, IOSIZE, "/\\\\%s", arg + 1); // Check for "/\\_$", should be "/\\_\$" @@ -471,7 +471,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep // Insert '-' before and after "CTRL-X" when applicable. if (*s < ' ' || (*s == '^' && s[1] - && (ASCII_ISALPHA(s[1]) || vim_strchr("?@[\\]^", s[1]) != NULL))) { + && (ASCII_ISALPHA(s[1]) || vim_strchr("?@[\\]^", (uint8_t)s[1]) != NULL))) { if (d > IObuff && d[-1] != '_' && d[-1] != '\\') { *d++ = '_'; // prepend a '_' to make x_CTRL-x } @@ -974,12 +974,12 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool } if (in_example) { // skip over example; a non-white in the first column ends it - if (vim_strchr(" \t\n\r", IObuff[0])) { + if (vim_strchr(" \t\n\r", (uint8_t)IObuff[0])) { continue; } in_example = false; } - p1 = vim_strchr((char *)IObuff, '*'); // find first '*' + p1 = vim_strchr(IObuff, '*'); // find first '*' while (p1 != NULL) { p2 = strchr((const char *)p1 + 1, '*'); // Find second '*'. if (p2 != NULL && p2 > p1 + 1) { // Skip "*" and "**". @@ -994,7 +994,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool // followed by a white character or end-of-line. if (s == p2 && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') - && (vim_strchr(" \t\n\r", s[1]) != NULL + && (vim_strchr(" \t\n\r", (uint8_t)s[1]) != NULL || s[1] == '\0')) { *p2 = '\0'; p1++; diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 404835c4a9..2a81b4deb0 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -2921,9 +2921,9 @@ color_name_table_T color_name_table[] = { /// return the hex value or -1 if could not find a correct value RgbValue name_to_color(const char *name, int *idx) { - if (name[0] == '#' && isxdigit(name[1]) && isxdigit(name[2]) - && isxdigit(name[3]) && isxdigit(name[4]) && isxdigit(name[5]) - && isxdigit(name[6])