diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2023-01-09 14:13:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 21:13:06 +0800 |
commit | 149209400383c673fdb4fdd1c9a7639139f17936 (patch) | |
tree | d2c4e5fa69fc302ec3050978a303f6a479f30291 | |
parent | fc2cd28547954e64ef429c83733f06fa3ee75d50 (diff) | |
download | rneovim-149209400383c673fdb4fdd1c9a7639139f17936.tar.gz rneovim-149209400383c673fdb4fdd1c9a7639139f17936.tar.bz2 rneovim-149209400383c673fdb4fdd1c9a7639139f17936.zip |
refactor: replace char_u with char 17 - remove STRLCPY (#21235)
refactor: replace char_u with char
Work on https://github.com/neovim/neovim/issues/459
43 files changed, 230 insertions, 233 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 239f2aa8ba..58abec351b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2760,7 +2760,7 @@ void buflist_list(exarg_T *eap) continue; } if (buf_spname(buf) != NULL) { - STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); + xstrlcpy(NameBuff, buf_spname(buf), MAXPATHL); } else { home_replace(buf, buf->b_fname, (char *)NameBuff, MAXPATHL, true); } @@ -3110,7 +3110,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) *p++ = '"'; if (buf_spname(curbuf) != NULL) { - STRLCPY(p, buf_spname(curbuf), IOSIZE - (p - buffer)); + xstrlcpy(p, buf_spname(curbuf), (size_t)(IOSIZE - (p - buffer))); } else { if (!fullname && curbuf->b_fname != NULL) { name = curbuf->b_fname; @@ -3436,9 +3436,9 @@ void get_rel_pos(win_T *wp, char *buf, int buflen) } below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1; if (below <= 0) { - STRLCPY(buf, (above == 0 ? _("All") : _("Bot")), buflen); + xstrlcpy(buf, (above == 0 ? _("All") : _("Bot")), (size_t)buflen); } else if (above <= 0) { - STRLCPY(buf, _("Top"), buflen); + xstrlcpy(buf, _("Top"), (size_t)buflen); } else { vim_snprintf(buf, (size_t)buflen, "%2d%%", above > 1000000L ? (int)(above / ((above + below) / 100L)) diff --git a/src/nvim/change.c b/src/nvim/change.c index 959dce6e98..e8c4af9879 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1433,7 +1433,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) leader = xmalloc((size_t)bytes); allocated = leader; // remember to free it later - STRLCPY(leader, saved_line, lead_len + 1); + xstrlcpy(leader, saved_line, (size_t)lead_len + 1); // TODO(vim): handle multi-byte and double width chars for (int li = 0; li < comment_start; li++) { diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 1fa9937fb2..a1030389a9 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1162,7 +1162,7 @@ char *addstar(char *fname, size_t len, int context) } } else { retval = xmalloc(len + 4); - STRLCPY(retval, fname, len + 1); + xstrlcpy(retval, fname, len + 1); // Don't add a star to *, ~, ~user, $var or `cmd`. // * would become **, which walks the whole tree. @@ -2650,10 +2650,10 @@ static void expand_shellcmd(char *filepat, int *num_file, char ***file, int flag if (l > MAXPATHL - 5) { break; } - STRLCPY(buf, s, l + 1); + xstrlcpy(buf, s, l + 1); add_pathsep(buf); l = strlen(buf); - STRLCPY(buf + l, pat, MAXPATHL - l); + xstrlcpy(buf + l, pat, MAXPATHL - l); // Expand matches in one directory of $PATH. ret = expand_wildcards(1, &buf, num_file, file, flags); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index f9a456a7b2..601d4f0f29 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1230,7 +1230,7 @@ void ex_diffpatch(exarg_T *eap) // have our own temp dir use that instead, it will be cleaned up when we // exit (any .rej files created). Don't change directory if we can't // return to the current. - if ((os_dirname((char_u *)dirbuf, MAXPATHL) != OK) + if ((os_dirname(dirbuf, MAXPATHL) != OK) || (os_chdir(dirbuf) != 0)) { dirbuf[0] = NUL; } else { diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 9669c0c9a1..924251a679 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -708,7 +708,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((char_u *)nextline + SPWORDLEN, (char_u *)line, SPWORDLEN); + spell_cat_line(nextline + SPWORDLEN, (char_u *)line, SPWORDLEN); } // When a word wrapped from the previous line the start of the current diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6a1c186c2b..a112a2e447 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7861,7 +7861,7 @@ repeat: if (p != NULL) { if (c == '.') { - os_dirname((char_u *)dirname, MAXPATHL); + os_dirname(dirname, MAXPATHL); if (has_homerelative) { s = xstrdup(dirname); home_replace(NULL, s, dirname, MAXPATHL, true); diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index d377508e27..d21d92d844 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -822,7 +822,7 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // Return the current directory char *cwd = xmalloc(MAXPATHL); - if (os_dirname((char_u *)cwd, MAXPATHL) != FAIL) { + if (os_dirname(cwd, MAXPATHL) != FAIL) { #ifdef BACKSLASH_IN_FILENAME slash_adjust(cwd); #endif @@ -2517,13 +2517,13 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } FALLTHROUGH; // In global directory, just need to get OS CWD. case kCdScopeInvalid: // If called without any arguments, get OS CWD. - if (os_dirname((char_u *)cwd, MAXPATHL) == FAIL) { + if (os_dirname(cwd, MAXPATHL) == FAIL) { from = ""; // Return empty string on failure. } } if (from) { - STRLCPY(cwd, from, MAXPATHL); + xstrlcpy(cwd, from, MAXPATHL); } rettv->vval.v_string = xstrdup(cwd); diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 69b074ab99..9f6aa0776c 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -260,7 +260,7 @@ int get_lambda_tv(char **arg, typval_T *rettv, bool evaluate) int varargs; int ret; char_u *start = (char_u *)skipwhite(*arg + 1); - char_u *s, *e; + char *s, *e; bool *old_eval_lavars = eval_lavars_used; bool eval_lavars = false; @@ -289,12 +289,12 @@ int get_lambda_tv(char **arg, typval_T *rettv, bool evaluate) // Get the start and the end of the expression. *arg = skipwhite((*arg) + 1); - s = (char_u *)(*arg); + s = *arg; ret = skip_expr(arg); if (ret == FAIL) { goto errret; } - e = (char_u *)(*arg); + e = *arg; *arg = skipwhite(*arg); if (**arg != '}') { semsg(_("E451: Expected }: %s"), *arg); @@ -304,7 +304,7 @@ int get_lambda_tv(char **arg, typval_T *rettv, bool evaluate) if (evaluate) { int flags = 0; - char_u *p; + char *p; garray_T newlines; char *name = (char *)get_lambda_name(); @@ -317,11 +317,11 @@ int get_lambda_tv(char **arg, typval_T *rettv, bool evaluate) // Add "return " before the expression. size_t len = (size_t)(7 + e - s + 1); - p = (char_u *)xmalloc(len); - ((char **)(newlines.ga_data))[newlines.ga_len++] = (char *)p; + p = xmalloc(len); + ((char **)(newlines.ga_data))[newlines.ga_len++] = p; STRCPY(p, "return "); - STRLCPY(p + 7, s, e - s + 1); - if (strstr((char *)p + 7, "a:") == NULL) { + xstrlcpy(p + 7, s, (size_t)(e - s) + 1); + if (strstr(p + 7, "a:") == NULL) { // No a: variables are used for sure. flags |= FC_NOARGS; } @@ -3214,7 +3214,7 @@ char *get_return_cmd(void *rettv) } STRCPY(IObuff, ":return "); - STRLCPY(IObuff + 8, s, IOSIZE - 8); + xstrlcpy(IObuff + 8, s, IOSIZE - 8); if (strlen(s) + 8 >= IOSIZE) { STRCPY(IObuff + IOSIZE - 4, "..."); } diff --git a/src/nvim/eval/window.h b/src/nvim/eval/window.h index 02e4457a1b..682a794113 100644 --- a/src/nvim/eval/window.h +++ b/src/nvim/eval/window.h @@ -31,13 +31,13 @@ typedef struct { && (curwin->w_localdir != NULL || wp->w_localdir != NULL \ || (curtab != tp && (curtab->tp_localdir != NULL || tp->tp_localdir != NULL)) \ || p_acd)) { \ - cwd_status_ = os_dirname((char_u *)cwd_, MAXPATHL); \ + cwd_status_ = os_dirname(cwd_, MAXPATHL); \ } \ /* If 'acd' is set, check we are using that directory. If yes, then */ \ /* apply 'acd' afterwards, otherwise restore the current directory. */ \ if (cwd_status_ == OK && p_acd) { \ do_autochdir(); \ - apply_acd_ = os_dirname((char_u *)autocwd_, MAXPATHL) == OK && strcmp(cwd_, autocwd_) == 0; \ + apply_acd_ = os_dirname(autocwd_, MAXPATHL) == OK && strcmp(cwd_, autocwd_) == 0; \ } \ switchwin_T switchwin_; \ if (switch_win_noblock(&switchwin_, wp_, (tp), true) == OK) { \ diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 6c38fd962a..7921fe0fc2 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5104,7 +5104,7 @@ static void ex_tabs(exarg_T *eap) msg_putchar(bufIsChanged(wp->w_buffer) ? '+' : ' '); msg_putchar(' '); if (buf_spname(wp->w_buffer) != NULL) { - STRLCPY(IObuff, buf_spname(wp->w_buffer), IOSIZE); + xstrlcpy(IObuff, buf_spname(wp->w_buffer), IOSIZE); } else { home_replace(wp->w_buffer, wp->w_buffer->b_fname, (char *)IObuff, IOSIZE, true); } @@ -5497,7 +5497,7 @@ static void post_chdir(CdScope scope, bool trigger_dirchanged) } char cwd[MAXPATHL]; - if (os_dirname((char_u *)cwd, MAXPATHL) != OK) { + if (os_dirname(cwd, MAXPATHL) != OK) { return; } switch (scope) { @@ -5544,7 +5544,7 @@ bool changedir_func(char *new_dir, CdScope scope) new_dir = pdir; } - if (os_dirname((char_u *)NameBuff, MAXPATHL) == OK) { + if (os_dirname(NameBuff, MAXPATHL) == OK) { pdir = xstrdup(NameBuff); } else { pdir = NULL; @@ -5627,7 +5627,7 @@ void ex_cd(exarg_T *eap) /// ":pwd". static void ex_pwd(exarg_T *eap) { - if (os_dirname((char_u *)NameBuff, MAXPATHL) == OK) { + if (os_dirname(NameBuff, MAXPATHL) == OK) { #ifdef BACKSLASH_IN_FILENAME slash_adjust(NameBuff); #endif @@ -6851,7 +6851,7 @@ char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T // postponed to avoid a delay when <afile> is not used. result = FullName_save(autocmd_fname, false); // Copy into `autocmd_fname`, don't reassign it. #8165 - STRLCPY(autocmd_fname, result, MAXPATHL); + xstrlcpy(autocmd_fname, result, MAXPATHL); xfree(result); } result = autocmd_fname; diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index ed83725740..137e94145a 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -559,7 +559,7 @@ static void discard_exception(except_T *excp, bool was_finished) } else { verbose_leave(); } - STRLCPY(IObuff, saved_IObuff, IOSIZE); + xstrlcpy(IObuff, saved_IObuff, IOSIZE); xfree(saved_IObuff); } if (excp->type != ET_INTERRUPT) { diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 2a80537a50..7bed8d5288 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -1007,7 +1007,7 @@ void ex_mkrc(exarg_T *eap) // // Change to session file's dir. // - if (os_dirname(dirnow, MAXPATHL) == FAIL + if (os_dirname((char *)dirnow, MAXPATHL) == FAIL || os_chdir((char *)dirnow) != 0) { *dirnow = NUL; } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 32d7c52749..b1742c04c3 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -290,7 +290,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i if (!vim_isAbsName((char_u *)rel_fname) && len + 1 < MAXPATHL) { // Make the start dir an absolute path name. - STRLCPY(ff_expand_buffer, rel_fname, len + 1); + xstrlcpy(ff_expand_buffer, rel_fname, len + 1); search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, false); } else { search_ctx->ffsc_start_dir = xstrnsave(rel_fname, len); @@ -315,7 +315,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i path += 2; } else // NOLINT(readability/braces) #endif - if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == FAIL) { + if (os_dirname(ff_expand_buffer, MAXPATHL) == FAIL) { goto error_return; } @@ -815,7 +815,7 @@ char_u *vim_findfile(void *search_ctx_arg) if (!path_with_url(file_path)) { simplify_filename((char_u *)file_path); } - if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == OK) { + if (os_dirname(ff_expand_buffer, MAXPATHL) == OK) { p = path_shorten_fname(file_path, ff_expand_buffer); if (p != NULL) { STRMOVE(file_path, p); @@ -1071,7 +1071,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char *fname, char *wc_p // For a URL we only compare the name, otherwise we compare the // device/inode. if (path_with_url(fname)) { - STRLCPY(ff_expand_buffer, fname, MAXPATHL); + xstrlcpy(ff_expand_buffer, fname, MAXPATHL); url = true; } else { ff_expand_buffer[0] = NUL; @@ -1580,10 +1580,10 @@ int vim_chdirfile(char *fname, CdCause cause) { char dir[MAXPATHL]; - STRLCPY(dir, fname, MAXPATHL); + xstrlcpy(dir, fname, MAXPATHL); *path_tail_with_sep(dir) = NUL; - if (os_dirname((char_u *)NameBuff, sizeof(NameBuff)) != OK) { + if (os_dirname(NameBuff, sizeof(NameBuff)) != OK) { NameBuff[0] = NUL; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 55ead4ae08..6ebc382ab5 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4234,7 +4234,7 @@ void shorten_fnames(int force) { char_u dirname[MAXPATHL]; - os_dirname(dirname, MAXPATHL); + os_dirname((char *)dirname, MAXPATHL); FOR_ALL_BUFFERS(buf) { shorten_buf_fname(buf, dirname, force); @@ -4281,7 +4281,7 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) // (we need the full path in case :cd is used). if (fname == NULL || *fname == NUL) { retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL - if (os_dirname((char_u *)retval, MAXPATHL) == FAIL + if (os_dirname(retval, MAXPATHL) == FAIL || strlen(retval) == 0) { xfree(retval); return NULL; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 8b773b2eee..4ac96cdfd2 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1615,7 +1615,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark STRCPY(newline, line); // Append the marker to the end of the line if (p == NULL || line_is_comment) { - STRLCPY(newline + line_len, marker, markerlen + 1); + xstrlcpy(newline + line_len, marker, markerlen + 1); added = markerlen; } else { STRCPY(newline + line_len, cms); diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 1beabb6111..5a2589cc66 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -244,7 +244,7 @@ static void add_buff(buffheader_T *const buf, const char *const s, ptrdiff_t sle size_t len; if (buf->bh_space >= (size_t)slen) { len = strlen(buf->bh_curr->b_str); - STRLCPY(buf->bh_curr->b_str + len, s, slen + 1); + xstrlcpy(buf->bh_curr->b_str + len, s, (size_t)slen + 1); buf->bh_space -= (size_t)slen; } else { if (slen < MINIMAL_SIZE) { @@ -254,7 +254,7 @@ static void add_buff(buffheader_T *const buf, const char *const s, ptrdiff_t sle } buffblock_T *p = xmalloc(sizeof(buffblock_T) + len); buf->bh_space = len - (size_t)slen; - STRLCPY(p->b_str, s, slen + 1); + xstrlcpy(p->b_str, s, (size_t)slen + 1); p->b_next = buf->bh_curr->b_next; buf->bh_curr->b_next = p; diff --git a/src/nvim/help.c b/src/nvim/help.c index 2095925db3..af28c37910 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -880,7 +880,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool bool mix = false; // detected mixed encodings // Find all *.txt files. - size_t dirlen = STRLCPY(NameBuff, dir, sizeof(NameBuff)); + size_t dirlen = xstrlcpy(NameBuff, dir, sizeof(NameBuff)); if (dirlen >= MAXPATHL || xstrlcat(NameBuff, "/**/*", sizeof(NameBuff)) >= MAXPATHL // NOLINT || xstrlcat(NameBuff, ext, sizeof(NameBuff)) >= MAXPATHL) { @@ -1089,7 +1089,7 @@ static void do_helptags(char *dirname, bool add_help_tags, bool ignore_writeerr) char **files; // Get a list of all files in the help directory and in subdirectories. - STRLCPY(NameBuff, dirname, sizeof(NameBuff)); + xstrlcpy(NameBuff, dirname, sizeof(NameBuff)); if (!add_pathsep((char *)NameBuff) || xstrlcat(NameBuff, "**", sizeof(NameBuff)) >= MAXPATHL) { emsg(_(e_fnametoolong)); diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 566558c33a..27d522d759 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3106,7 +3106,7 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p if (tmp_ptr - ptr >= IOSIZE - len) { tmp_ptr = ptr + IOSIZE - len - 1; } - STRLCPY(IObuff + len, ptr, IOSIZE - len); + xstrlcpy(IObuff + len, ptr, (size_t)(IOSIZE - len)); len += (int)(tmp_ptr - ptr); *cont_s_ipos = true; } diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 5fffc72056..199cc7b369 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -271,7 +271,7 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs return false; } mapargs->lhs_len = strlen(replaced); - STRLCPY(mapargs->lhs, replaced, sizeof(mapargs->lhs)); + xstrlcpy(mapargs->lhs, replaced, sizeof(mapargs->lhs)); if (did_simplify) { replaced = replace_termcodes(orig_lhs, orig_lhs_len, &bufarg, flags | REPTERM_NO_SIMPLIFY, NULL, cpo_flags); @@ -279,7 +279,7 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs return false; } mapargs->alt_lhs_len = strlen(replaced); - STRLCPY(mapargs->alt_lhs, replaced, sizeof(mapargs->alt_lhs)); + xstrlcpy(mapargs->alt_lhs, replaced, sizeof(mapargs->alt_lhs)); } else { mapargs->alt_lhs_len = 0; } @@ -298,7 +298,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len if (rhs_lua == LUA_NOREF) { mapargs->orig_rhs_len = orig_rhs_len; mapargs->orig_rhs = xcalloc(mapargs->orig_rhs_len + 1, sizeof(char_u)); - STRLCPY(mapargs->orig_rhs, orig_rhs, mapargs->orig_rhs_len + 1); + xstrlcpy(mapargs->orig_rhs, orig_rhs, mapargs->orig_rhs_len + 1); if (STRICMP(orig_rhs, "<nop>") == 0) { // "<Nop>" means nothing mapargs->rhs = xcalloc(1, sizeof(char_u)); // single NUL-char mapargs->rhs_len = 0; @@ -427,11 +427,11 @@ static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *ma if (orig_lhs_len >= 256) { return 1; } - char_u lhs_to_replace[256]; - STRLCPY(lhs_to_replace, to_parse, orig_lhs_len + 1); + char lhs_to_replace[256]; + xstrlcpy(lhs_to_replace, to_parse, orig_lhs_len + 1); size_t orig_rhs_len = strlen(rhs_start); - if (!set_maparg_lhs_rhs((char *)lhs_to_replace, orig_lhs_len, + if (!set_maparg_lhs_rhs(lhs_to_replace, orig_lhs_len, rhs_start, orig_rhs_len, LUA_NOREF, CPO_TO_CPO_FLAGS, mapargs)) { return 1; @@ -464,7 +464,7 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, mp->m_keys = xstrdup(keys); mp->m_str = args->rhs; - mp->m_orig_str = (char *)args->orig_rhs; + mp->m_orig_str = args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!simplified) { args->rhs = NULL; @@ -776,7 +776,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, XFREE_CLEAR(mp->m_orig_str); } mp->m_str = args->rhs; - mp->m_orig_str = (char *)args->orig_rhs; + mp->m_orig_str = args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!keyround1_simplified) { args->rhs = NULL; diff --git a/src/nvim/mapping.h b/src/nvim/mapping.h index 7053aa814d..58e28810bc 100644 --- a/src/nvim/mapping.h +++ b/src/nvim/mapping.h @@ -32,11 +32,11 @@ struct map_arguments { /// vim limits this to MAXMAPLEN characters, allowing us to use a static /// buffer. Setting lhs_len to a value larger than MAXMAPLEN can signal /// that {lhs} was too long and truncated. - char_u lhs[MAXMAPLEN + 1]; + char lhs[MAXMAPLEN + 1]; size_t lhs_len; /// Unsimplifed {lhs} of the mapping. If no simplification has been done then alt_lhs_len is 0. - char_u alt_lhs[MAXMAPLEN + 1]; + char alt_lhs[MAXMAPLEN + 1]; size_t alt_lhs_len; char *rhs; /// The {rhs} of the mapping. @@ -44,7 +44,7 @@ struct map_arguments { LuaRef rhs_lua; /// lua function as {rhs} bool rhs_is_noop; /// True when the {rhs} should be <Nop>. - char_u *orig_rhs; /// The original text of the {rhs}. + char *orig_rhs; /// The original text of the {rhs}. size_t orig_rhs_len; char *desc; /// map description }; diff --git a/src/nvim/mark.c b/src/nvim/mark.c index c38aa834bf..0d4a95ebab 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -664,13 +664,13 @@ static void fname2fnum(xfmark_T *fm) expand_env("~/", NameBuff, MAXPATHL); int len = (int)strlen(NameBuff); - STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len); + xstrlcpy(NameBuff + len, fm->fname + 2, (size_t)(MAXPATHL - len)); } else { - STRLCPY(NameBuff, fm->fname, MAXPATHL); + xstrlcpy(NameBuff, fm->fname, MAXPATHL); } // Try to shorten the file name. - os_dirname((char_u *)IObuff, IOSIZE); + os_dirname(IObuff, IOSIZE); char *p = path_shorten_fname(NameBuff, IObuff); // buflist_new() will call fmarks_check_names() diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 03fe0be896..8d92b30959 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -640,7 +640,7 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf) size_t ulen = strlen(uname); size_t flen = strlen(b0p->b0_fname); if (retval == FAIL || ulen + flen > B0_FNAME_SIZE_CRYPT - 1) { - STRLCPY(b0p->b0_fname, buf->b_ffname, B0_FNAME_SIZE_CRYPT); + xstrlcpy(b0p->b0_fname, buf->b_ffname, B0_FNAME_SIZE_CRYPT); } else { memmove(b0p->b0_fname + ulen + 1, b0p->b0_fname + 1, flen); memmove(b0p->b0_fname + 1, uname, ulen); @@ -896,7 +896,7 @@ void ml_recover(bool checkext) smsg(_("Using swap file \"%s\""), NameBuff); if (buf_spname(curbuf) != NULL) { - STRLCPY(NameBuff, buf_spname(curbuf), MAXPATHL); + xstrlcpy(NameBuff, buf_spname(curbuf), MAXPATHL); } else { home_replace(NULL, curbuf->b_ffname, (char *)NameBuff, MAXPATHL, true); } @@ -2966,7 +2966,7 @@ int resolve_symlink(const char *fname, char *buf) } // Put the result so far in tmp[], starting with the original name. - STRLCPY(tmp, fname, MAXPATHL); + xstrlcpy(tmp, fname, MAXPATHL); for (;;) { // Limit symlink depth to 100, catch recursive loops. diff --git a/src/nvim/menu.c b/src/nvim/menu.c index e6987d6149..ac73510266 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -960,7 +960,7 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for if (after_dot > arg) { size_t path_len = (size_t)(after_dot - arg); path_name = xmalloc(path_len); - STRLCPY(path_name, arg, path_len); + xstrlcpy(path_name, arg, path_len); } name = path_name; while (name != NULL && *name) { @@ -1075,9 +1075,9 @@ char *get_menu_names(expand_T *xp, int idx) if (menu->modes & expand_modes) { if (menu->children != NULL) { if (should_advance) { - STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN); + xstrlcpy(tbuffer, menu->en_dname, TBUFFER_LEN); } else { - STRLCPY(tbuffer, menu->dname, TBUFFER_LEN); + xstrlcpy(tbuffer, menu->dname, TBUFFER_LEN); if (menu->en_dname == NULL) { should_advance = true; } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index ccfd3ab834..2566108618 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2440,7 +2440,7 @@ int op_change(oparg_T *oap) long pre_indent = 0; char_u *newp; char *firstline; - char_u *ins_text; + char *ins_text; char *oldp; struct block_def bd; @@ -2510,8 +2510,8 @@ int op_change(oparg_T *oap) if (ins_len > 0) { // Subsequent calls to ml_get() flush the firstline data - take a // copy of the inserted text. - ins_text = (char_u *)xmalloc((size_t)(ins_len + 1)); - STRLCPY(ins_text, firstline + bd.textcol, ins_len + 1); + ins_text = xmalloc((size_t)(ins_len + 1)); + xstrlcpy(ins_text, firstline + bd.textcol, (size_t)ins_len + 1); for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; linenr++) { block_prep(oap, &bd, linenr, true); diff --git a/src/nvim/option.c b/src/nvim/option.c index 922cf6eb4f..06de8be129 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1455,7 +1455,7 @@ skip: } if (errmsg != NULL) { - STRLCPY(IObuff, _(errmsg), IOSIZE); + xstrlcpy(IObuff, _(errmsg), IOSIZE); int i = (int)strlen(IObuff) + 2; if (i + (arg - startarg) < IOSIZE) { // append the argument with the error @@ -4798,15 +4798,15 @@ void ExpandOldSetting(int *num_file, char ***file) /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL static void option_value2string(vimoption_T *opp, int scope) { - char_u *varp = (char_u *)get_varp_scope(opp, scope); + char *varp = get_varp_scope(opp, scope); if (opp->flags & P_NUM) { long wc = 0; - if (wc_use_keyname(varp, &wc)) { - STRLCPY(NameBuff, get_special_key_name((int)wc, 0), sizeof(NameBuff)); + if (wc_use_keyname((char_u *)varp, &wc)) { + xstrlcpy(NameBuff, (char *)get_special_key_name((int)wc, 0), sizeof(NameBuff)); } else if (wc != 0) { - STRLCPY(NameBuff, transchar((int)wc), sizeof(NameBuff)); + xstrlcpy(NameBuff, (char *)transchar((int)wc), sizeof(NameBuff)); } else { snprintf((char *)NameBuff, sizeof(NameBuff), @@ -4814,16 +4814,16 @@ static void option_value2string(vimoption_T *opp, int scope) (int64_t)(*(long *)varp)); } } else { // P_STRING - varp = *(char_u **)(varp); + varp = *(char **)(varp); if (varp == NULL) { // Just in case. NameBuff[0] = NUL; } else if (opp->flags & P_EXPAND) { - home_replace(NULL, (char *)varp, (char *)NameBuff, MAXPATHL, false); + home_replace(NULL, varp, (char *)NameBuff, MAXPATHL, false); // Translate 'pastetoggle' into special key names. } else if ((char **)opp->var == &p_pt) { str2specialbuf((const char *)p_pt, (char *)NameBuff, MAXPATHL); } else { - STRLCPY(NameBuff, varp, MAXPATHL); + xstrlcpy(NameBuff, varp, MAXPATHL); } } } diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 4b892fac28..ef9b9c5958 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -488,8 +488,8 @@ void init_homedir(void) if (var != NULL) { // Change to the directory and get the actual path. This resolves // links. Don't do it when we can't return. - if (os_dirname((char_u *)os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { - if (!os_chdir(var) && os_dirname((char_u *)IObuff, IOSIZE) == OK) { + if (os_dirname(os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { + if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { var = (char *)IObuff; } if (os_chdir(os_buf) != 0) { @@ -500,7 +500,7 @@ void init_homedir(void) // Fall back to current working directory if home is not found if ((var == NULL || *var == NUL) - && os_dirname((char_u *)os_buf, sizeof(os_buf)) == OK) { + && os_dirname(os_buf, sizeof(os_buf)) == OK) { var = os_buf; } #endif @@ -1056,7 +1056,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si } if (buf != NULL && buf->b_help) { - const size_t dlen = STRLCPY(dst, path_tail((char *)src), dstlen); + const size_t dlen = xstrlcpy(dst, path_tail((char *)src), dstlen); return MIN(dlen, dstlen - 1); } @@ -1176,7 +1176,7 @@ char *get_env_name(expand_T *xp, int idx) assert(idx >= 0); char *envname = os_getenvname_at_index((size_t)idx); if (envname) { - STRLCPY(xp->xp_buf, envname, EXPAND_BUF_LEN); + xstrlcpy(xp->xp_buf, envname, EXPAND_BUF_LEN); xfree(envname); return xp->xp_buf; } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4906dd0df2..b8ade07038 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -105,12 +105,12 @@ int os_chdir(const char *path) /// @param buf Buffer to store the directory name. /// @param len Length of `buf`. /// @return `OK` for success, `FAIL` for failure. -int os_dirname(char_u *buf, size_t len) +int os_dirname(char *buf, size_t len) FUNC_ATTR_NONNULL_ALL { int error_number; - if ((error_number = uv_cwd((char *)buf, &len)) != kLibuvSuccess) { - STRLCPY(buf, uv_strerror(error_number), len); + if ((error_number = uv_cwd(buf, &len)) != kLibuvSuccess) { + xstrlcpy(buf, uv_strerror(error_number), len); return FAIL; } return OK; @@ -379,7 +379,7 @@ static bool is_executable_in_path(const char *name, char **abspath) char *e = xstrchrnul(p, ENV_SEPCHAR); // Combine the $PATH segment with `name`. - STRLCPY(buf, p, e - p + 1); + xstrlcpy(buf, p, (size_t)(e - p) + 1); append_path(buf, name, buf_len); #ifdef MSWIN diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 57dc2eb797..ef2986246b 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -146,7 +146,7 @@ int os_get_uname(uv_uid_t uid, char *s, size_t len) if ((pw = getpwuid(uid)) != NULL // NOLINT(runtime/threadsafe_fn) && pw->pw_name != NULL && *(pw->pw_name) != NUL) { - STRLCPY(s, pw->pw_name, len); + xstrlcpy(s, pw->pw_name, len); return OK; } #endif diff --git a/src/nvim/path.c b/src/nvim/path.c index b912020ea5..0905c16e39 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -71,7 +71,7 @@ FileComparison path_full_compare(char *const s1, char *const s2, const bool chec if (expandenv) { expand_env(s1, exp1, MAXPATHL); } else { - STRLCPY(exp1, s1, MAXPATHL); + xstrlcpy(exp1, s1, MAXPATHL); } bool id_ok_1 = os_fileid(exp1, &file_id_1); bool id_ok_2 = os_fileid(s2, &file_id_2); @@ -964,7 +964,7 @@ static void uniquefy_paths(garray_T *gap, char *pattern) } char *curdir = xmalloc(MAXPATHL); - os_dirname((char_u *)curdir, MAXPATHL); + os_dirname(curdir, MAXPATHL); expand_path_option(curdir, &path_ga); in_curdir = xcalloc((size_t)gap->ga_len, sizeof(char_u *)); @@ -1118,7 +1118,7 @@ static int expand_in_path(garray_T *const gap, char_u *const pattern, const int garray_T path_ga; char_u *const curdir = xmalloc(MAXPATHL); - os_dirname(curdir, MAXPATHL); + os_dirname((char *)curdir, MAXPATHL); ga_init(&path_ga, (int)sizeof(char_u *), 1); expand_path_option((char *)curdir, &path_ga); @@ -1916,12 +1916,12 @@ void path_fix_case(char *name) // Only accept names that differ in case and are the same byte // length. TODO: accept different length name. if (STRICMP(tail, entry) == 0 && strlen(tail) == strlen(entry)) { - char_u newname[MAXPATHL + 1]; + char newname[MAXPATHL + 1]; // Verify the inode is equal. - STRLCPY(newname, name, MAXPATHL + 1); - STRLCPY(newname + (tail - name), entry, - MAXPATHL - (tail - name) + 1); + xstrlcpy(newname, name, MAXPATHL + 1); + xstrlcpy(newname + (tail - name), entry, + (size_t)(MAXPATHL - (tail - name) + 1)); FileInfo file_info_new; if (os_fileinfo_link((char *)newname, &file_info_new) && os_fileinfo_id_equal(&file_info, &file_info_new)) { @@ -2049,7 +2049,7 @@ char_u *path_try_shorten_fname(char_u *full_path) char_u *dirname = xmalloc(MAXPATHL); char_u *p = full_path; - if (os_dirname(dirname, MAXPATHL) == OK) { + if (os_dirname((char *)dirname, MAXPATHL) == OK) { p = (char_u *)path_shorten_fname((char *)full_path, (char *)dirname); if (p == NULL || *p == NUL) { p = full_path; @@ -2272,13 +2272,13 @@ int path_full_dir_name(char *directory, char *buffer, size_t len) int retval = OK; if (strlen(directory) == 0) { - return os_dirname((char_u *)buffer, len); + return os_dirname(buffer, len); } char old_dir[MAXPATHL]; // Get current directory name. - if (os_dirname((char_u *)old_dir, MAXPATHL) == FAIL) { + if (os_dirname(old_dir, MAXPATHL) == FAIL) { return FAIL; } @@ -2298,7 +2298,7 @@ int path_full_dir_name(char *directory, char *buffer, size_t len) xstrlcpy(buffer, old_dir, len); append_path(buffer, directory, len); } - } else if (os_dirname((char_u *)buffer, len) == FAIL) { + } else if (os_dirname(buffer, len) == FAIL) { // Do not return immediately since we are in the wrong directory. retval = FAIL; } @@ -2421,7 +2421,7 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize) xstrlcpy(buf, argv0, bufsize); } else if (argv0[0] == '.' || strchr(argv0, PATHSEP)) { // Relative to CWD. - if (os_dirname((char_u *)buf, MAXPATHL) != OK) { + if (os_dirname(buf, MAXPATHL) != OK) { buf[0] = NUL; } xstrlcat(buf, PATHSEPSTR, bufsize); @@ -2439,7 +2439,7 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize) if (dir_len + 1 > sizeof(NameBuff)) { continue; } - STRLCPY(NameBuff, dir, dir_len + 1); + xstrlcpy(NameBuff, dir, dir_len + 1); xstrlcat(NameBuff, PATHSEPSTR, sizeof(NameBuff)); xstrlcat(NameBuff, argv0, sizeof(NameBuff)); if (os_can_exe((char *)NameBuff, NULL, false)) { diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 6c13aa5d50..63a6dcec50 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -712,8 +712,8 @@ static int qf_get_next_list_line(qfstate_T *state) state->linelen = len; } - STRLCPY(state->linebuf, TV_LIST_ITEM_TV(p_li)->vval.v_string, - state->linelen + 1); + xstrlcpy(state->linebuf, TV_LIST_ITEM_TV(p_li)->vval.v_string, + state->linelen + 1); state->p_li = TV_LIST_ITEM_NEXT(state->p_list, p_li); return QF_OK; @@ -736,7 +736,7 @@ static int qf_get_next_buf_line(qfstate_T *state) state->linebuf = (char *)IObuff; state->linelen = len; } - STRLCPY(state->linebuf, p_buf, state->linelen + 1); + xstrlcpy(state->linebuf, p_buf, state->linelen + 1); return QF_OK; } @@ -818,7 +818,7 @@ retry: char *line = string_convert(&state->vc, state->linebuf, &state->linelen); if (line != NULL) { if (state->linelen < IOSIZE) { - STRLCPY(state->linebuf, line, state->linelen + 1); + xstrlcpy(state->linebuf, line, state->linelen + 1); xfree(line); } else { xfree(state->growbuf); @@ -1195,7 +1195,7 @@ static void qf_store_title(qf_list_T *qfl, const char *title) char *p = xmallocz(len); qfl->qf_title = p; - STRLCPY(p, title, len + 1); + xstrlcpy(p, title, len + 1); } } @@ -1350,7 +1350,7 @@ static int copy_nonerror_line(const char *linebuf, size_t linelen, qffields_T *f fields->errmsglen = linelen + 1; } // copy whole line to error message - STRLCPY(fields->errmsg, linebuf, linelen + 1); + xstrlcpy(fields->errmsg, linebuf, linelen + 1); return QF_OK; } @@ -1368,7 +1368,7 @@ static int qf_parse_fmt_m(regmatch_T *rmp, int midx, qffields_T *fields) fields->errmsg = xrealloc(fields->errmsg, len + 1); fields->errmsglen = len + 1; } - STRLCPY(fields->errmsg, rmp->startp[midx], len + 1); + xstrlcpy(fields->errmsg, rmp->startp[midx], len + 1); return QF_OK; } @@ -3941,18 +3941,18 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, const qfli // If the 'quickfixtextfunc' function returned a non-empty custom string // for this entry, then use it. if (qftf_str != NULL && *qftf_str != NUL) { - STRLCPY(IObuff, qftf_str, IOSIZE); + xstrlcpy(IObuff, qftf_str, IOSIZE); } else { buf_T *errbuf; int len; if (qfp->qf_module != NULL) { - STRLCPY(IObuff, qfp->qf_module, IOSIZE); + xstrlcpy(IObuff, qfp->qf_module, IOSIZE); len = (int)strlen(IObuff); } else if (qfp->qf_fnum != 0 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL && errbuf->b_fname != NULL) { if (qfp->qf_type == 1) { // :helpgrep - STRLCPY(IObuff, path_tail(errbuf->b_fname), IOSIZE); + xstrlcpy(IObuff, path_tail(errbuf->b_fname), IOSIZE); } else { // Shorten the file name if not done already. // For optimization, do this only for the first entry in a @@ -3961,11 +3961,11 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, const qfli && (errbuf->b_sfname == NULL || path_is_absolute((char_u *)errbuf->b_sfname))) { if (*dirname == NUL) { - os_dirname((char_u *)dirname, MAXPATHL); + os_dirname(dirname, MAXPATHL); } shorten_buf_fname(errbuf, (char_u *)dirname, false); } - STRLCPY(IObuff, errbuf->b_fname, IOSIZE); + xstrlcpy(IObuff, errbuf->b_fname, IOSIZE); } len = (int)strlen(IObuff); } else { @@ -5370,7 +5370,7 @@ static int vgr_process_files(win_T *wp, qf_info_T *qi, vgr_args_T *cmd_args, boo // Remember the current directory, because a BufRead autocommand that does // ":lcd %:p:h" changes the meaning of short path names. - os_dirname((char_u *)dirname_start, MAXPATHL); + os_dirname(dirname_start, MAXPATHL); time_t seconds = (time_t)0; for (int fi = 0; fi < cmd_args->fcount && !got_int && cmd_args->tomatch > 0; fi++) { @@ -5581,7 +5581,7 @@ static void restore_start_dir(char *dirname_start) { char *dirname_now = xmalloc(MAXPATHL); - os_dirname((char_u *)dirname_now, MAXPATHL); + os_dirname(dirname_now, MAXPATHL); if (strcmp(dirname_start, dirname_now) != 0) { // If the directory has changed, change it back by building up an // appropriate ex command and executing it. @@ -5675,7 +5675,7 @@ static buf_T *load_dummy_buffer(char *fname, char *dirname_start, char *resultin // When autocommands/'autochdir' option changed directory: go back. // Let the caller know what the resulting dir was first, in case it is // important. - os_dirname((char_u *)resulting_dir, MAXPATHL); + os_dirname(resulting_dir, MAXPATHL); restore_start_dir(dirname_start); if (!bufref_valid(&newbufref)) { diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index cbf5530995..9bc9d86374 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2141,7 +2141,7 @@ char *reg_submatch(int no) // Within one line: take form start to end col. len = rsm.sm_mmatch->endpos[no].col - rsm.sm_mmatch->startpos[no].col; if (round == 2) { - STRLCPY(retval, s, len + 1); + xstrlcpy(retval, s, (size_t)len + 1); } len++; } else { diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index d922a4d303..0e1fe67e4a 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -654,8 +654,8 @@ static void expand_pack_entry(RuntimeSearchPath *search_path, Map(String, handle if (pack_entry_len + strlen(start_pat[i]) + 1 > sizeof buf) { continue; } - STRLCPY(buf, pack_entry, sizeof buf); - STRLCPY(buf + pack_entry_len, start_pat[i], sizeof buf - pack_entry_len); + xstrlcpy(buf, pack_entry, sizeof buf); + xstrlcpy(buf + pack_entry_len, start_pat[i], sizeof buf - pack_entry_len); expand_rtp_entry(search_path, rtp_used, buf, false); size_t after_size = strlen(buf) + 7; char *after = xmallocz(after_size); @@ -1085,7 +1085,7 @@ static void add_pack_start_dir(char *fname, void *cookie) if (strlen(fname) + strlen(start_pat[i]) + 1 > MAXPATHL) { continue; } - STRLCPY(buf, fname, MAXPATHL); + xstrlcpy(buf, fname, MAXPATHL); xstrlcat(buf, start_pat[i], sizeof buf); if (pack_has_entries(buf)) { add_pack_dir_to_rtp(buf, true); diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 8655206574..58aec2e84c 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -681,7 +681,7 @@ static void recording_mode(int attr) void get_trans_bufname(buf_T *buf) { if (buf_spname(buf) != NULL) { - STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); + xstrlcpy(NameBuff, buf_spname(buf), MAXPATHL); } else { home_replace(buf, buf->b_fname, (char *)NameBuff, MAXPATHL, true); } diff --git a/src/nvim/search.c b/src/nvim/search.c index 4a1f26ea39..51ad2b0cbb 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -3414,10 +3414,10 @@ void f_matchfuzzypos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// Get line "lnum" and copy it into "buf[LSIZE]". /// The copy is made because the regexp may make the line invalid when using a /// mark. -static char_u *get_line_and_copy(linenr_T lnum, char_u *buf) +static char *get_line_and_copy(linenr_T lnum, char *buf) { - char_u *line = (char_u *)ml_get(lnum); - STRLCPY(buf, line, LSIZE); + char *line = ml_get(lnum); + xstrlcpy(buf, line, LSIZE); return buf; } @@ -3517,7 +3517,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool if (lnum > end_lnum) { // do at least one line lnum = end_lnum; } - line = (char *)get_line_and_copy(lnum, file_line); + line = get_line_and_copy(lnum, (char *)file_line); for (;;) { if (incl_regmatch.regprog != NULL @@ -3794,7 +3794,7 @@ search_line: if (lnum >= end_lnum) { goto exit_matched; } - line = (char *)get_line_and_copy(++lnum, file_line); + line = get_line_and_copy(++lnum, (char *)file_line); } else if (vim_fgets(line = (char *)file_line, LSIZE, files[depth].fp)) { goto exit_matched; @@ -3984,7 +3984,7 @@ exit_matched: if (++lnum > end_lnum) { break; } - line = (char *)get_line_and_copy(lnum, file_line); + line = get_line_and_copy(lnum, (char *)file_line); } already = NULL; } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 251c4726a5..33dd76b704 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -739,14 +739,14 @@ static void find_word(matchinf_T *mip, int mode) mip->mi_compflags[mip->mi_complen] = (char_u)((unsigned)flags >> 24); mip->mi_compflags[mip->mi_complen + 1] = NUL; if (word_ends) { - char_u fword[MAXWLEN] = { 0 }; + char fword[MAXWLEN] = { 0 }; if (slang->sl_compsylmax < MAXWLEN) { // "fword" is only needed for checking syllables. if (ptr == mip->mi_word) { - (void)spell_casefold(mip->mi_win, (char_u *)ptr, wlen, fword, MAXWLEN); + (void)spell_casefold(mip->mi_win, (char_u *)ptr, wlen, (char_u *)fword, MAXWLEN); } else { - STRLCPY(fword, ptr, endlen[endidxcnt] + 1); + xstrlcpy(fword, ptr, (size_t)endlen[endidxcnt] + 1); } } if (!can_compound(slang, (char *)fword, mip->mi_compflags)) { @@ -1318,7 +1318,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att bool empty_line = *skipwhite((const char *)line) == NUL; STRCPY(buf, line); if (lnum < wp->w_buffer->b_ml.ml_line_count) { - spell_cat_line((char_u *)buf + strlen(buf), + spell_cat_line(buf + strlen(buf), (char_u *)ml_get_buf(wp->w_buffer, lnum + 1, false), MAXWLEN); } @@ -1480,7 +1480,7 @@ theend: // "buf", blanking-out special characters. Copy less than "maxlen" bytes. // Keep the blanks at the start of the next line, this is used in win_line() // to skip those bytes if the word was OK. -void spell_cat_line(char_u *buf, char_u *line, int maxlen) +void spell_cat_line(char *buf, char_u *line, int maxlen) { char_u *p = (char_u *)skipwhite((char *)line); while (vim_strchr("*#/\"\t", *p) != NULL) { @@ -1493,7 +1493,7 @@ void spell_cat_line(char_u *buf, char_u *line, int maxlen) int n = (int)(p - line) + 1; if (n < maxlen - 1) { memset(buf, ' ', (size_t)n); - STRLCPY(buf + n, p, maxlen - n); + xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n)); } } } @@ -1731,7 +1731,7 @@ void count_common_word(slang_T *lp, char *word, int len, uint8_t count) } else if (len >= MAXWLEN) { return; } else { - STRLCPY(buf, word, len + 1); + xstrlcpy(buf, word, (size_t)len + 1); p = buf; } @@ -1789,7 +1789,7 @@ int init_syl_tab(slang_T *slang) } syl_item_T *syl = GA_APPEND_VIA_PTR(syl_item_T, &slang->sl_syl_items); - STRLCPY(syl->sy_chars, s, l + 1); + xstrlcpy(syl->sy_chars, s, (size_t)l + 1); syl->sy_len = l; } return OK; @@ -1916,7 +1916,7 @@ char *did_set_spelllang(win_T *wp) p = vim_strchr(path_tail((char *)lang), '_'); if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2]) && !ASCII_ISALPHA(p[3])) { - STRLCPY(region_cp, p + 1, 3); + xstrlcpy(region_cp, p + 1, 3); memmove(p, p + 3, (size_t)(len - (p - lang) - 2)); region = region_cp; } else { @@ -2055,7 +2055,7 @@ char *did_set_spelllang(win_T *wp) if (round == 0) { STRCPY(lang, "internal wordlist"); } else { - STRLCPY(lang, path_tail((char *)spf_name), MAXWLEN + 1); + xstrlcpy(lang, path_tail((char *)spf_name), MAXWLEN + 1); p = vim_strchr((char *)lang, '.'); if (p != NULL) { *p = NUL; // truncate at ".encoding.add" @@ -2176,7 +2176,7 @@ static void use_midword(slang_T *lp, win_T *wp) char *bp = xstrnsave(wp->w_s->b_spell_ismw_mb, (size_t)n + (size_t)l); xfree(wp->w_s->b_spell_ismw_mb); wp->w_s->b_spell_ismw_mb = bp; - STRLCPY(bp + n, p, l + 1); + xstrlcpy(bp + n, p, (size_t)l + 1); } p += l; } @@ -2634,7 +2634,7 @@ void ex_spellrepall(exarg_T *eap) /// @param[in] word source string to copy /// @param[in,out] wcopy copied string, with case of first letter changed /// @param[in] upper True to upper case, otherwise lower case -void onecap_copy(char_u *word, char_u *wcopy, bool upper) +void onecap_copy(char_u *word, char *wcopy, bool upper) { char_u *p = word; int c = mb_cptr2char_adv((const char_u **)&p); @@ -2643,8 +2643,8 @@ void onecap_copy(char_u *word, char_u *wcopy, bool upper) } else { c = SPELL_TOFOLD(c); } - int l = utf_char2bytes(c, (char *)wcopy); - STRLCPY(wcopy + l, p, MAXWLEN - l); + int l = utf_char2bytes(c, wcopy); + xstrlcpy(wcopy + l, (char *)p, (size_t)(MAXWLEN - l)); } // Make a copy of "word" with all the letters upper cased into @@ -2697,7 +2697,7 @@ void make_case_word(char_u *fword, char_u *cword, int flags) allcap_copy(fword, cword); } else if (flags & WF_ONECAP) { // Make the first letter upper-case - onecap_copy(fword, cword, true); + onecap_copy(fword, (char *)cword, true); } else { // Use goodword as-is. STRCPY(cword, fword); @@ -3319,7 +3319,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) // Apply the prefix, if there is one. if (c != 0) { - lnum = dump_prefixes(slang, (char_u *)word, (char_u *)pat, dir, + lnum = dump_prefixes(slang, word, (char_u *)pat, dir, dumpflags, flags, lnum); } } @@ -3436,21 +3436,21 @@ static void dump_word(slang_T *slang, char *word, char *pat, Direction *dir, int /// @param flags flags with prefix ID /// /// @return the updated line number. -static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, Direction *dir, +static linenr_T dump_prefixes(slang_T *slang, char *word, char_u *pat, Direction *dir, int dumpflags, int flags, linenr_T startlnum) { idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; - char_u prefix[MAXWLEN]; - char_u word_up[MAXWLEN]; + char prefix[MAXWLEN]; + char word_up[MAXWLEN]; bool has_word_up = false; linenr_T lnum = startlnum; // If the word starts with a lower-case letter make the word with an // upper-case letter in word_up[]. - int c = utf_ptr2char((char *)word); + int c = utf_ptr2char(word); if (SPELL_TOUPPER(c) != c) { - onecap_copy(word, word_up, true); + onecap_copy((char_u *)word, (char *)word_up, true); has_word_up = true; } @@ -3484,9 +3484,9 @@ static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, Directi } curi[depth] += i - 1; - c = valid_word_prefix(i, n, flags, word, slang, false); + c = valid_word_prefix(i, n, flags, (char_u *)word, slang, false); if (c != 0) { - STRLCPY(prefix + depth, word, MAXWLEN - depth); + xstrlcpy(prefix + depth, word, (size_t)(MAXWLEN - depth)); dump_word(slang, (char *)prefix, (char *)pat, dir, dumpflags, (c & WF_RAREPFX) ? (flags | WF_RARE) : flags, lnum); if (lnum != 0) { @@ -3498,10 +3498,10 @@ static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, Directi // first letter is upper-case, but only if the prefix has // a condition. if (has_word_up) { - c = valid_word_prefix(i, n, flags, word_up, slang, + c = valid_word_prefix(i, n, flags, (char_u *)word_up, slang, true); if (c != 0) { - STRLCPY(prefix + depth, word_up, MAXWLEN - depth); + xstrlcpy(prefix + depth, word_up, (size_t)(MAXWLEN - depth)); dump_word(slang, (char *)prefix, (char *)pat, dir, dumpflags, (c & WF_RAREPFX) ? (flags | WF_RARE) : flags, lnum); if (lnum != 0) { @@ -3511,7 +3511,7 @@ static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, Directi } } else { // Normal char, go one level deeper. - prefix[depth++] = (char_u)c; + prefix[depth++] = (char)c; arridx[depth] = idxs[n]; curi[depth] = 1; } diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index f2c335c69a..d01acd6300 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2348,7 +2348,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) && aff_todo == 0 && itemcnt >= 4) { int lasti = 4; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; if (*items[0] == 'P') { tp = &aff->af_pref; @@ -2360,7 +2360,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // times. The affix files that do this have an undocumented // "S" flag on all but the last block, thus we check for that // and store it in ah_follows. - STRLCPY(key, items[1], AH_KEY_LEN); + xstrlcpy(key, items[1], AH_KEY_LEN); hi = hash_find(tp, (char *)key); if (!HASHITEM_EMPTY(hi)) { cur_aff = HI2AH(hi); @@ -2533,7 +2533,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // upper-case letter. if (aff_entry->ae_cond != NULL) { char_u buf[MAXLINELEN]; - onecap_copy((char_u *)items[4], buf, true); + onecap_copy((char_u *)items[4], (char *)buf, true); aff_entry->ae_cond = (char_u *)getroom_save(spin, (char *)buf); if (aff_entry->ae_cond != NULL) { sprintf((char *)buf, "^%s", aff_entry->ae_cond); // NOLINT(runtime/printf) @@ -2902,13 +2902,13 @@ static unsigned get_affitem(int flagtype, char_u **pp) static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags) { char *p; - char_u *prevp; + char *prevp; unsigned flag; compitem_T *ci; int id; int len; char_u *tp; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; hashitem_T *hi; // Make room for the old and the new compflags, concatenated with a / in @@ -2932,12 +2932,12 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags *tp++ = (char_u)(*p++); } else { // First get the flag number, also checks validity. - prevp = (char_u *)p; + prevp = p; flag = get_affitem(aff->af_flagtype, (char_u **)&p); if (flag != 0) { // Find the flag in the hashtable. If it was used before, use // the existing ID. Otherwise add a new entry. - STRLCPY(key, prevp, (char_u *)p - prevp + 1); + xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); hi = hash_find(&aff->af_comp, (char *)key); if (!HASHITEM_EMPTY(hi)) { id = HI2CI(hi)->ci_newID; @@ -3281,14 +3281,14 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Additionally do matching prefixes that combine. if (store_aff_word(spin, dw, afflist, affile, &affile->af_suff, &affile->af_pref, - CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { + CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { retval = FAIL; } // Find all matching prefixes and add the resulting words. if (store_aff_word(spin, dw, afflist, affile, &affile->af_pref, NULL, - CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { + CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { retval = FAIL; } } @@ -3353,18 +3353,18 @@ static int get_affix_flags(afffile_T *affile, char_u *afflist) static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist) { char_u *p; - char_u *prevp; + char *prevp; int cnt = 0; int id; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; hashitem_T *hi; for (p = afflist; *p != NUL;) { - prevp = p; + prevp = (char *)p; if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a postponed prefix flag if it appears in "af_pref" // and its ID is not zero. - STRLCPY(key, prevp, p - prevp + 1); + xstrlcpy(key, prevp, (size_t)(p - (char_u *)prevp) + 1); hi = hash_find(&affile->af_pref, (char *)key); if (!HASHITEM_EMPTY(hi)) { id = HI2AH(hi)->ah_newID; @@ -3388,16 +3388,16 @@ static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist static void get_compflags(afffile_T *affile, char_u *afflist, char_u *store_afflist) { char_u *p; - char_u *prevp; + char *prevp; int cnt = 0; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; hashitem_T *hi; for (p = afflist; *p != NUL;) { - prevp = p; + prevp = (char *)p; if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a compound flag if it appears in "af_comp". - STRLCPY(key, prevp, p - prevp + 1); + xstrlcpy(key, prevp, (size_t)(p - (char_u *)prevp) + 1); hi = hash_find(&affile->af_comp, (char *)key); if (!HASHITEM_EMPTY(hi)) { store_afflist[cnt++] = (char_u)HI2CI(hi)->ci_newID; @@ -3427,7 +3427,7 @@ static void get_compflags(afffile_T *affile, char_u *afflist, char_u *store_affl /// /// @return FAIL when out of memory. static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffile_T *affile, - hashtab_T *ht, hashtab_T *xht, int condit, int flags, char_u *pfxlist, + hashtab_T *ht, hashtab_T *xht, int condit, int flags, char *pfxlist, int pfxlen) { int todo; @@ -3439,11 +3439,11 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil int i, j; char_u *p; int use_flags; - char_u *use_pfxlist; + char *use_pfxlist; int use_pfxlen; bool need_affix; char_u store_afflist[MAXWLEN]; - char_u pfx_pfxlist[MAXWLEN]; + char pfx_pfxlist[MAXWLEN]; size_t wordlen = strlen(word); int use_condit; @@ -3488,7 +3488,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil if (ae->ae_add == NULL) { *newword = NUL; } else { - STRLCPY(newword, ae->ae_add, MAXWLEN); + xstrlcpy(newword, ae->ae_add, MAXWLEN); } p = (char_u *)word; if (ae->ae_chop != NULL) { @@ -3501,7 +3501,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil STRCAT(newword, p); } else { // suffix: chop/add at the end of the word - STRLCPY(newword, word, MAXWLEN); + xstrlcpy(newword, word, MAXWLEN); if (ae->ae_chop != NULL) { // Remove chop string. p = (char_u *)newword + strlen(newword); @@ -3550,7 +3550,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil } else { use_pfxlen = 0; } - use_pfxlist = store_afflist; + use_pfxlist = (char *)store_afflist; // Combine the prefix IDs. Avoid adding the // same ID twice. @@ -3568,7 +3568,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil if (spin->si_compflags != NULL) { // Get compound IDS from the affix list. get_compflags(affile, ae->ae_flags, - use_pfxlist + use_pfxlen); + (char_u *)use_pfxlist + use_pfxlen); } else { use_pfxlist[use_pfxlen] = NUL; } @@ -3593,7 +3593,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil // Obey a "COMPOUNDFORBIDFLAG" of the affix: don't // use the compound flags. if (use_pfxlist != NULL && ae->ae_compforbid) { - STRLCPY(pfx_pfxlist, use_pfxlist, use_pfxlen + 1); + xstrlcpy(pfx_pfxlist, use_pfxlist, (size_t)use_pfxlen + 1); use_pfxlist = pfx_pfxlist; } @@ -3624,7 +3624,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil // Store the modified word. if (store_word(spin, newword, use_flags, - spin->si_region, use_pfxlist, + spin->si_region, (char_u *)use_pfxlist, need_affix) == FAIL) { retval = FAIL; } @@ -4970,7 +4970,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname) // Write the .sug file. // Make the file name by changing ".spl" to ".sug". fname = xmalloc(MAXPATHL); - STRLCPY(fname, wfname, MAXPATHL); + xstrlcpy(fname, wfname, MAXPATHL); len = (int)strlen(fname); fname[len - 2] = 'u'; fname[len - 1] = 'g'; @@ -5328,7 +5328,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); } else if (len > 4 && strcmp(fnames[0] + len - 4, ".spl") == 0) { // Name ends in ".spl", use as the file name. - STRLCPY(wfname, fnames[0], MAXPATHL); + xstrlcpy(wfname, fnames[0], MAXPATHL); } else { // Name should be language, make the file name from it. vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL, @@ -5716,7 +5716,7 @@ static void init_spellfile(void) if (aspath) { // Use directory of an entry with path, e.g., for // "/dir/lg.utf-8.spl" use "/dir". - STRLCPY(buf, curbuf->b_s.b_p_spl, lstart - (char_u *)curbuf->b_s.b_p_spl); + xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - (char_u *)curbuf->b_s.b_p_spl)); } else { // Copy the path from 'runtimepath' to buf[]. copy_option_part((char **)&rtp, buf, MAXPATHL, ","); @@ -5725,7 +5725,7 @@ static void init_spellfile(void) // Use the first language name from 'spelllang' and the // encoding used in the first loaded .spl file. if (aspath) { - STRLCPY(buf, curbuf->b_s.b_p_spl, lend - (char_u *)curbuf->b_s.b_p_spl + 1); + xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - (char_u *)curbuf->b_s.b_p_spl + 1)); } else { // Create the "spell" directory if it doesn't exist yet. l = (int)strlen(buf); diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 6bdcfe5ffe..bde61e753c 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -445,7 +445,7 @@ void spell_suggest(int count) { char *line; pos_T prev_cursor = curwin->w_cursor; - char_u wcopy[MAXWLEN + 2]; + char wcopy[MAXWLEN + 2]; char_u *p; int c; suginfo_T sug; @@ -562,10 +562,10 @@ void spell_suggest(int count) // The suggested word may replace only part of the bad word, add // the not replaced part. But only when it's not getting too long. - STRLCPY(wcopy, stp->st_word, MAXWLEN + 1); + xstrlcpy(wcopy, stp->st_word, MAXWLEN + 1); int el = sug.su_badlen - stp->st_orglen; if (el > 0 && stp->st_wordlen + el <= MAXWLEN) { - STRLCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen, el + 1); + xstrlcpy(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen, (size_t)el + 1); } vim_snprintf((char *)IObuff, IOSIZE, "%2d", i + 1); if (cmdmsg_rl) { @@ -743,7 +743,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma if (su->su_badlen >= MAXWLEN) { su->su_badlen = MAXWLEN - 1; // just in case } - STRLCPY(su->su_badword, su->su_badptr, su->su_badlen + 1); + xstrlcpy((char *)su->su_badword, su->su_badptr, (size_t)su->su_badlen + 1); (void)spell_casefold(curwin, (char_u *)su->su_badptr, su->su_badlen, (char_u *)su->su_fbadword, MAXWLEN); @@ -783,7 +783,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma // for that. c = utf_ptr2char(su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { - make_case_word(su->su_badword, (char_u *)buf, WF_ONECAP); + make_case_word((char_u *)su->su_badword, (char_u *)buf, WF_ONECAP); add_suggestion(su, &su->su_ga, (char *)buf, su->su_badlen, SCORE_ICASE, 0, true, su->su_sallang, false); } @@ -1393,9 +1393,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun compflags[sp->ts_complen] = (char_u)((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; - STRLCPY(preword + sp->ts_prewordlen, - tword + sp->ts_splitoff, - sp->ts_twordlen - sp->ts_splitoff + 1); + xstrlcpy(preword + sp->ts_prewordlen, + tword + sp->ts_splitoff, + (size_t)(sp->ts_twordlen - sp->ts_splitoff) + 1); // Verify CHECKCOMPOUNDPATTERN rules. if (match_checkcompoundpattern(preword, sp->ts_prewordlen, @@ -2584,7 +2584,7 @@ static void score_combine(suginfo_T *su) // Add the alternate score to su_sga. for (int i = 0; i < su->su_sga.ga_len; i++) { stp = &SUG(su->su_sga, i); - stp->st_altscore = spell_edit_score(slang, su->su_badword, (char_u *)stp->st_word); + stp->st_altscore = spell_edit_score(slang, (char_u *)su->su_badword, (char_u *)stp->st_word); if (stp->st_score == SCORE_MAXMAX) { stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8; } else { @@ -2653,7 +2653,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * char_u badsound2[MAXWLEN]; char_u fword[MAXWLEN]; char_u goodsound[MAXWLEN]; - char_u goodword[MAXWLEN]; + char goodword[MAXWLEN]; int lendiff; lendiff = su->su_badlen - stp->st_orglen; @@ -2682,9 +2682,9 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * // Add part of the bad word to the good word, so that we soundfold // what replaces the bad word. STRCPY(goodword, stp->st_word); - STRLCPY(goodword + stp->st_wordlen, - su->su_badptr + su->su_badlen - lendiff, lendiff + 1); - pgood = goodword; + xstrlcpy(goodword + stp->st_wordlen, + su->su_badptr + su->su_badlen - lendiff, (size_t)lendiff + 1); + pgood = (char_u *)goodword; } else { pgood = (char_u *)stp->st_word; } @@ -2949,9 +2949,9 @@ badword: // inefficient, using an array is quicker. limit = MAXSCORE(su->su_sfmaxscore - goodscore, score); if (limit > SCORE_LIMITMAX) { - goodscore += spell_edit_score(slang, su->su_badword, p); + goodscore += spell_edit_score(slang, (char_u *)su->su_badword, p); } else { - goodscore += spell_edit_score_limit(slang, su->su_badword, + goodscore += spell_edit_score_limit(slang, (char_u *)su->su_badword, p, limit); } @@ -3205,7 +3205,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i static void check_suggestions(suginfo_T *su, garray_T *gap) { suggest_T *stp; - char_u longword[MAXWLEN + 1]; + char longword[MAXWLEN + 1]; int len; hlf_T attr; @@ -3215,12 +3215,12 @@ static void check_suggestions(suginfo_T *su, garray_T *gap) stp = &SUG(*gap, 0); for (int i = gap->ga_len - 1; i >= 0; i--) { // Need to append what follows to check for "the the". - STRLCPY(longword, stp[i].st_word, MAXWLEN + 1); + xstrlcpy(longword, stp[i].st_word, MAXWLEN + 1); len = stp[i].st_wordlen; - STRLCPY(longword + len, su->su_badptr + stp[i].st_orglen, - MAXWLEN - len + 1); + xstrlcpy(longword + len, su->su_badptr + stp[i].st_orglen, + (size_t)(MAXWLEN - len + 1)); attr = HLF_COUNT; - (void)spell_check(curwin, longword, &attr, NULL, false); + (void)spell_check(curwin, (char_u *)longword, &attr, NULL, false); if (attr != HLF_COUNT) { // Remove this entry. xfree(stp[i].st_word); diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 072b58e08e..80936251b0 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -374,7 +374,7 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) // Make all characters printable. p = transstr(buf, true); - len = (int)STRLCPY(buf, p, sizeof(buf)); + len = (int)xstrlcpy(buf, p, sizeof(buf)); len = (size_t)len < sizeof(buf) ? len : (int)sizeof(buf) - 1; xfree(p); @@ -1349,7 +1349,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n // get replaced with the fillchar fillable = false; if (buf_spname(wp->w_buffer) != NULL) { - STRLCPY(NameBuff, buf_spname(wp->w_buffer), MAXPATHL); + xstrlcpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL); } else { char *t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname : wp->w_buffer->b_fname; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 0b92757fd9..8f0d8d2041 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -2742,20 +2742,20 @@ static int check_keyword_id(char *const line, const int startcol, int *const end // Must make a copy of the keyword, so we can add a NUL and make it // lowercase. - char_u keyword[MAXKEYWLEN + 1]; // assume max. keyword len is 80 - STRLCPY(keyword, kwp, kwlen + 1); + char keyword[MAXKEYWLEN + 1]; // assume max. keyword len is 80 + xstrlcpy(keyword, kwp, (size_t)kwlen + 1); keyentry_T *kp = NULL; // matching case if (syn_block->b_keywtab.ht_used != 0) { - kp = match_keyword((char *)keyword, &syn_block->b_keywtab, cur_si); + kp = match_keyword(keyword, &syn_block->b_keywtab, cur_si); } // ignoring case if (kp == NULL && syn_block->b_keywtab_ic.ht_used != 0) { - str_foldcase((char_u *)kwp, kwlen, (char *)keyword, MAXKEYWLEN + 1); - kp = match_keyword((char *)keyword, &syn_block->b_keywtab_ic, cur_si); + str_foldcase((char_u *)kwp, kwlen, keyword, MAXKEYWLEN + 1); + kp = match_keyword(keyword, &syn_block->b_keywtab_ic, cur_si); } if (kp != NULL) { @@ -4989,7 +4989,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list, do { for (end = p; *end && !ascii_iswhite(*end) && *end != ','; end++) {} char *const name = xmalloc((size_t)(end - p) + 3); // leave room for "^$" - STRLCPY(name + 1, p, end - p + 1); + xstrlcpy(name + 1, p, (size_t)(end - p) + 1); if (strcmp(name + 1, "ALLBUT") == 0 || strcmp(name + 1, "ALL") == 0 || strcmp(name + 1, "TOP") == 0 diff --git a/src/nvim/tag.c b/src/nvim/tag.c index bbfa0f518e..72d7ae1154 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -984,11 +984,11 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char static int add_llist_tags(char_u *tag, int num_matches, char **matches) { list_T *list; - char_u tag_name[128 + 1]; - char_u *fname; + char tag_name[128 + 1]; + char *fname; char_u *cmd; int i; - char_u *p; + char *p; tagptrs_T tagp; fname = xmalloc(MAXPATHL + 1); @@ -1007,15 +1007,15 @@ static int add_llist_tags(char_u *tag, int num_matches, char **matches) if (len > 128) { len = 128; } - STRLCPY(tag_name, tagp.tagname, len + 1); + xstrlcpy(tag_name, tagp.tagname, (size_t)len + 1); tag_name[len] = NUL; // Save the tag file name - p = tag_full_fname(&tagp); + p = (char *)tag_full_fname(&tagp); if (p == NULL) { continue; } - STRLCPY(fname, p, MAXPATHL); + xstrlcpy(fname, p, MAXPATHL); XFREE_CLEAR(p); // Get the line number or the search pattern used to locate @@ -1033,9 +1033,9 @@ static int add_llist_tags(char_u *tag, int num_matches, char **matches) cmd_start = (char_u *)tagp.command; cmd_end = tagp.command_end; if (cmd_end == NULL) { - for (p = (char_u *)tagp.command; + for (p = tagp.command; *p && *p != '\r' && *p != '\n'; p++) {} - cmd_end = p; + cmd_end = (char_u *)p; } // Now, cmd_end points to the character after the @@ -1091,7 +1091,7 @@ static int add_llist_tags(char_u *tag, int num_matches, char **matches) dict = tv_dict_alloc(); tv_list_append_dict(list, dict); - tv_dict_add_str(dict, S_LEN("text"), (const char *)tag_name); + tv_dict_add_str(dict, S_LEN("text"), tag_name); tv_dict_add_str(dict, S_LEN("filename"), (const char *)fname); tv_dict_add_nr(dict, S_LEN("lnum"), lnum); if (lnum == 0) { @@ -1484,7 +1484,7 @@ static bool findtags_in_help_init(findtags_state_T *st) // language name in help_lang[]. i = (int)strlen(st->tag_fname); if (i > 3 && st->tag_fname[i - 3] == '-') { - STRLCPY(st->help_lang, st->tag_fname + i - 2, 3); + xstrlcpy(st->help_lang, st->tag_fname + i - 2, 3); } else { STRCPY(st->help_lang, "en"); } @@ -2034,7 +2034,7 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_ if (tagpp->command + 2 < (char *)temp_end) { len = (size_t)(temp_end - (char_u *)tagpp->command - 2); mfp = xmalloc(len + 2); - STRLCPY(mfp, tagpp->command + 2, len + 1); + xstrlcpy(mfp, tagpp->command + 2, len + 1); } else { mfp = NULL; } @@ -2042,7 +2042,7 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_ } else { len = (size_t)((char *)tagpp->tagname_end - tagpp->tagname); mfp = xmalloc(sizeof(char) + len + 1); - STRLCPY(mfp, tagpp->tagname, len + 1); + xstrlcpy(mfp, tagpp->tagname, len + 1); // if wanted, re-read line to get long form too if (State & MODE_INSERT) { @@ -2558,7 +2558,7 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) } } } else { - STRLCPY(buf, ((char **)(tag_fnames.ga_data))[tnp->tn_hf_idx++], MAXPATHL); + xstrlcpy(buf, ((char **)(tag_fnames.ga_data))[tnp->tn_hf_idx++], MAXPATHL); } return OK; } @@ -3140,8 +3140,7 @@ static char *expand_tag_fname(char *fname, char *const tag_fname, const bool exp && (p = path_tail(tag_fname)) != tag_fname) { retval = xmalloc(MAXPATHL); STRCPY(retval, tag_fname); - STRLCPY(retval + (p - tag_fname), fname, - MAXPATHL - (p - tag_fname)); + xstrlcpy(retval + (p - tag_fname), fname, (size_t)(MAXPATHL - (p - tag_fname))); // Translate names like "src/a/../b/file.c" into "src/b/file.c". simplify_filename((char_u *)retval); } else { @@ -3303,7 +3302,7 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start } return FAIL; } - char_u *buf = xmalloc(MAXPATHL); + char *buf = xmalloc(MAXPATHL); if (start != NULL) { if (end == NULL) { end = start + strlen(start); @@ -3315,11 +3314,10 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start if (len > MAXPATHL - 1) { len = MAXPATHL - 1; } - STRLCPY(buf, start, len + 1); + xstrlcpy(buf, start, (size_t)len + 1); } buf[len] = NUL; - retval = tv_dict_add_str(dict, field_name, strlen(field_name), - (const char *)buf); + retval = tv_dict_add_str(dict, field_name, strlen(field_name), buf); xfree(buf); return retval; } diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 0f9b0af1c1..ad44e2ca22 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -569,7 +569,7 @@ void ui_comp_msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep if (scrolled && row > 0) { msg_sep_row = (int)row - 1; if (sep_char.data) { - STRLCPY(msg_sep_char, sep_char.data, sizeof(msg_sep_char)); + xstrlcpy(msg_sep_char, sep_char.data, sizeof(msg_sep_char)); } } else { msg_sep_row = -1; diff --git a/src/nvim/vim.h b/src/nvim/vim.h index df24e423cf..c395eb438c 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -200,7 +200,6 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext() #endif #define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) // NOLINT(runtime/printf) -#define STRLCPY(d, s, n) xstrlcpy((char *)(d), (char *)(s), (size_t)(n)) #ifdef HAVE_STRCASECMP # define STRICMP(d, s) strcasecmp((char *)(d), (char *)(s)) #else diff --git a/src/nvim/window.c b/src/nvim/window.c index bb915d2fc5..4e569ce11f 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -648,7 +648,7 @@ wingotofile: static void cmd_with_count(char *cmd, char *bufp, size_t bufsize, int64_t Prenum) { - size_t len = STRLCPY(bufp, cmd, bufsize); + size_t len = xstrlcpy(bufp, cmd, bufsize); if (Prenum > 0 && len < bufsize) { vim_snprintf(bufp + len, bufsize - len, "%" PRId64, Prenum); @@ -4879,7 +4879,7 @@ void fix_current_dir(void) // New directory is either the local directory of the window, tab or NULL. char *new_dir = curwin->w_localdir ? curwin->w_localdir : curtab->tp_localdir; char cwd[MAXPATHL]; - if (os_dirname((char_u *)cwd, MAXPATHL) != OK) { + if (os_dirname(cwd, MAXPATHL) != OK) { cwd[0] = NUL; } |