From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/buffer.c | 6 +- src/nvim/api/private/helpers.c | 4 +- src/nvim/arglist.c | 2 +- src/nvim/autocmd.c | 2 +- src/nvim/change.c | 4 +- src/nvim/charset.c | 4 +- src/nvim/cmdexpand.c | 81 +++++++++++------------ src/nvim/cmdhist.c | 8 +-- src/nvim/cursor.c | 15 ++--- src/nvim/diff.c | 39 ++++++----- src/nvim/digraph.c | 6 +- src/nvim/drawline.c | 10 +-- src/nvim/edit.c | 68 ++++++++++---------- src/nvim/eval.c | 18 +++--- src/nvim/eval/funcs.c | 54 ++++++++-------- src/nvim/eval/typval.c | 2 +- src/nvim/eval/typval.h | 15 ++--- src/nvim/eval/userfunc.c | 48 +++++++------- src/nvim/ex_cmds.c | 14 ++-- src/nvim/ex_docmd.c | 10 +-- src/nvim/ex_eval.c | 2 +- src/nvim/ex_getln.c | 16 ++--- src/nvim/file_search.c | 100 ++++++++++++++-------------- src/nvim/fileio.c | 24 +++---- src/nvim/fold.c | 8 +-- src/nvim/getchar.c | 44 ++++++------- src/nvim/globals.h | 2 +- src/nvim/hardcopy.c | 2 +- src/nvim/help.c | 15 ++--- src/nvim/highlight_group.c | 6 +- src/nvim/if_cscope.c | 10 +-- src/nvim/indent.c | 8 +-- src/nvim/indent_c.c | 6 +- src/nvim/insexpand.c | 94 +++++++++++++-------------- src/nvim/lua/converter.c | 8 +-- src/nvim/lua/stdlib.c | 2 +- src/nvim/lua/treesitter.c | 2 +- src/nvim/macros.h | 2 +- src/nvim/mapping.c | 74 ++++++++++----------- src/nvim/mapping.h | 2 +- src/nvim/mark.c | 12 ++-- src/nvim/match.c | 6 +- src/nvim/mbyte.c | 32 ++++----- src/nvim/memfile.c | 12 ++-- src/nvim/memfile_defs.h | 2 +- src/nvim/memline.c | 76 +++++++++++----------- src/nvim/mouse.c | 2 +- src/nvim/normal.c | 26 ++++---- src/nvim/ops.c | 54 ++++++++-------- src/nvim/option.c | 62 +++++++++--------- src/nvim/optionstr.c | 2 +- src/nvim/os/env.c | 6 +- src/nvim/os/shell.c | 10 +-- src/nvim/path.c | 77 +++++++++++----------- src/nvim/plines.c | 4 +- src/nvim/quickfix.c | 12 ++-- src/nvim/regexp.c | 64 +++++++++--------- src/nvim/regexp_bt.c | 4 +- src/nvim/regexp_defs.h | 2 +- src/nvim/regexp_nfa.c | 6 +- src/nvim/screen.c | 2 +- src/nvim/search.c | 36 +++++------ src/nvim/shada.c | 2 +- src/nvim/spell.c | 30 ++++----- src/nvim/spell_defs.h | 6 +- src/nvim/spellfile.c | 143 ++++++++++++++++++++--------------------- src/nvim/spellsuggest.c | 32 ++++----- src/nvim/statusline.c | 22 +++---- src/nvim/strings.c | 15 ++--- src/nvim/syntax.c | 8 +-- src/nvim/tag.c | 99 ++++++++++++++-------------- src/nvim/tag.h | 2 +- src/nvim/textformat.c | 28 ++++---- src/nvim/textobject.c | 4 +- src/nvim/undo.c | 12 ++-- 75 files changed, 867 insertions(+), 882 deletions(-) (limited to 'src') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 16f574f46d..6f8cad3e33 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -570,7 +570,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In char *str_at_end = NULL; // Another call to ml_get_buf() may free the line, so make a copy. - str_at_start = xstrdup((char *)ml_get_buf(buf, (linenr_T)start_row, false)); + str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false)); size_t len_at_start = strlen(str_at_start); if (start_col < 0 || (size_t)start_col > len_at_start) { api_set_error(err, kErrorTypeValidation, "start_col out of bounds"); @@ -578,7 +578,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In } // Another call to ml_get_buf() may free the line, so make a copy. - str_at_end = xstrdup((char *)ml_get_buf(buf, (linenr_T)end_row, false)); + str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false)); size_t len_at_end = strlen(str_at_end); if (end_col < 0 || (size_t)end_col > len_at_end) { api_set_error(err, kErrorTypeValidation, "end_col out of bounds"); @@ -608,7 +608,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In for (int64_t i = 1; i < end_row - start_row; i++) { int64_t lnum = start_row + i; - const char *bufline = (char *)ml_get_buf(buf, (linenr_T)lnum, false); + const char *bufline = ml_get_buf(buf, (linenr_T)lnum, false); old_byte += (bcount_t)(strlen(bufline)) + 1; } old_byte += (bcount_t)end_col + 1; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index ebcf6cca6d..22d2ffbaf1 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -466,7 +466,7 @@ bool buf_collect_lines(buf_T *buf, size_t n, int64_t start, bool replace_nl, Arr return false; } - const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false); + const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false); Object str = STRING_OBJ(cstr_to_string(bufstr)); if (replace_nl) { @@ -499,7 +499,7 @@ String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col return rv; } - const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false); + const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false); size_t line_length = strlen(bufstr); start_col = start_col < 0 ? (int64_t)line_length + start_col + 1 : start_col; diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index e6ac1f6247..0000636417 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -86,7 +86,7 @@ void alist_expand(int *fnum_list, int fnum_len) // can't set the options. p_su = empty_option; for (int i = 0; i < GARGCOUNT; i++) { - old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname); + old_arg_files[i] = xstrdup(GARGLIST[i].ae_fname); } int old_arg_count = GARGCOUNT; char **new_arg_files; diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 1c1de214cd..635875b16f 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -2214,7 +2214,7 @@ bool has_autocmd(event_T event, char *sfname, buf_T *buf) #ifdef BACKSLASH_IN_FILENAME // Replace all backslashes with forward slashes. This makes the // autocommand patterns portable between Unix and Windows. - sfname = vim_strsave(sfname); + sfname = xstrdup(sfname); forward_slash(sfname); forward_slash(fname); #endif diff --git a/src/nvim/change.c b/src/nvim/change.c index 5e9edac4f2..f4568fc617 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -774,7 +774,7 @@ int del_char(bool fixpos) int del_chars(long count, int fixpos) { int bytes = 0; - char *p = (char *)get_cursor_pos_ptr(); + char *p = get_cursor_pos_ptr(); for (long i = 0; i < count && *p != NUL; i++) { int l = utfc_ptr2len(p); bytes += l; @@ -1036,7 +1036,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) colnr_T mincol = curwin->w_cursor.col + 1; // make a copy of the current line so we can mess with it - char *saved_line = (char *)vim_strsave((char_u *)get_cursor_line_ptr()); + char *saved_line = xstrdup(get_cursor_line_ptr()); if (State & VREPLACE_FLAG) { // With MODE_VREPLACE we make a copy of the next line, which we will be diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 3396e2de41..693ff90179 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -913,7 +913,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en int ts = (int)wp->w_buffer->b_p_ts; colnr_T vcol = 0; - char *line = ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line + char *line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line if (pos->col == MAXCOL) { // continue until the NUL @@ -1076,7 +1076,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e colnr_T endadd = 0; // Cannot put the cursor on part of a wide character. - char *ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); + char *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col < (colnr_T)STRLEN(ptr)) { int c = utf_ptr2char(ptr + pos->col); diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 30e734b93f..3f624c77f3 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -183,7 +183,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) if (type == WILD_NEXT || type == WILD_PREV) { // Get next/previous match for a previous expanded pattern. - p2 = ExpandOne(xp, NULL, NULL, 0, type); + p2 = (char_u *)ExpandOne(xp, NULL, NULL, 0, type); } else { // Translate string into pattern and expand it. p1 = (char_u *)addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); @@ -193,8 +193,8 @@ int nextwild(expand_T *xp, int type, int options, bool escape) | WILD_SILENT | (escape ? WILD_ESCAPE : 0) | (p_wic ? WILD_ICASE : 0)); - p2 = ExpandOne(xp, p1, (char_u *)xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len), - use_options, type); + p2 = (char_u *)ExpandOne(xp, (char *)p1, xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len), + use_options, type); xfree(p1); // xp->xp_pattern might have been modified by ExpandOne (for example, @@ -278,7 +278,7 @@ void cmdline_pum_cleanup(CmdlineInfo *cclp) /// Get the next or prev cmdline completion match. The index of the match is set /// in "p_findex" -static char_u *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char_u *orig_save) +static char *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char *orig_save) { if (xp->xp_numfiles <= 0) { return NULL; @@ -318,17 +318,17 @@ static char_u *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, cha } *p_findex = findex; - return vim_strsave(findex == -1 ? orig_save : (char_u *)xp->xp_files[findex]); + return xstrdup(findex == -1 ? orig_save : xp->xp_files[findex]); } /// Start the command-line expansion and get the matches. -static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options) +static char *ExpandOne_start(int mode, expand_T *xp, char *str, int options) { int non_suf_match; // number without matching suffix - char_u *ss = NULL; + char *ss = NULL; // Do the expansion. - if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, options) == FAIL) { + if (ExpandFromContext(xp, (char_u *)str, &xp->xp_numfiles, &xp->xp_files, options) == FAIL) { #ifdef FNAME_ILLEGAL // Illegal file name has been silently skipped. But when there // are wildcards, the real problem is that there was no match, @@ -343,7 +343,7 @@ static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options) } } else { // Escape the matches for use on the command line. - ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); + ExpandEscape(xp, (char_u *)str, xp->xp_numfiles, xp->xp_files, options); // Check for matching suffixes in file names. if (mode != WILD_ALL && mode != WILD_ALL_KEEP @@ -378,7 +378,7 @@ static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options) } } if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) { - ss = vim_strsave((char_u *)xp->xp_files[0]); + ss = xstrdup(xp->xp_files[0]); } } } @@ -458,11 +458,11 @@ static char *find_longest_match(expand_T *xp, int options) /// The variables xp->xp_context and xp->xp_backslash must have been set! /// /// @param orig allocated copy of original of expanded string -char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode) +char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) { - char_u *ss = NULL; + char *ss = NULL; static int findex; - static char_u *orig_save = NULL; // kept value of orig + static char *orig_save = NULL; // kept value of orig int orig_saved = false; int i; @@ -472,10 +472,11 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode } if (mode == WILD_CANCEL) { - ss = vim_strsave(orig_save ? orig_save : (char_u *)""); + ss = xstrdup(orig_save ? orig_save : ""); } else if (mode == WILD_APPLY) { - ss = vim_strsave(findex == -1 ? (orig_save ? orig_save : (char_u *)"") - : (char_u *)xp->xp_files[findex]); + ss = xstrdup(findex == -1 + ? (orig_save ? orig_save : "") + : xp->xp_files[findex]); } // free old names @@ -500,7 +501,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode // Find longest common part if (mode == WILD_LONGEST && xp->xp_numfiles > 0) { - ss = (char_u *)find_longest_match(xp, options); + ss = find_longest_match(xp, options); findex = -1; // next p_wc gets first one } @@ -1915,7 +1916,7 @@ int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char *** } /// Expand file or directory names. -static int expand_files_and_dirs(expand_T *xp, char_u *pat, char ***file, int *num_file, int flags, +static int expand_files_and_dirs(expand_T *xp, char *pat, char ***file, int *num_file, int flags, int options) { bool free_pat = false; @@ -1923,7 +1924,7 @@ static int expand_files_and_dirs(expand_T *xp, char_u *pat, char ***file, int *n // for ":set path=" and ":set tags=" halve backslashes for escaped space if (xp->xp_backslash != XP_BS_NONE) { free_pat = true; - pat = vim_strsave(pat); + pat = xstrdup(pat); for (int i = 0; pat[i]; i++) { if (pat[i] == '\\') { if (xp->xp_backslash == XP_BS_THREE @@ -2124,7 +2125,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f if (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_DIRECTORIES || xp->xp_context == EXPAND_FILES_IN_PATH) { - return expand_files_and_dirs(xp, pat, file, num_file, flags, options); + return expand_files_and_dirs(xp, (char *)pat, file, num_file, flags, options); } *file = NULL; @@ -2142,7 +2143,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f if (xp->xp_context == EXPAND_SHELLCMD) { *file = NULL; - expand_shellcmd(pat, num_file, file, flags); + expand_shellcmd((char *)pat, num_file, file, flags); return OK; } if (xp->xp_context == EXPAND_OLD_SETTING) { @@ -2238,18 +2239,18 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha { int i; size_t count = 0; - char_u *str; + char *str; // count the number of matching names for (i = 0;; i++) { - str = (char_u *)(*func)(xp, i); + str = (*func)(xp, i); if (str == NULL) { // end of list break; } if (*str == NUL) { // skip empty strings continue; } - if (vim_regexec(regmatch, (char *)str, (colnr_T)0)) { + if (vim_regexec(regmatch, str, (colnr_T)0)) { count++; } } @@ -2263,20 +2264,20 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha // copy the matching names into allocated memory count = 0; for (i = 0;; i++) { - str = (char_u *)(*func)(xp, i); + str = (*func)(xp, i); if (str == NULL) { // End of list. break; } if (*str == NUL) { // Skip empty strings. continue; } - if (vim_regexec(regmatch, (char *)str, (colnr_T)0)) { + if (vim_regexec(regmatch, str, (colnr_T)0)) { if (escaped) { - str = vim_strsave_escaped(str, (char_u *)" \t\\."); + str = (char *)vim_strsave_escaped((char_u *)str, (char_u *)" \t\\."); } else { - str = vim_strsave(str); + str = xstrdup(str); } - (*file)[count++] = (char *)str; + (*file)[count++] = str; if (func == get_menu_names) { // Test for separator added by get_menu_names(). str += STRLEN(str) - 1; @@ -2313,22 +2314,22 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha /// *file will either be set to NULL or point to /// allocated memory. /// @param flagsarg is a combination of EW_* flags. -static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int flagsarg) +static void expand_shellcmd(char *filepat, int *num_file, char ***file, int flagsarg) FUNC_ATTR_NONNULL_ALL { - char_u *pat; + char *pat; int i; - char_u *path = NULL; + char *path = NULL; garray_T ga; char *buf = xmalloc(MAXPATHL); size_t l; - char_u *s, *e; + char *s, *e; int flags = flagsarg; int ret; bool did_curdir = false; // for ":set path=" and ":set tags=" halve backslashes for escaped space - pat = vim_strsave(filepat); + pat = xstrdup(filepat); for (i = 0; pat[i]; i++) { if (pat[i] == '\\' && pat[i + 1] == ' ') { STRMOVE(pat + i, pat + i + 1); @@ -2340,14 +2341,14 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int fl bool mustfree = false; // Track memory allocation for *path. if (pat[0] == '.' && (vim_ispathsep(pat[1]) || (pat[1] == '.' && vim_ispathsep(pat[2])))) { - path = (char_u *)"."; + path = "."; } else { // For an absolute name we don't use $PATH. - if (!path_is_absolute(pat)) { - path = (char_u *)vim_getenv("PATH"); + if (!path_is_absolute((char_u *)pat)) { + path = vim_getenv("PATH"); } if (path == NULL) { - path = (char_u *)""; + path = ""; } else { mustfree = true; } @@ -2360,7 +2361,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int fl hashtab_T found_ht; hash_init(&found_ht); for (s = path;; s = e) { - e = (char_u *)vim_strchr((char *)s, ENV_SEPCHAR); + e = vim_strchr(s, ENV_SEPCHAR); if (e == NULL) { e = s + STRLEN(s); } @@ -2895,7 +2896,7 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) theend: pat = (char_u *)addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context); - ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP); + ExpandOne(&xpc, (char *)pat, NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); for (int i = 0; i < xpc.xp_numfiles; i++) { diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 629c47f24a..38353f44b5 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -382,13 +382,13 @@ static int calc_hist_idx(int histype, int num) /// Get a history entry by its index. /// /// @param histype may be one of the HIST_ values. -static char_u *get_history_entry(int histype, int idx) +static char *get_history_entry(int histype, int idx) { idx = calc_hist_idx(histype, idx); if (idx >= 0) { - return (char_u *)history[histype][idx].hisstr; + return history[histype][idx].hisstr; } else { - return (char_u *)""; + return ""; } } @@ -556,7 +556,7 @@ void f_histget(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) idx = (int)tv_get_number_chk(&argvars[1], NULL); } // -1 on type error - rettv->vval.v_string = (char *)vim_strsave(get_history_entry(type, idx)); + rettv->vval.v_string = xstrdup(get_history_entry(type, idx)); } rettv->v_type = VAR_STRING; } diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 2a3fe9701c..cd651fcf4c 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -101,7 +101,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a || (VIsual_active && *p_sel != 'o') || ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL); - char_u *line = ml_get_buf(curbuf, pos->lnum, false); + char_u *line = (char_u *)ml_get_buf(curbuf, pos->lnum, false); if (wcol >= MAXCOL) { idx = (int)STRLEN(line) - 1 + one_more; @@ -308,7 +308,7 @@ void check_pos(buf_T *buf, pos_T *pos) } if (pos->col > 0) { - char_u *line = ml_get_buf(buf, pos->lnum, false); + char_u *line = (char_u *)ml_get_buf(buf, pos->lnum, false); colnr_T len = (colnr_T)STRLEN(line); if (pos->col > len) { pos->col = len; @@ -481,7 +481,7 @@ bool leftcol_changed(void) int gchar_cursor(void) { - return utf_ptr2char((char *)get_cursor_pos_ptr()); + return utf_ptr2char(get_cursor_pos_ptr()); } /// Write a character at the current cursor position. @@ -489,18 +489,17 @@ int gchar_cursor(void) void pchar_cursor(char_u c) { *(ml_get_buf(curbuf, curwin->w_cursor.lnum, true) - + curwin->w_cursor.col) = c; + + curwin->w_cursor.col) = (char)c; } /// @return pointer to cursor line. char *get_cursor_line_ptr(void) { - return (char *)ml_get_buf(curbuf, curwin->w_cursor.lnum, false); + return ml_get_buf(curbuf, curwin->w_cursor.lnum, false); } /// @return pointer to cursor position. -char_u *get_cursor_pos_ptr(void) +char *get_cursor_pos_ptr(void) { - return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) + - curwin->w_cursor.col; + return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) + curwin->w_cursor.col; } diff --git a/src/nvim/diff.c b/src/nvim/diff.c index a3046bb7d7..69883966ab 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -573,9 +573,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) if (dir == BACKWARD) { off_org = dp->df_count[i_org] - 1; } - char *line_org = (char *)vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], - dp->df_lnum[i_org] + off_org, - false)); + char *line_org = xstrdup(ml_get_buf(tp->tp_diffbuf[i_org], + dp->df_lnum[i_org] + off_org, + false)); int i_new; for (i_new = i_org + 1; i_new < DB_COUNT; i_new++) { @@ -592,9 +592,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) break; } - if (diff_cmp((char_u *)line_org, ml_get_buf(tp->tp_diffbuf[i_new], - dp->df_lnum[i_new] + off_new, - false)) != 0) { + if (diff_cmp((char_u *)line_org, (char_u *)ml_get_buf(tp->tp_diffbuf[i_new], + dp->df_lnum[i_new] + off_new, + false)) != 0) { break; } } @@ -750,7 +750,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) len = 0; for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char_u *s = ml_get_buf(buf, lnum, false); *s != NUL;) { + for (char_u *s = (char_u *)ml_get_buf(buf, lnum, false); *s != NUL;) { if (diff_flags & DIFF_ICASE) { int c; char cbuf[MB_MAXBYTES + 1]; @@ -824,9 +824,9 @@ static void diff_try_update(diffio_T *dio, int idx_orig, exarg_T *eap) ga_init(&dio->dio_diff.dout_ga, sizeof(char *), 1000); } else { // We need three temp file names. - dio->dio_orig.din_fname = vim_tempname(); - dio->dio_new.din_fname = vim_tempname(); - dio->dio_diff.dout_fname = vim_tempname(); + dio->dio_orig.din_fname = (char_u *)vim_tempname(); + dio->dio_new.din_fname = (char_u *)vim_tempname(); + dio->dio_diff.dout_fname = (char_u *)vim_tempname(); if (dio->dio_orig.din_fname == NULL || dio->dio_new.din_fname == NULL || dio->dio_diff.dout_fname == NULL) { @@ -1178,9 +1178,9 @@ void ex_diffpatch(exarg_T *eap) // We need two temp file names. // Name of original temp file. - char_u *tmp_orig = vim_tempname(); + char_u *tmp_orig = (char_u *)vim_tempname(); // Name of patched temp file. - char_u *tmp_new = vim_tempname(); + char_u *tmp_new = (char_u *)vim_tempname(); if ((tmp_orig == NULL) || (tmp_new == NULL)) { goto theend; @@ -1920,11 +1920,11 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2) } for (int i = 0; i < dp->df_count[idx1]; i++) { - char *line = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], - dp->df_lnum[idx1] + i, false)); + char *line = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx1], + dp->df_lnum[idx1] + i, false)); - int cmp = diff_cmp((char_u *)line, ml_get_buf(curtab->tp_diffbuf[idx2], - dp->df_lnum[idx2] + i, false)); + int cmp = diff_cmp((char_u *)line, (char_u *)ml_get_buf(curtab->tp_diffbuf[idx2], + dp->df_lnum[idx2] + i, false)); xfree(line); if (cmp != 0) { @@ -2290,7 +2290,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) int l; // Make a copy of the line, the next ml_get() will invalidate it. - char *line_org = (char *)vim_strsave(ml_get_buf(wp->w_buffer, lnum, false)); + char *line_org = xstrdup(ml_get_buf(wp->w_buffer, lnum, false)); int idx = diff_buf_idx(wp->w_buffer); if (idx == DB_COUNT) { @@ -2322,8 +2322,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) continue; } added = false; - line_new = (char *)ml_get_buf(curtab->tp_diffbuf[i], - dp->df_lnum[i] + off, false); + line_new = ml_get_buf(curtab->tp_diffbuf[i], dp->df_lnum[i] + off, false); // Search for start of difference si_org = si_new = 0; @@ -2718,7 +2717,7 @@ void ex_diffgetput(exarg_T *eap) if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) { break; } - p = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false)); + p = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false)); ml_append(lnum + i - 1, p, 0, false); xfree(p); added++; diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 53b6c66c46..8e31d3feab 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1932,9 +1932,9 @@ void f_digraph_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } int code = digraph_get(digraphs[0], digraphs[1], false); - char_u buf[NUMBUFLEN]; - buf[utf_char2bytes(code, (char *)buf)] = NUL; - rettv->vval.v_string = (char *)vim_strsave(buf); + char buf[NUMBUFLEN]; + buf[utf_char2bytes(code, buf)] = NUL; + rettv->vval.v_string = xstrdup(buf); } /// "digraph_getlist()" function diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 7846510ad9..9de8b9996a 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -689,7 +689,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // Trick: skip a few chars for C/shell/Vim comments nextline[SPWORDLEN] = NUL; if (lnum < wp->w_buffer->b_ml.ml_line_count) { - line = ml_get_buf(wp->w_buffer, lnum + 1, false); + line = (char_u *)ml_get_buf(wp->w_buffer, lnum + 1, false); spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); } @@ -866,7 +866,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, line_attr_lowprio_save = line_attr_lowprio; } - line = end_fill ? (char_u *)"" : ml_get_buf(wp->w_buffer, lnum, false); + line = end_fill ? (char_u *)"" : (char_u *)ml_get_buf(wp->w_buffer, lnum, false); ptr = line; if (has_spell && !number_only) { @@ -1006,7 +1006,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, len = spell_move_to(wp, FORWARD, true, true, &spell_hlf); // spell_move_to() may call ml_get() and make "line" invalid - line = ml_get_buf(wp->w_buffer, lnum, false); + line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false); ptr = line + linecol; if (len == 0 || (int)wp->w_cursor.col > ptr - line) { @@ -1224,7 +1224,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, c_extra = ' '; c_final = NUL; n_extra = - get_breakindent_win(wp, ml_get_buf(wp->w_buffer, lnum, false)); + get_breakindent_win(wp, (char_u *)ml_get_buf(wp->w_buffer, lnum, false)); if (row == startrow) { n_extra -= win_col_off2(wp); if (n_extra < 0) { @@ -1676,7 +1676,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // Need to get the line again, a multi-line regexp may // have made it invalid. - line = ml_get_buf(wp->w_buffer, lnum, false); + line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false); ptr = line + v; if (!attr_pri) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b20fc7d44a..f7a16abfb2 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1439,21 +1439,21 @@ void edit_putchar(int c, bool highlight) } } -/// Return the effective prompt for the specified buffer. -char_u *buf_prompt_text(const buf_T *const buf) +/// @return the effective prompt for the specified buffer. +char *buf_prompt_text(const buf_T *const buf) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { if (buf->b_prompt_text == NULL) { - return (char_u *)"% "; + return "% "; } - return (char_u *)buf->b_prompt_text; + return buf->b_prompt_text; } // Return the effective prompt for the current buffer. char_u *prompt_text(void) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { - return buf_prompt_text(curbuf); + return (char_u *)buf_prompt_text(curbuf); } // Prepare for prompt mode: Make sure the last line has the prompt text. @@ -1574,11 +1574,11 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang int start_col; colnr_T vc; colnr_T orig_col = 0; // init for GCC - char_u *new_line, *orig_line = NULL; // init for GCC + char *new_line, *orig_line = NULL; // init for GCC // MODE_VREPLACE state needs to know what the line was like before changing if (State & VREPLACE_FLAG) { - orig_line = vim_strsave((char_u *)get_cursor_line_ptr()); // Deal with NULL below + orig_line = xstrdup(get_cursor_line_ptr()); // Deal with NULL below orig_col = curwin->w_cursor.col; } @@ -1733,14 +1733,14 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // then put it back again the way we wanted it. if (State & VREPLACE_FLAG) { // Save new line - new_line = vim_strsave((char_u *)get_cursor_line_ptr()); + new_line = xstrdup(get_cursor_line_ptr()); // We only put back the new line up to the cursor new_line[curwin->w_cursor.col] = NUL; int new_col = curwin->w_cursor.col; // Put back original line - ml_replace(curwin->w_cursor.lnum, (char *)orig_line, false); + ml_replace(curwin->w_cursor.lnum, orig_line, false); curwin->w_cursor.col = orig_col; curbuf_splice_pending++; @@ -1749,7 +1749,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang backspace_until_column(0); // Insert new stuff into line again - ins_bytes((char *)new_line); + ins_bytes(new_line); xfree(new_line); @@ -1813,7 +1813,7 @@ static bool del_char_after_col(int limit_col) // composing character. mb_adjust_cursor(); while (curwin->w_cursor.col < (colnr_T)limit_col) { - int l = utf_ptr2len((char *)get_cursor_pos_ptr()); + int l = utf_ptr2len(get_cursor_pos_ptr()); if (l == 0) { // end of line break; @@ -2466,7 +2466,7 @@ int oneright(void) pos_T prevpos = curwin->w_cursor; // Adjust for multi-wide char (excluding TAB) - ptr = (char *)get_cursor_pos_ptr(); + ptr = get_cursor_pos_ptr(); coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char(ptr))) ? ptr2cells(ptr) : 1)); curwin->w_set_curswant = true; @@ -2475,7 +2475,7 @@ int oneright(void) || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL; } - ptr = (char *)get_cursor_pos_ptr(); + ptr = get_cursor_pos_ptr(); if (*ptr == NUL) { return FAIL; // already at the very end } @@ -2518,7 +2518,7 @@ int oneleft(void) if (curwin->w_cursor.coladd == 1) { // Adjust for multi-wide char (not a TAB) - char *ptr = (char *)get_cursor_pos_ptr(); + char *ptr = get_cursor_pos_ptr(); if (*ptr != TAB && vim_isprintc(utf_ptr2char(ptr)) && ptr2cells(ptr) > 1) { curwin->w_cursor.coladd = 0; } @@ -2720,19 +2720,19 @@ char_u *get_last_insert(void) // Returns pointer to allocated memory (must be freed) or NULL. char_u *get_last_insert_save(void) { - char_u *s; + char *s; int len; if (last_insert == NULL) { return NULL; } - s = vim_strsave(last_insert + last_insert_skip); + s = xstrdup((char *)last_insert + last_insert_skip); len = (int)STRLEN(s); if (len > 0 && s[len - 1] == ESC) { // remove trailing ESC s[len - 1] = NUL; } - return s; + return (char_u *)s; } /// Check the word in front of the cursor for an abbreviation. @@ -2934,7 +2934,7 @@ static void replace_do_bs(int limit_col) // Get the number of screen cells used by the character we are // going to delete. getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL); - orig_vcols = win_chartabsize(curwin, (char *)get_cursor_pos_ptr(), start_vcol); + orig_vcols = win_chartabsize(curwin, get_cursor_pos_ptr(), start_vcol); } (void)del_char_after_col(limit_col); if (l_State & VREPLACE_FLAG) { @@ -2945,7 +2945,7 @@ static void replace_do_bs(int limit_col) if (l_State & VREPLACE_FLAG) { // Get the number of screen cells used by the inserted characters - p = get_cursor_pos_ptr(); + p = (char_u *)get_cursor_pos_ptr(); ins_len = (int)STRLEN(p) - orig_len; vcol = start_vcol; for (i = 0; i < ins_len; i++) { @@ -3186,7 +3186,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) if (keytyped == (int)p[-1] || (icase && keytyped < 256 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1]))) { - line = get_cursor_pos_ptr(); + line = (char_u *)get_cursor_pos_ptr(); assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX); if ((curwin->w_cursor.col == (colnr_T)(p - look) || !vim_iswordc(line[-(p - look) - 1])) @@ -3880,7 +3880,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) // again when auto-formatting. if (has_format_option(FO_AUTO) && has_format_option(FO_WHITE_PAR)) { - char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); + char_u *ptr = (char_u *)ml_get_buf(curbuf, curwin->w_cursor.lnum, true); int len; len = (int)STRLEN(ptr); @@ -3974,7 +3974,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) // delete characters until we are at or before want_vcol while (vcol > want_vcol && curwin->w_cursor.col > 0 - && (cc = *(get_cursor_pos_ptr() - 1), ascii_iswhite(cc))) { + && (cc = (uint8_t)(*(get_cursor_pos_ptr() - 1)), ascii_iswhite(cc))) { ins_bs_one(&vcol); } @@ -4006,7 +4006,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) // Delete up to starting point, start of line or previous word. int prev_cclass = 0; - int cclass = mb_get_class(get_cursor_pos_ptr()); + int cclass = mb_get_class((char_u *)get_cursor_pos_ptr()); do { if (!revins_on) { // put cursor on char to be deleted dec_cursor(); @@ -4014,7 +4014,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) cc = gchar_cursor(); // look multi-byte character class prev_cclass = cclass; - cclass = mb_get_class(get_cursor_pos_ptr()); + cclass = mb_get_class((char_u *)get_cursor_pos_ptr()); if (mode == BACKSPACE_WORD && !ascii_isspace(cc)) { // start of word? mode = BACKSPACE_WORD_NOT_SPACE; temp = vim_iswordc(cc); @@ -4033,7 +4033,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) } else { const int l_p_deco = p_deco; if (l_p_deco) { - (void)utfc_ptr2char((char *)get_cursor_pos_ptr(), cpc); + (void)utfc_ptr2char(get_cursor_pos_ptr(), cpc); } (void)del_char(false); // If there are combining characters and 'delcombine' is set @@ -4286,7 +4286,7 @@ static void ins_right(void) if (virtual_active()) { oneright(); } else { - curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr()); + curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); } revins_legal++; @@ -4507,7 +4507,7 @@ static bool ins_tab(void) || get_sts_value() > 0 || (p_sta && ind))) { char_u *ptr; - char_u *saved_line = NULL; // init for GCC + char *saved_line = NULL; // init for GCC pos_T pos; pos_T fpos; pos_T *cursor; @@ -4520,10 +4520,10 @@ static bool ins_tab(void) if (State & VREPLACE_FLAG) { pos = curwin->w_cursor; cursor = &pos; - saved_line = vim_strsave((char_u *)get_cursor_line_ptr()); - ptr = saved_line + pos.col; + saved_line = xstrdup(get_cursor_line_ptr()); + ptr = (char_u *)saved_line + pos.col; } else { - ptr = get_cursor_pos_ptr(); + ptr = (char_u *)get_cursor_pos_ptr(); cursor = &curwin->w_cursor; } @@ -4627,7 +4627,7 @@ static bool ins_tab(void) // Insert each char in saved_line from changed_col to // ptr-cursor - ins_bytes_len((char *)saved_line + change_col, (size_t)(cursor->col - change_col)); + ins_bytes_len(saved_line + change_col, (size_t)(cursor->col - change_col)); } } @@ -4946,13 +4946,13 @@ static char_u *do_insert_char_pre(int c) textlock++; set_vim_var_string(VV_CHAR, buf, -1); - char_u *res = NULL; + char *res = NULL; if (ins_apply_autocmds(EVENT_INSERTCHARPRE)) { // Get the value of v:char. It may be empty or more than one // character. Only use it when changed, otherwise continue with the // original character to avoid breaking autoindent. if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) { - res = vim_strsave((char_u *)get_vim_var_str(VV_CHAR)); + res = xstrdup(get_vim_var_str(VV_CHAR)); } } @@ -4962,7 +4962,7 @@ static char_u *do_insert_char_pre(int c) // Restore the State, it may have been changed. State = save_State; - return res; + return (char_u *)res; } bool get_can_cindent(void) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 06ee4c8d81..0c41381313 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3909,7 +3909,7 @@ char *partial_name(partial_T *pt) FUNC_ATTR_PURE { if (pt->pt_name != NULL) { - return (char *)pt->pt_name; + return pt->pt_name; } return (char *)pt->pt_func->uf_name; } @@ -3924,7 +3924,7 @@ static void partial_free(partial_T *pt) xfree(pt->pt_argv); tv_dict_unref(pt->pt_dict); if (pt->pt_name != NULL) { - func_unref(pt->pt_name); + func_unref((char_u *)pt->pt_name); xfree(pt->pt_name); } else { func_ptr_unref(pt->pt_func); @@ -4478,7 +4478,7 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack // A partial does not have a copyID, because it cannot contain itself. if (pt != NULL) { - abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID); + abort = set_ref_in_func((char_u *)pt->pt_name, pt->pt_func, copyID); if (pt->pt_dict != NULL) { typval_T dtv; @@ -4846,7 +4846,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) break; } - vimvars[VV_KEY].vv_str = (char *)vim_strsave(di->di_key); + vimvars[VV_KEY].vv_str = xstrdup((char *)di->di_key); int r = filter_map_one(&di->di_tv, expr, map, &rem); tv_clear(&vimvars[VV_KEY].vv_tv); if (r == FAIL || did_emsg) { @@ -5113,7 +5113,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) func_ptr_ref(pt->pt_func); xfree(name); } else { - pt->pt_name = (char_u *)name; + pt->pt_name = name; func_ref((char_u *)name); } @@ -6208,7 +6208,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) buf_T *buf = buflist_findnr((int)tv->vval.v_number); if (buf) { for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { + for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) { *len += 1; } *len += 1; @@ -6226,7 +6226,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) char *ret = xmalloc((size_t)(*len) + 1); char *end = ret; for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { + for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) { *end++ = (*p == '\n') ? NUL : *p; } *end++ = '\n'; @@ -6275,7 +6275,7 @@ int buf_byteidx_to_charidx(buf_T *buf, linenr_T lnum, int byteidx) lnum = buf->b_ml.ml_line_count; } - char *str = (char *)ml_get_buf(buf, lnum, false); + char *str = ml_get_buf(buf, lnum, false); if (*str == NUL) { return 0; @@ -6313,7 +6313,7 @@ int buf_charidx_to_byteidx(buf_T *buf, linenr_T lnum, int charidx) lnum = buf->b_ml.ml_line_count; } - char *str = (char *)ml_get_buf(buf, lnum, false); + char *str = ml_get_buf(buf, lnum, false); // Convert the character offset to a byte offset char *t = str; diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 60a6ec6201..408b6e6cb5 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -849,7 +849,7 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol) // col(".") when the cursor is on the NUL at the end of the line // because of "coladd" can be seen as an extra column. if (virtual_active() && fp == &curwin->w_cursor) { - char *p = (char *)get_cursor_pos_ptr(); + char *p = get_cursor_pos_ptr(); if (curwin->w_cursor.coladd >= (colnr_T)win_chartabsize(curwin, p, curwin->w_virtcol - curwin->w_cursor.coladd)) { @@ -930,12 +930,12 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } // Return the current directory - char_u *cwd = xmalloc(MAXPATHL); - if (os_dirname(cwd, MAXPATHL) != FAIL) { + char *cwd = xmalloc(MAXPATHL); + if (os_dirname((char_u *)cwd, MAXPATHL) != FAIL) { #ifdef BACKSLASH_IN_FILENAME slash_adjust(cwd); #endif - rettv->vval.v_string = (char *)vim_strsave(cwd); + rettv->vval.v_string = xstrdup(cwd); } xfree(cwd); @@ -2016,10 +2016,9 @@ static void f_expand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) options += WILD_ICASE; } if (rettv->v_type == VAR_STRING) { - rettv->vval.v_string = (char *)ExpandOne(&xpc, (char_u *)s, NULL, options, - WILD_ALL); + rettv->vval.v_string = ExpandOne(&xpc, (char *)s, NULL, options, WILD_ALL); } else { - ExpandOne(&xpc, (char_u *)s, NULL, options, WILD_ALL_KEEP); + ExpandOne(&xpc, (char *)s, NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); for (int i = 0; i < xpc.xp_numfiles; i++) { tv_list_append_string(rettv->vval.v_list, @@ -2437,7 +2436,7 @@ static void f_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) pt = argvars[0].vval.v_partial; } else { CLEAR_FIELD(fref_pt); - fref_pt.pt_name = (char_u *)argvars[0].vval.v_string; + fref_pt.pt_name = argvars[0].vval.v_string; pt = &fref_pt; } @@ -2579,9 +2578,8 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, int retli } } else { rettv->v_type = VAR_STRING; - rettv->vval.v_string = - (char *)((start >= 1 && start <= buf->b_ml.ml_line_count) - ? vim_strsave(ml_get_buf(buf, start, false)) : NULL); + rettv->vval.v_string = ((start >= 1 && start <= buf->b_ml.ml_line_count) + ? xstrdup(ml_get_buf(buf, start, false)) : NULL); } } @@ -2919,7 +2917,7 @@ static void f_getftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "getftype({fname})" function static void f_getftype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - char_u *type = NULL; + char *type = NULL; char *t; const char *fname = tv_get_string(&argvars[0]); @@ -2945,9 +2943,9 @@ static void f_getftype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } else { t = "other"; } - type = vim_strsave((char_u *)t); + type = xstrdup(t); } - rettv->vval.v_string = (char *)type; + rettv->vval.v_string = type; } /// "getjumplist()" function @@ -3441,11 +3439,11 @@ static void f_glob(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) options += WILD_ICASE; } if (rettv->v_type == VAR_STRING) { - rettv->vval.v_string = (char *)ExpandOne(&xpc, (char_u *) - tv_get_string(&argvars[0]), NULL, options, - WILD_ALL); + rettv->vval.v_string = ExpandOne(&xpc, (char *) + tv_get_string(&argvars[0]), NULL, options, + WILD_ALL); } else { - ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options, + ExpandOne(&xpc, (char *)tv_get_string(&argvars[0]), NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); for (int i = 0; i < xpc.xp_numfiles; i++) { @@ -5443,11 +5441,11 @@ static void f_pathshorten(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } rettv->v_type = VAR_STRING; - const char_u *p = (char_u *)tv_get_string_chk(&argvars[0]); + const char *p = tv_get_string_chk(&argvars[0]); if (p == NULL) { rettv->vval.v_string = NULL; } else { - rettv->vval.v_string = (char *)vim_strsave(p); + rettv->vval.v_string = xstrdup(p); shorten_dir_len((char_u *)rettv->vval.v_string, trim_len); } } @@ -5565,7 +5563,7 @@ static void f_prompt_getprompt(typval_T *argvars, typval_T *rettv, EvalFuncData return; } - rettv->vval.v_string = (char *)vim_strsave(buf_prompt_text(buf)); + rettv->vval.v_string = xstrdup(buf_prompt_text(buf)); } /// "prompt_setprompt({buffer}, {text})" function @@ -7107,7 +7105,7 @@ static void f_screenstring(typval_T *argvars, typval_T *rettv, EvalFuncData fptr return; } - rettv->vval.v_string = (char *)vim_strsave(grid->chars[grid->line_offset[row] + (size_t)col]); + rettv->vval.v_string = xstrdup((char *)grid->chars[grid->line_offset[row] + (size_t)col]); } /// "search()" function @@ -8052,7 +8050,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv, EvalFuncData fptr // Find the start and length of the badly spelled word. len = spell_move_to(curwin, FORWARD, true, true, &attr); if (len != 0) { - word = (char *)get_cursor_pos_ptr(); + word = get_cursor_pos_ptr(); curwin->w_set_curswant = true; } } else if (*curbuf->b_s.b_p_spl != NUL) { @@ -8740,7 +8738,7 @@ static void f_swapname(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) || buf->b_ml.ml_mfp->mf_fname == NULL) { rettv->vval.v_string = NULL; } else { - rettv->vval.v_string = (char *)vim_strsave(buf->b_ml.ml_mfp->mf_fname); + rettv->vval.v_string = xstrdup(buf->b_ml.ml_mfp->mf_fname); } } @@ -9101,7 +9099,7 @@ static void f_taglist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) static void f_tempname(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)vim_tempname(); + rettv->vval.v_string = vim_tempname(); } /// "termopen(cmd[, cwd])" function @@ -9595,12 +9593,12 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "visualmode()" function static void f_visualmode(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - char_u str[2]; + char str[2]; rettv->v_type = VAR_STRING; - str[0] = (char_u)curbuf->b_visual_mode_eval; + str[0] = (char)curbuf->b_visual_mode_eval; str[1] = NUL; - rettv->vval.v_string = (char *)vim_strsave(str); + rettv->vval.v_string = xstrdup(str); // A non-zero number or non-empty string argument: reset mode. if (non_zero_arg(&argvars[0])) { diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index a409271596..f6b97fe05b 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2777,7 +2777,7 @@ static void tv_dict_list(typval_T *const tv, typval_T *const rettv, const DictLi switch (what) { case kDictListKeys: tv_item.v_type = VAR_STRING; - tv_item.vval.v_string = (char *)vim_strsave(di->di_key); + tv_item.vval.v_string = xstrdup((char *)di->di_key); break; case kDictListValues: tv_copy(&di->di_tv, &tv_item); diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h index 8177d01f90..cf7b04c8ce 100644 --- a/src/nvim/eval/typval.h +++ b/src/nvim/eval/typval.h @@ -360,15 +360,14 @@ struct ufunc { }; struct partial_S { - int pt_refcount; ///< Reference count. - char_u *pt_name; ///< Function name; when NULL use pt_func->name. - ufunc_T *pt_func; ///< Function pointer; when NULL lookup function with - ///< pt_name. - bool pt_auto; ///< When true the partial was created by using dict.member - ///< in handle_subscript(). - int pt_argc; ///< Number of arguments. + int pt_refcount; ///< Reference count. + char *pt_name; ///< Function name; when NULL use pt_func->name. + ufunc_T *pt_func; ///< Function pointer; when NULL lookup function with pt_name. + bool pt_auto; ///< When true the partial was created by using dict.member + ///< in handle_subscript(). + int pt_argc; ///< Number of arguments. typval_T *pt_argv; ///< Arguments in allocated array. - dict_T *pt_dict; ///< Dict for "self". + dict_T *pt_dict; ///< Dict for "self". }; /// Structure used for explicit stack while garbage collecting hash tables diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 3ab66c319f..36bc51179c 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -142,18 +142,18 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int any_default = true; p = skipwhite(p) + 1; p = skipwhite(p); - char_u *expr = (char_u *)p; + char *expr = p; if (eval1(&p, &rettv, false) != FAIL) { ga_grow(default_args, 1); // trim trailing whitespace - while (p > (char *)expr && ascii_iswhite(p[-1])) { + while (p > expr && ascii_iswhite(p[-1])) { p--; } c = (char_u)(*p); *p = NUL; - expr = vim_strsave(expr); - ((char **)(default_args->ga_data))[default_args->ga_len] = (char *)expr; + expr = xstrdup(expr); + ((char **)(default_args->ga_data))[default_args->ga_len] = expr; default_args->ga_len++; *p = (char)c; } else { @@ -1680,7 +1680,7 @@ static void list_func_head(ufunc_T *fp, int indent, bool force) char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, partial_T **partial) FUNC_ATTR_NONNULL_ARG(1) { - char_u *name = NULL; + char *name = NULL; const char_u *start; const char_u *end; int lead; @@ -1739,7 +1739,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa fdp->fd_di = lv.ll_di; } if (lv.ll_tv->v_type == VAR_FUNC && lv.ll_tv->vval.v_string != NULL) { - name = vim_strsave((char_u *)lv.ll_tv->vval.v_string); + name = xstrdup(lv.ll_tv->vval.v_string); *pp = (char *)end; } else if (lv.ll_tv->v_type == VAR_PARTIAL && lv.ll_tv->vval.v_partial != NULL) { @@ -1753,7 +1753,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa memcpy(name, end + 1, (size_t)len); *pp = (char *)end + 1 + len; } else { - name = vim_strsave((char_u *)partial_name(lv.ll_tv->vval.v_partial)); + name = xstrdup(partial_name(lv.ll_tv->vval.v_partial)); *pp = (char *)end; } if (partial != NULL) { @@ -1781,28 +1781,28 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa // Check if the name is a Funcref. If so, use the value. if (lv.ll_exp_name != NULL) { len = (int)strlen(lv.ll_exp_name); - name = deref_func_name(lv.ll_exp_name, &len, partial, - flags & TFN_NO_AUTOLOAD); + name = (char *)deref_func_name(lv.ll_exp_name, &len, partial, + flags & TFN_NO_AUTOLOAD); if ((const char *)name == lv.ll_exp_name) { name = NULL; } } else if (!(flags & TFN_NO_DEREF)) { len = (int)(end - (char_u *)(*pp)); - name = deref_func_name((const char *)(*pp), &len, partial, - flags & TFN_NO_AUTOLOAD); - if (name == (char_u *)(*pp)) { + name = (char *)deref_func_name((const char *)(*pp), &len, partial, + flags & TFN_NO_AUTOLOAD); + if (name == *pp) { name = NULL; } } if (name != NULL) { - name = vim_strsave(name); + name = xstrdup(name); *pp = (char *)end; if (STRNCMP(name, "", 5) == 0) { // Change "" to the byte sequence. - name[0] = K_SPECIAL; - name[1] = KS_EXTRA; + name[0] = (char)K_SPECIAL; + name[1] = (char)KS_EXTRA; name[2] = KE_SNR; - memmove(name + 3, name + 5, strlen((char *)name + 5) + 1); + memmove(name + 3, name + 5, strlen(name + 5) + 1); } goto theend; } @@ -1865,8 +1865,8 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa name = xmalloc((size_t)len + (size_t)lead + 1); if (!skip && lead > 0) { - name[0] = K_SPECIAL; - name[1] = KS_EXTRA; + name[0] = (char)K_SPECIAL; + name[1] = (char)KS_EXTRA; name[2] = KE_SNR; if (sid_buf_len > 0) { // If it's "" memcpy(name + 3, sid_buf, sid_buf_len); @@ -1878,7 +1878,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa theend: clear_lval(&lv); - return name; + return (char_u *)name; } #define MAX_FUNC_NESTING 50 @@ -3104,7 +3104,7 @@ char *get_return_cmd(void *rettv) STRCPY(IObuff + IOSIZE - 4, "..."); } xfree(tofree); - return (char *)vim_strsave(IObuff); + return xstrdup((char *)IObuff); } /// Get next function line. @@ -3192,7 +3192,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) } else { fname = rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING ? (char_u *)rettv->vval.v_string - : rettv->vval.v_partial->pt_name; + : (char_u *)rettv->vval.v_partial->pt_name; // Translate "s:func" to the stored function name. fname = (char_u *)fname_trans_sid((char *)fname, (char *)fname_buf, (char **)&tofree, &error); fp = find_func(fname); @@ -3208,7 +3208,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) pt->pt_auto = true; if (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING) { // Just a function: Take over the function name and use selfdict. - pt->pt_name = (char_u *)rettv->vval.v_string; + pt->pt_name = rettv->vval.v_string; } else { partial_T *ret_pt = rettv->vval.v_partial; int i; @@ -3217,8 +3217,8 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) // args. Can't take over name or args, the partial might // be referenced elsewhere. if (ret_pt->pt_name != NULL) { - pt->pt_name = vim_strsave(ret_pt->pt_name); - func_ref(pt->pt_name); + pt->pt_name = xstrdup(ret_pt->pt_name); + func_ref((char_u *)pt->pt_name); } else { pt->pt_func = ret_pt->pt_func; func_ptr_ref(pt->pt_func); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 8f256728e3..12920d932d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -118,7 +118,7 @@ void do_ascii(const exarg_T *const eap) { char *dig; int cc[MAX_MCO]; - int c = utfc_ptr2char((char *)get_cursor_pos_ptr(), cc); + int c = utfc_ptr2char(get_cursor_pos_ptr(), cc); if (c == NUL) { msg("NUL"); return; @@ -1068,7 +1068,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) curwin->w_cursor.lnum = n; while (line1 <= line2) { - // need to use vim_strsave() because the line will be unlocked within + // need to use xstrdup() because the line will be unlocked within // ml_append() p = xstrdup(ml_get(line1)); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false); @@ -1305,8 +1305,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; curwin->w_cursor.lnum = line2; - } else if ((do_in && (itmp = (char *)vim_tempname()) == NULL) - || (do_out && (otmp = (char *)vim_tempname()) == NULL)) { + } else if ((do_in && (itmp = vim_tempname()) == NULL) + || (do_out && (otmp = vim_tempname()) == NULL)) { emsg(_(e_notmp)); goto filterend; } @@ -3291,7 +3291,7 @@ static bool sub_joining_lines(exarg_T *eap, char *pat, char *sub, char *cmd, boo if (save) { if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) { - save_re_pat(RE_SUBST, (char_u *)pat, p_magic); + save_re_pat(RE_SUBST, pat, p_magic); } // put pattern in history add_to_history(HIST_SEARCH, pat, true, NUL); @@ -3608,7 +3608,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T sub = xstrdup(sub); sub_copy = sub; } else { - char *newsub = (char *)regtilde((char_u *)sub, p_magic, cmdpreview); + char *newsub = regtilde(sub, p_magic, cmdpreview); if (newsub != sub) { // newsub was allocated, free it later. sub_copy = newsub; @@ -4782,7 +4782,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i if (next_linenr == orig_buf->b_ml.ml_line_count + 1) { line = ""; } else { - line = (char *)ml_get_buf(orig_buf, next_linenr, false); + line = ml_get_buf(orig_buf, next_linenr, false); line_size = strlen(line) + (size_t)col_width + 1; // Reallocate if line not long enough diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 8fb166d2c9..e32eb860ce 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -785,7 +785,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) vim_snprintf((char *)IObuff, IOSIZE, _("E605: Exception not caught: %s"), current_exception->value); - p = (char *)vim_strsave(IObuff); + p = xstrdup((char *)IObuff); break; case ET_ERROR: messages = current_exception->messages; @@ -1300,7 +1300,7 @@ static void parse_register(exarg_T *eap) // for '=' register: accept the rest of the line as an expression if (eap->arg[-1] == '=' && eap->arg[0] != NUL) { if (!eap->skip) { - set_expr_line(vim_strsave((char_u *)eap->arg)); + set_expr_line(xstrdup(eap->arg)); } eap->arg += STRLEN(eap->arg); } @@ -3829,7 +3829,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) if (p_wic) { options += WILD_ICASE; } - p = (char *)ExpandOne(&xpc, (char_u *)eap->arg, NULL, options, WILD_EXPAND_FREE); + p = ExpandOne(&xpc, eap->arg, NULL, options, WILD_EXPAND_FREE); if (p == NULL) { return FAIL; } @@ -5274,7 +5274,7 @@ static void ex_swapname(exarg_T *eap) if (curbuf->b_ml.ml_mfp == NULL || curbuf->b_ml.ml_mfp->mf_fname == NULL) { msg(_("No swap file")); } else { - msg((char *)curbuf->b_ml.ml_mfp->mf_fname); + msg(curbuf->b_ml.ml_mfp->mf_fname); } } @@ -6563,7 +6563,7 @@ static void ex_tag_cmd(exarg_T *eap, char *name) cmd = DT_LTAG; } - do_tag((char_u *)eap->arg, cmd, eap->addr_count > 0 ? (int)eap->line2 : 1, + do_tag(eap->arg, cmd, eap->addr_count > 0 ? (int)eap->line2 : 1, eap->forceit, true); } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 20725b81ee..f40149d07a 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -529,7 +529,7 @@ static void discard_exception(except_T *excp, bool was_finished) if (p_verbose >= 13 || debug_break_level > 0) { int save_msg_silent = msg_silent; - saved_IObuff = (char *)vim_strsave(IObuff); + saved_IObuff = xstrdup((char *)IObuff); if (debug_break_level > 0) { msg_silent = false; // display messages } else { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index da99a03c38..cf95287d61 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -105,7 +105,7 @@ typedef struct command_line_state { int c; int gotesc; // true when just typed int do_abbr; // when true check for abbr. - char_u *lookfor; // string to match + char *lookfor; // string to match int hiscnt; // current history line in use int save_hiscnt; // history line before attempting // to jump to next match @@ -116,7 +116,7 @@ typedef struct command_line_state { int res; int save_msg_scroll; int save_State; // remember State when called - char_u *save_p_icm; + char *save_p_icm; int some_key_typed; // one of the keys was typed // mouse drag and release events are ignored, unless they are // preceded with a mouse down event @@ -632,7 +632,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init .ignore_drag_release = true, }; CommandLineState *s = &state; - s->save_p_icm = vim_strsave((char_u *)p_icm); + s->save_p_icm = xstrdup(p_icm); init_incsearch_state(&s->is_state); CmdlineInfo save_ccline; bool did_save_ccline = false; @@ -879,7 +879,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init need_wait_return = false; } - set_string_option_direct("icm", -1, (char *)s->save_p_icm, OPT_FREE, SID_NONE); + set_string_option_direct("icm", -1, s->save_p_icm, OPT_FREE, SID_NONE); State = s->save_State; if (cmdpreview != save_cmdpreview) { cmdpreview = save_cmdpreview; // restore preview state @@ -1087,7 +1087,7 @@ static int command_line_execute(VimState *state, int key) s->c = get_expr_register(); if (s->c == '=') { textlock++; - p = get_expr_line(); + p = (char_u *)get_expr_line(); textlock--; if (p != NULL) { @@ -1853,7 +1853,7 @@ static int command_line_handle_key(CommandLineState *s) // save current command string so it can be restored later if (s->lookfor == NULL) { - s->lookfor = vim_strsave((char_u *)ccline.cmdbuff); + s->lookfor = xstrdup(ccline.cmdbuff); s->lookfor[ccline.cmdpos] = NUL; } @@ -1870,13 +1870,13 @@ static int command_line_handle_key(CommandLineState *s) XFREE_CLEAR(ccline.cmdbuff); s->xpc.xp_context = EXPAND_NOTHING; if (s->hiscnt == get_hislen()) { - p = s->lookfor; // back to the old one + p = (char_u *)s->lookfor; // back to the old one } else { p = (char_u *)get_histentry(s->histype)[s->hiscnt].hisstr; } if (s->histype == HIST_SEARCH - && p != s->lookfor + && p != (char_u *)s->lookfor && (old_firstc = p[STRLEN(p) + 1]) != s->firstc) { // Correct for the separator character used when // adding the history entry vs the one used now. diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 76a429b5ef..5416be651d 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -69,7 +69,7 @@ #include "nvim/vim.h" #include "nvim/window.h" -static char_u *ff_expand_buffer = NULL; // used for expanding filenames +static char *ff_expand_buffer = NULL; // used for expanding filenames // type for the directory search stack typedef struct ff_stack { @@ -105,7 +105,7 @@ typedef struct ff_visited { // Visited directories are different if the wildcard string are // different. So we have to save it. - char_u *ffv_wc_path; + char *ffv_wc_path; // use FileID for comparison (needed because of links), else use filename. bool file_id_valid; @@ -131,7 +131,7 @@ typedef struct ff_visited_list_hdr { struct ff_visited_list_hdr *ffvl_next; // the filename the attached visited list is for - char_u *ffvl_filename; + char *ffvl_filename; ff_visited_T *ffvl_visited_list; } ff_visited_list_hdr_T; @@ -259,12 +259,12 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i // Reuse old visited lists. Get the visited list for the given // filename. If no list for the current filename exists, creates a new // one. - search_ctx->ffsc_visited_list = ff_get_visited_list((char_u *)filename, + search_ctx->ffsc_visited_list = ff_get_visited_list(filename, &search_ctx->ffsc_visited_lists_list); if (search_ctx->ffsc_visited_list == NULL) { goto error_return; } - search_ctx->ffsc_dir_visited_list = ff_get_visited_list((char_u *)filename, + search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename, &search_ctx->ffsc_dir_visited_lists_list); if (search_ctx->ffsc_dir_visited_list == NULL) { goto error_return; @@ -286,7 +286,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); - search_ctx->ffsc_start_dir = FullName_save((char *)ff_expand_buffer, false); + search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, false); } else { search_ctx->ffsc_start_dir = xstrnsave(rel_fname, len); } @@ -310,11 +310,11 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i path += 2; } else #endif - if (os_dirname(ff_expand_buffer, MAXPATHL) == FAIL) { + if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == FAIL) { goto error_return; } - search_ctx->ffsc_start_dir = (char *)vim_strsave(ff_expand_buffer); + search_ctx->ffsc_start_dir = xstrdup(ff_expand_buffer); #ifdef BACKSLASH_IN_FILENAME // A path that starts with "/dir" is relative to the drive, not to the @@ -396,12 +396,12 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i break; } if (STRNCMP(wc_part, "**", 2) == 0) { - ff_expand_buffer[len++] = (char_u)(*wc_part++); - ff_expand_buffer[len++] = (char_u)(*wc_part++); + ff_expand_buffer[len++] = *wc_part++; + ff_expand_buffer[len++] = *wc_part++; llevel = strtol(wc_part, &errpt, 10); if (errpt != wc_part && llevel > 0 && llevel < 255) { - ff_expand_buffer[len++] = (char_u)llevel; + ff_expand_buffer[len++] = (char)llevel; } else if (errpt != wc_part && llevel == 0) { // restrict is 0 -> remove already added '**' len -= 2; @@ -416,11 +416,11 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i goto error_return; } } else { - ff_expand_buffer[len++] = (char_u)(*wc_part++); + ff_expand_buffer[len++] = *wc_part++; } } ff_expand_buffer[len] = NUL; - search_ctx->ffsc_wc_path = (char *)vim_strsave(ff_expand_buffer); + search_ctx->ffsc_wc_path = xstrdup(ff_expand_buffer); } else { search_ctx->ffsc_fix_path = xstrdup(path); } @@ -439,7 +439,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i goto error_return; } STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); - add_pathsep((char *)ff_expand_buffer); + add_pathsep(ff_expand_buffer); { size_t eb_len = STRLEN(ff_expand_buffer); char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1); @@ -448,7 +448,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); if (os_isdir((char *)buf)) { STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); - add_pathsep((char *)ff_expand_buffer); + add_pathsep(ff_expand_buffer); } else { char *p = path_tail(search_ctx->ffsc_fix_path); char *wc_path = NULL; @@ -464,7 +464,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i goto error_return; } STRLCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, eb_len + (size_t)len + 1); - add_pathsep((char *)ff_expand_buffer); + add_pathsep(ff_expand_buffer); } else { len = (int)STRLEN(search_ctx->ffsc_fix_path); } @@ -484,7 +484,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i xfree(buf); } - sptr = ff_create_stack_element(ff_expand_buffer, (char_u *)search_ctx->ffsc_wc_path, level, 0); + sptr = ff_create_stack_element(ff_expand_buffer, search_ctx->ffsc_wc_path, level, 0); ff_push(search_ctx, sptr); search_ctx->ffsc_file_to_search = xstrdup(filename); @@ -607,7 +607,7 @@ char_u *vim_findfile(void *search_ctx_arg) // first time (hence stackp->ff_filearray == NULL) if (stackp->ffs_filearray == NULL && ff_check_visited(&search_ctx->ffsc_dir_visited_list->ffvl_visited_list, - stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL) { + (char *)stackp->ffs_fix_path, (char *)stackp->ffs_wc_path) == FAIL) { #ifdef FF_VERBOSE if (p_verbose >= 5) { verbose_enter_scroll(); @@ -787,7 +787,7 @@ char_u *vim_findfile(void *search_ctx_arg) == os_isdir((char *)file_path))))) #ifndef FF_VERBOSE && (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list, - file_path, (char_u *)"") == OK) + (char *)file_path, "") == OK) #endif ) { #ifdef FF_VERBOSE @@ -811,10 +811,10 @@ char_u *vim_findfile(void *search_ctx_arg) if (!path_with_url((char *)file_path)) { simplify_filename(file_path); } - if (os_dirname(ff_expand_buffer, MAXPATHL) + if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == OK) { p = path_shorten_fname(file_path, - ff_expand_buffer); + (char_u *)ff_expand_buffer); if (p != NULL) { STRMOVE(file_path, p); } @@ -845,8 +845,8 @@ char_u *vim_findfile(void *search_ctx_arg) continue; // not a directory } ff_push(search_ctx, - ff_create_stack_element((char_u *)stackp->ffs_filearray[i], - rest_of_wildcards, + ff_create_stack_element(stackp->ffs_filearray[i], + (char *)rest_of_wildcards, stackp->ffs_level - 1, 0)); } } @@ -867,8 +867,8 @@ char_u *vim_findfile(void *search_ctx_arg) continue; // not a directory } ff_push(search_ctx, - ff_create_stack_element((char_u *)stackp->ffs_filearray[i], - stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); + ff_create_stack_element(stackp->ffs_filearray[i], + (char *)stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); } } @@ -914,8 +914,8 @@ char_u *vim_findfile(void *search_ctx_arg) STRCAT(file_path, search_ctx->ffsc_fix_path); // create a new stack entry - sptr = ff_create_stack_element(file_path, - (char_u *)search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); + sptr = ff_create_stack_element((char *)file_path, + search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); ff_push(search_ctx, sptr); } else { break; @@ -972,7 +972,7 @@ static void ff_free_visited_list(ff_visited_T *vl) /// @return the already visited list for the given filename. If none is found it /// allocates a new one. -static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, +static ff_visited_list_hdr_T *ff_get_visited_list(char *filename, ff_visited_list_hdr_T **list_headp) { ff_visited_list_hdr_T *retptr = NULL; @@ -1009,7 +1009,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, retptr = xmalloc(sizeof(*retptr)); retptr->ffvl_visited_list = NULL; - retptr->ffvl_filename = vim_strsave(filename); + retptr->ffvl_filename = xstrdup(filename); retptr->ffvl_next = *list_headp; *list_headp = retptr; @@ -1060,7 +1060,7 @@ static bool ff_wc_equal(char_u *s1, char_u *s2) /// /// @return FAIL if the given file/dir is already in the list or, /// OK if it is newly added -static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path) +static int ff_check_visited(ff_visited_T **visited_list, char *fname, char *wc_path) { ff_visited_T *vp; bool url = false; @@ -1068,12 +1068,12 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * FileID file_id; // For a URL we only compare the name, otherwise we compare the // device/inode. - if (path_with_url((char *)fname)) { + if (path_with_url(fname)) { STRLCPY(ff_expand_buffer, fname, MAXPATHL); url = true; } else { ff_expand_buffer[0] = NUL; - if (!os_fileid((char *)fname, &file_id)) { + if (!os_fileid(fname, &file_id)) { return FAIL; } } @@ -1084,7 +1084,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * || (!url && vp->file_id_valid && os_fileid_equal(&(vp->file_id), &file_id))) { // are the wildcard parts equal - if (ff_wc_equal(vp->ffv_wc_path, wc_path)) { + if (ff_wc_equal((char_u *)vp->ffv_wc_path, (char_u *)wc_path)) { // already visited return FAIL; } @@ -1104,7 +1104,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * } if (wc_path != NULL) { - vp->ffv_wc_path = vim_strsave(wc_path); + vp->ffv_wc_path = xstrdup(wc_path); } else { vp->ffv_wc_path = NULL; } @@ -1116,7 +1116,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * } /// create stack element from given path pieces -static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, int level, +static ff_stack_T *ff_create_stack_element(char *fix_part, char *wc_part, int level, int star_star_empty) { ff_stack_T *new = xmalloc(sizeof(ff_stack_T)); @@ -1131,14 +1131,14 @@ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, in // the following saves NULL pointer checks in vim_findfile if (fix_part == NULL) { - fix_part = (char_u *)""; + fix_part = ""; } - new->ffs_fix_path = vim_strsave(fix_part); + new->ffs_fix_path = (char_u *)xstrdup(fix_part); if (wc_part == NULL) { - wc_part = (char_u *)""; + wc_part = ""; } - new->ffs_wc_path = vim_strsave(wc_part); + new->ffs_wc_path = (char_u *)xstrdup(wc_part); return new; } @@ -1292,7 +1292,7 @@ char_u *find_file_in_path(char_u *ptr, size_t len, int options, int first, char_ FINDFILE_BOTH, rel_fname, (char_u *)curbuf->b_p_sua); } -static char_u *ff_file_to_find = NULL; +static char *ff_file_to_find = NULL; static void *fdip_search_ctx = NULL; #if defined(EXITFREE) @@ -1338,7 +1338,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first static char *dir; static int did_findfile_init = false; char_u save_char; - char_u *file_name = NULL; + char *file_name = NULL; char *buf = NULL; int rel_to_curdir; @@ -1359,10 +1359,10 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first ptr[len] = save_char; xfree(ff_file_to_find); - ff_file_to_find = vim_strsave((char_u *)NameBuff); + ff_file_to_find = xstrdup(NameBuff); if (options & FNAME_UNESC) { // Change all "\ " to " ". - for (ptr = ff_file_to_find; *ptr != NUL; ptr++) { + for (ptr = (char_u *)ff_file_to_find; *ptr != NUL; ptr++) { if (ptr[0] == '\\' && ptr[1] == ' ') { memmove(ptr, ptr + 1, STRLEN(ptr)); } @@ -1376,7 +1376,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first || (ff_file_to_find[1] == '.' && (ff_file_to_find[2] == NUL || vim_ispathsep(ff_file_to_find[2]))))); - if (vim_isAbsName(ff_file_to_find) + if (vim_isAbsName((char_u *)ff_file_to_find) // "..", "../path", "." and "./path": don't use the path_option || rel_to_curdir #if defined(WIN32) @@ -1390,8 +1390,8 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first // If this is not a first call, return NULL. We already returned a // filename on the first call. if (first == true) { - if (path_with_url((char *)ff_file_to_find)) { - file_name = vim_strsave(ff_file_to_find); + if (path_with_url(ff_file_to_find)) { + file_name = xstrdup(ff_file_to_find); goto theend; } @@ -1420,7 +1420,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first && (find_what == FINDFILE_BOTH || ((find_what == FINDFILE_DIR) == os_isdir(NameBuff))))) { - file_name = vim_strsave((char_u *)NameBuff); + file_name = xstrdup(NameBuff); goto theend; } if (*buf == NUL) { @@ -1444,7 +1444,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first for (;;) { if (did_findfile_init) { - file_name = vim_findfile(fdip_search_ctx); + file_name = (char *)vim_findfile(fdip_search_ctx); if (file_name != NULL) { break; } @@ -1468,7 +1468,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first // get the stopdir string r_ptr = vim_findfile_stopdir((char_u *)buf); - fdip_search_ctx = vim_findfile_init(buf, (char *)ff_file_to_find, + fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, (char *)r_ptr, 100, false, find_what, fdip_search_ctx, false, (char *)rel_fname); if (fdip_search_ctx != NULL) { @@ -1499,7 +1499,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first } theend: - return file_name; + return (char_u *)file_name; } void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause, bool pre) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index b399885095..0d8eec1023 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2049,7 +2049,7 @@ static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp) char_u *tmpname; char *errmsg = NULL; - tmpname = vim_tempname(); + tmpname = (char_u *)vim_tempname(); if (tmpname == NULL) { errmsg = _("Can't find temp file for conversion"); } else { @@ -2697,7 +2697,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } } - rootname = (char *)get_file_in_dir((char_u *)fname, IObuff); + rootname = get_file_in_dir(fname, (char *)IObuff); if (rootname == NULL) { some_error = true; // out of memory goto nobackup; @@ -2847,7 +2847,7 @@ nobackup: } if (backup == NULL) { - rootname = (char *)get_file_in_dir((char_u *)fname, IObuff); + rootname = get_file_in_dir(fname, (char *)IObuff); if (rootname == NULL) { backup = NULL; } else { @@ -2993,7 +2993,7 @@ nobackup: // writing, write to a temp file instead and let the conversion // overwrite the original file. if (*p_ccv != NUL) { - wfname = (char *)vim_tempname(); + wfname = vim_tempname(); if (wfname == NULL) { // Can't write without a tempfile! SET_ERRMSG(_("E214: Can't find temp file for writing")); goto restore_backup; @@ -3170,7 +3170,7 @@ restore_backup: for (lnum = start; lnum <= end; lnum++) { // The next while loop is done once for each character written. // Keep it fast! - ptr = (char *)ml_get_buf(buf, lnum, false) - 1; + ptr = ml_get_buf(buf, lnum, false) - 1; if (write_undo_file) { sha256_update(&sha_ctx, (char_u *)ptr + 1, (uint32_t)(STRLEN(ptr + 1) + 1)); } @@ -4704,13 +4704,13 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf) buf_T *tbuf = curbuf; int retval = OK; linenr_T lnum; - char_u *p; + char *p; // Copy the lines in "frombuf" to "tobuf". curbuf = tobuf; for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; lnum++) { - p = vim_strsave(ml_get_buf(frombuf, lnum, false)); - if (ml_append(lnum - 1, (char *)p, 0, false) == FAIL) { + p = xstrdup(ml_get_buf(frombuf, lnum, false)); + if (ml_append(lnum - 1, p, 0, false) == FAIL) { xfree(p); retval = FAIL; break; @@ -5358,7 +5358,7 @@ static bool vim_settempdir(char *tempdir) /// /// @return pointer to the temp file name or NULL if Nvim can't create /// temporary directory for its own temporary files. -char_u *vim_tempname(void) +char *vim_tempname(void) { // Temp filename counter. static uint64_t temp_count; @@ -5370,10 +5370,10 @@ char_u *vim_tempname(void) // There is no need to check if the file exists, because we own the directory // and nobody else creates a file in it. - char_u template[TEMP_FILE_PATH_MAXLEN]; - snprintf((char *)template, TEMP_FILE_PATH_MAXLEN, + char template[TEMP_FILE_PATH_MAXLEN]; + snprintf(template, TEMP_FILE_PATH_MAXLEN, "%s%" PRIu64, tempdir, temp_count++); - return vim_strsave(template); + return xstrdup(template); } /// Tries matching a filename with a "pattern" ("prog" is NULL), or use the diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 0f085df3d0..2e8d282ede 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1582,7 +1582,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark linenr_T lnum = pos.lnum; // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end - char *line = (char *)ml_get_buf(buf, lnum, false); + char *line = ml_get_buf(buf, lnum, false); size_t line_len = STRLEN(line); size_t added = 0; @@ -1640,7 +1640,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t marker } char *cms = buf->b_p_cms; - char *line = (char *)ml_get_buf(buf, lnum, false); + char *line = ml_get_buf(buf, lnum, false); for (char *p = line; *p != NUL; p++) { if (STRNCMP(p, marker, markerlen) != 0) { continue; @@ -2848,7 +2848,7 @@ static void foldlevelIndent(fline_T *flp) linenr_T lnum = flp->lnum + flp->off; buf_T *buf = flp->wp->w_buffer; - char *s = skipwhite((char *)ml_get_buf(buf, lnum, false)); + char *s = skipwhite(ml_get_buf(buf, lnum, false)); // empty line or lines starting with a character in 'foldignore': level // depends on surrounding lines @@ -3010,7 +3010,7 @@ static void foldlevelMarker(fline_T *flp) flp->start = 0; flp->lvl_next = flp->lvl; - char *s = (char *)ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); + char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); while (*s) { if (*s == cstart && STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index e125d88395..0f0e3aece1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1708,26 +1708,26 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = n; if (n != 0 && (IS_SPECIAL(n) || mod_mask != 0)) { - char_u temp[10]; // modifier: 3, mbyte-char: 6, NUL: 1 + char temp[10]; // modifier: 3, mbyte-char: 6, NUL: 1 int i = 0; // Turn a special key into three bytes, plus modifier. if (mod_mask != 0) { - temp[i++] = K_SPECIAL; - temp[i++] = KS_MODIFIER; - temp[i++] = (char_u)mod_mask; + temp[i++] = (char)K_SPECIAL; + temp[i++] = (char)KS_MODIFIER; + temp[i++] = (char)mod_mask; } if (IS_SPECIAL(n)) { - temp[i++] = K_SPECIAL; - temp[i++] = (char_u)K_SECOND(n); - temp[i++] = K_THIRD(n); + temp[i++] = (char)K_SPECIAL; + temp[i++] = (char)K_SECOND(n); + temp[i++] = (char)K_THIRD(n); } else { - i += utf_char2bytes((int)n, (char *)temp + i); + i += utf_char2bytes((int)n, temp + i); } assert(i < 10); temp[i++] = NUL; rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)vim_strsave(temp); + rettv->vval.v_string = xstrdup(temp); if (is_mouse_key((int)n)) { int row = mouse_row; @@ -2135,7 +2135,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // complete match if (keylen >= 0 && keylen <= typebuf.tb_len) { - char_u *map_str = NULL; + char *map_str = NULL; // Write chars to script file(s). // Note: :lmap mappings are written *after* being applied. #5658 @@ -2175,8 +2175,8 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) char save_m_expr = mp->m_expr; int save_m_noremap = mp->m_noremap; char save_m_silent = mp->m_silent; - char_u *save_m_keys = NULL; // only saved when needed - char_u *save_m_str = NULL; // only saved when needed + char *save_m_keys = NULL; // only saved when needed + char *save_m_str = NULL; // only saved when needed LuaRef save_m_luaref = mp->m_luaref; // Handle ":map ": evaluate the {rhs} as an @@ -2193,9 +2193,9 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) vgetc_busy = 0; may_garbage_collect = false; - save_m_keys = vim_strsave(mp->m_keys); + save_m_keys = xstrdup((char *)mp->m_keys); if (save_m_luaref == LUA_NOREF) { - save_m_str = vim_strsave((char_u *)mp->m_str); + save_m_str = xstrdup(mp->m_str); } map_str = eval_map_expr(mp, NUL); @@ -2207,13 +2207,13 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // If an error was displayed and the expression returns an empty // string, generate a to allow for a redraw. if (prev_did_emsg != did_emsg && (map_str == NULL || *map_str == NUL)) { - char_u buf[4]; + char buf[4]; xfree(map_str); - buf[0] = K_SPECIAL; - buf[1] = KS_EXTRA; + buf[0] = (char)K_SPECIAL; + buf[1] = (char)KS_EXTRA; buf[2] = KE_IGNORE; buf[3] = NUL; - map_str = vim_strsave(buf); + map_str = xstrdup(buf); if (State & MODE_CMDLINE) { // redraw the command below the error msg_didout = true; @@ -2227,7 +2227,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) vgetc_busy = save_vgetc_busy; may_garbage_collect = save_may_garbage_collect; } else { - map_str = (char_u *)mp->m_str; + map_str = mp->m_str; } // Insert the 'to' part in the typebuf.tb_buf. @@ -2242,18 +2242,18 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // If this is a LANGMAP mapping, then we didn't record the keys // at the start of the function and have to record them now. if (keylen > typebuf.tb_maplen && (mp->m_mode & MODE_LANGMAP) != 0) { - gotchars(map_str, STRLEN(map_str)); + gotchars((char_u *)map_str, STRLEN(map_str)); } if (save_m_noremap != REMAP_YES) { noremap = save_m_noremap; - } else if (STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : mp->m_keys, + } else if (STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : (char *)mp->m_keys, (size_t)keylen) != 0) { noremap = REMAP_YES; } else { noremap = REMAP_SKIP; } - i = ins_typebuf((char *)map_str, noremap, 0, true, cmd_silent || save_m_silent); + i = ins_typebuf(map_str, noremap, 0, true, cmd_silent || save_m_silent); if (save_m_expr) { xfree(map_str); } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 060db3b3b1..84c01e0140 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -599,7 +599,7 @@ EXTERN int inhibit_delete_count INIT(= 0); #define DBCS_DEBUG (-1) /// Encoding used when 'fencs' is set to "default" -EXTERN char_u *fenc_default INIT(= NULL); +EXTERN char *fenc_default INIT(= NULL); /// "State" is the main state of Vim. /// There are other variables that modify the state: diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 85f59f39de..903349dcae 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -2292,7 +2292,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) // If the user didn't specify a file name, use a temp file. if (psettings->outfile == NULL) { - prt_ps_file_name = vim_tempname(); + prt_ps_file_name = (char_u *)vim_tempname(); if (prt_ps_file_name == NULL) { emsg(_(e_notmp)); return FAIL; diff --git a/src/nvim/help.c b/src/nvim/help.c index 245d80489f..235f64744a 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -180,7 +180,7 @@ void ex_help(exarg_T *eap) // It is needed for do_tag top open folds under the cursor. KeyTyped = old_KeyTyped; - do_tag((char_u *)tag, DT_HELP, 1, false, true); + do_tag(tag, DT_HELP, 1, false, true); // Delete the empty buffer if we're not using it. Careful: autocommands // may have jumped to another window, check that the buffer is not in a @@ -658,13 +658,13 @@ void fix_help_buffer(void) if (!syntax_present(curwin)) { for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) { - line = (char *)ml_get_buf(curbuf, lnum, false); + line = ml_get_buf(curbuf, lnum, false); const size_t len = STRLEN(line); if (in_example && len > 0 && !ascii_iswhite(line[0])) { // End of example: non-white or '<' in first column. if (line[0] == '<') { // blank-out a '<' in the first column - line = (char *)ml_get_buf(curbuf, lnum, true); + line = ml_get_buf(curbuf, lnum, true); line[0] = ' '; } in_example = false; @@ -672,12 +672,12 @@ void fix_help_buffer(void) if (!in_example && len > 0) { if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) { // blank-out a '>' in the last column (start of example) - line = (char *)ml_get_buf(curbuf, lnum, true); + line = ml_get_buf(curbuf, lnum, true); line[len - 1] = ' '; in_example = true; } else if (line[len - 1] == '~') { // blank-out a '~' at the end of line (header marker) - line = (char *)ml_get_buf(curbuf, lnum, true); + line = ml_get_buf(curbuf, lnum, true); line[len - 1] = ' '; } } @@ -694,7 +694,7 @@ void fix_help_buffer(void) && TOLOWER_ASC(fname[7]) == 'x' && fname[8] == NUL)) { for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; lnum++) { - line = (char *)ml_get_buf(curbuf, lnum, false); + line = ml_get_buf(curbuf, lnum, false); if (strstr(line, "*local-additions*") == NULL) { continue; } @@ -1167,8 +1167,7 @@ void ex_helptags(exarg_T *eap) } else { ExpandInit(&xpc); xpc.xp_context = EXPAND_DIRECTORIES; - dirname = (char *)ExpandOne(&xpc, (char_u *)eap->arg, NULL, - WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); + dirname = ExpandOne(&xpc, eap->arg, NULL, WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); if (dirname == NULL || !os_isdir(dirname)) { semsg(_("E150: Not a directory: %s"), eap->arg); } else { diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 412fe3509d..7e5fd52243 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -553,12 +553,12 @@ void init_highlight(bool both, bool reset) // Try finding the color scheme file. Used when a color file was loaded // and 'background' or 't_Co' is changed. - char_u *p = get_var_value("g:colors_name"); + char *p = (char *)get_var_value("g:colors_name"); if (p != NULL) { // Value of g:colors_name could be freed in load_colors() and make // p invalid, so copy it. - char_u *copy_p = vim_strsave(p); - bool okay = load_colors(copy_p); + char *copy_p = xstrdup(p); + bool okay = load_colors((char_u *)copy_p); xfree(copy_p); if (okay) { return; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 85534ebcff..719899d0b8 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -228,16 +228,16 @@ void ex_cstag(exarg_T *eap) } if (cs_check_for_tags()) { - ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false); + ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false); } } } else if (cs_check_for_tags()) { - ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false); + ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false); } break; case 1: if (cs_check_for_tags()) { - ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false); + ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false); if (ret == false) { if (msg_col) { msg_putchar('\n'); @@ -1003,7 +1003,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool if (qfpos != NULL && *qfpos != '0') { // Fill error list. FILE *f; - char_u *tmp = vim_tempname(); + char_u *tmp = (char_u *)vim_tempname(); qf_info_T *qi = NULL; win_T *wp = NULL; @@ -1053,7 +1053,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool (void)cs_manage_matches(matches, contexts, matched, Store); - return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); + return do_tag(pat, DT_CSCOPE, 0, forceit, verbose); } } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index a41a396abc..af5bcd7d2a 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -362,7 +362,7 @@ int get_indent_lnum(linenr_T lnum) // "buf". int get_indent_buf(buf_T *buf, linenr_T lnum) { - return get_indent_str_vtab((char *)ml_get_buf(buf, lnum, false), + return get_indent_str_vtab(ml_get_buf(buf, lnum, false), curbuf->b_p_ts, buf->b_p_vts_array, false); @@ -874,7 +874,7 @@ bool may_do_si(void) return curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL && !p_paste; } -// Get indent level from 'indentexpr'. +/// Get indent level from 'indentexpr'. int get_expr_indent(void) { int indent = -1; @@ -898,8 +898,8 @@ int get_expr_indent(void) // Need to make a copy, the 'indentexpr' option could be changed while // evaluating it. - char_u *inde_copy = vim_strsave((char_u *)curbuf->b_p_inde); - indent = (int)eval_to_number((char *)inde_copy); + char *inde_copy = xstrdup(curbuf->b_p_inde); + indent = (int)eval_to_number(inde_copy); xfree(inde_copy); if (use_sandbox) { diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 5941473825..c7f37790b6 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1838,7 +1838,7 @@ int get_c_indent(void) int cur_amount = MAXCOL; colnr_T col; char_u *theline; - char_u *linecopy; + char *linecopy; pos_T *trypos; pos_T *comment_pos; pos_T *tryposBrace = NULL; @@ -1893,7 +1893,7 @@ int get_c_indent(void) // Get a copy of the current contents of the line. // This is required, because only the most recent line obtained with // ml_get is valid! - linecopy = vim_strsave((char_u *)ml_get(cur_curpos.lnum)); + linecopy = xstrdup(ml_get(cur_curpos.lnum)); // In insert mode and the cursor is on a ')' truncate the line at the // cursor position. We don't want to line up with the matching '(' when @@ -1906,7 +1906,7 @@ int get_c_indent(void) linecopy[curwin->w_cursor.col] = NUL; } - theline = (char_u *)skipwhite((char *)linecopy); + theline = (char_u *)skipwhite(linecopy); // move the cursor to the start of the line diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index dce72a2611..686461ce60 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -132,10 +132,10 @@ typedef struct compl_S compl_T; struct compl_S { compl_T *cp_next; compl_T *cp_prev; - char_u *cp_str; ///< matched text - char_u *(cp_text[CPT_COUNT]); ///< text for the menu + char *cp_str; ///< matched text + char *(cp_text[CPT_COUNT]); ///< text for the menu typval_T cp_user_data; - char_u *cp_fname; ///< file containing the match, allocated when + char *cp_fname; ///< file containing the match, allocated when ///< cp_flags has CP_FREE_FNAME int cp_flags; ///< CP_ values int cp_number; ///< sequence number @@ -191,7 +191,7 @@ static bool compl_enter_selects = false; /// When "compl_leader" is not NULL only matches that start with this string /// are used. -static char_u *compl_leader = NULL; +static char *compl_leader = NULL; static bool compl_get_longest = false; ///< put longest common string in compl_leader @@ -802,7 +802,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons if (flags & CP_ORIGINAL_TEXT) { match->cp_number = 0; } - match->cp_str = (char_u *)xstrnsave(str, (size_t)len); + match->cp_str = xstrnsave(str, (size_t)len); // match-fname is: // - compl_curr_match->cp_fname if it is a string equal to fname. @@ -814,7 +814,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons && STRCMP(fname, compl_curr_match->cp_fname) == 0) { match->cp_fname = compl_curr_match->cp_fname; } else if (fname != NULL) { - match->cp_fname = vim_strsave((char_u *)fname); + match->cp_fname = xstrdup(fname); flags |= CP_FREE_FNAME; } else { match->cp_fname = NULL; @@ -829,9 +829,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons continue; } if (*cptext[i] != NUL) { - match->cp_text[i] = (cptext_allocated - ? (char_u *)cptext[i] - : (char_u *)xstrdup(cptext[i])); + match->cp_text[i] = (cptext_allocated ? cptext[i] : xstrdup(cptext[i])); } else if (cptext_allocated) { xfree(cptext[i]); } @@ -898,11 +896,11 @@ static void ins_compl_longest_match(compl_T *match) if (compl_leader == NULL) { // First match, use it as a whole. - compl_leader = vim_strsave(match->cp_str); + compl_leader = xstrdup(match->cp_str); had_match = (curwin->w_cursor.col > compl_col); ins_compl_delete(); - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); ins_redraw(false); // When the match isn't there (to avoid matching itself) remove it @@ -916,8 +914,8 @@ static void ins_compl_longest_match(compl_T *match) } // Reduce the text if this match differs from compl_leader. - p = compl_leader; - s = match->cp_str; + p = (char_u *)compl_leader; + s = (char_u *)match->cp_str; while (*p != NUL) { c1 = utf_ptr2char((char *)p); c2 = utf_ptr2char((char *)s); @@ -936,7 +934,7 @@ static void ins_compl_longest_match(compl_T *match) *p = NUL; had_match = (curwin->w_cursor.col > compl_col); ins_compl_delete(); - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); ins_redraw(false); // When the match isn't there (to avoid matching itself) remove it @@ -1131,7 +1129,7 @@ static int ins_compl_build_pum(void) do { if (!match_at_original_text(compl) && (compl_leader == NULL - || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) { + || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) { compl_match_arraysize++; } compl = compl->cp_next; @@ -1156,7 +1154,7 @@ static int ins_compl_build_pum(void) do { if (!match_at_original_text(compl) && (compl_leader == NULL - || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) { + || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) { if (!shown_match_ok) { if (compl == compl_shown_match || did_find_shown_match) { // This item is the shown match or this is the @@ -1173,16 +1171,16 @@ static int ins_compl_build_pum(void) } if (compl->cp_text[CPT_ABBR] != NULL) { - compl_match_array[i].pum_text = compl->cp_text[CPT_ABBR]; + compl_match_array[i].pum_text = (char_u *)compl->cp_text[CPT_ABBR]; } else { - compl_match_array[i].pum_text = compl->cp_str; + compl_match_array[i].pum_text = (char_u *)compl->cp_str; } - compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND]; - compl_match_array[i].pum_info = compl->cp_text[CPT_INFO]; + compl_match_array[i].pum_kind = (char_u *)compl->cp_text[CPT_KIND]; + compl_match_array[i].pum_info = (char_u *)compl->cp_text[CPT_INFO]; if (compl->cp_text[CPT_MENU] != NULL) { - compl_match_array[i++].pum_extra = compl->cp_text[CPT_MENU]; + compl_match_array[i++].pum_extra = (char_u *)compl->cp_text[CPT_MENU]; } else { - compl_match_array[i++].pum_extra = compl->cp_fname; + compl_match_array[i++].pum_extra = (char_u *)compl->cp_fname; } } @@ -1236,8 +1234,8 @@ void ins_compl_show_pum(void) } else { // popup menu already exists, only need to find the current item. for (int i = 0; i < compl_match_arraysize; i++) { - if (compl_match_array[i].pum_text == compl_shown_match->cp_str - || compl_match_array[i].pum_text == compl_shown_match->cp_text[CPT_ABBR]) { + if (compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_str + || compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_text[CPT_ABBR]) { cur = i; break; } @@ -1649,7 +1647,7 @@ int ins_compl_bs(void) line = get_cursor_line_ptr(); xfree(compl_leader); - compl_leader = (char_u *)xstrnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col)); + compl_leader = xstrnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col)); ins_compl_new_leader(); if (compl_shown_match != NULL) { @@ -1678,7 +1676,7 @@ static void ins_compl_new_leader(void) { ins_compl_del_pum(); ins_compl_delete(); - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); compl_used_match = false; if (compl_started) { @@ -1743,8 +1741,8 @@ void ins_compl_addleader(int c) } xfree(compl_leader); - compl_leader = (char_u *)xstrnsave(get_cursor_line_ptr() + compl_col, - (size_t)(curwin->w_cursor.col - compl_col)); + compl_leader = xstrnsave(get_cursor_line_ptr() + compl_col, + (size_t)(curwin->w_cursor.col - compl_col)); ins_compl_new_leader(); } @@ -1764,7 +1762,7 @@ static void ins_compl_restart(void) } /// Set the first match, the original text. -static void ins_compl_set_original_text(char_u *str) +static void ins_compl_set_original_text(char *str) FUNC_ATTR_NONNULL_ALL { // Replace the original text entry. @@ -1772,11 +1770,11 @@ static void ins_compl_set_original_text(char_u *str) // be at the last item for backward completion if (match_at_original_text(compl_first_match)) { // safety check xfree(compl_first_match->cp_str); - compl_first_match->cp_str = vim_strsave(str); + compl_first_match->cp_str = xstrdup(str); } else if (compl_first_match->cp_prev != NULL && match_at_original_text(compl_first_match->cp_prev)) { xfree(compl_first_match->cp_prev->cp_str); - compl_first_match->cp_prev->cp_str = vim_strsave(str); + compl_first_match->cp_prev->cp_str = xstrdup(str); } } @@ -1789,7 +1787,7 @@ void ins_compl_addfrommatch(void) int c; compl_T *cp; assert(compl_shown_match != NULL); - p = compl_shown_match->cp_str; + p = (char_u *)compl_shown_match->cp_str; if ((int)STRLEN(p) <= len) { // the match is too short // When still at the original match use the first entry that matches // the leader. @@ -1801,8 +1799,8 @@ void ins_compl_addfrommatch(void) for (cp = compl_shown_match->cp_next; cp != NULL && !is_first_match(cp); cp = cp->cp_next) { if (compl_leader == NULL - || ins_compl_equal(cp, compl_leader, STRLEN(compl_leader))) { - p = cp->cp_str; + || ins_compl_equal(cp, (char_u *)compl_leader, STRLEN(compl_leader))) { + p = (char_u *)cp->cp_str; break; } } @@ -1955,7 +1953,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) // CTRL-E then don't use the current match. char_u *ptr; if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) { - ptr = compl_curr_match->cp_str; + ptr = (char_u *)compl_curr_match->cp_str; } else { ptr = NULL; } @@ -2006,7 +2004,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) ins_compl_delete(); char_u *p = NULL; if (compl_leader != NULL) { - p = compl_leader; + p = (char_u *)compl_leader; } else if (compl_first_match != NULL) { p = (char_u *)compl_orig_text; } @@ -2168,7 +2166,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) if (ptr == NULL) { if (compl_leader != NULL) { - ptr = compl_leader; + ptr = (char_u *)compl_leader; } else { return; // nothing to do } @@ -2919,14 +2917,14 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p bool *cont_s_ipos) { *match_len = 0; - char_u *ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col; + char_u *ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col; int len; if (ctrl_x_mode_line_or_eval()) { if (compl_status_adding()) { if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count) { return NULL; } - ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); + ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); if (!p_paste) { ptr = (char_u *)skipwhite((char *)ptr); } @@ -2954,7 +2952,7 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p // normal command "J" was used. IOSIZE is always greater than // compl_length, so the next STRNCPY always works -- Acevedo STRNCPY(IObuff, ptr, len); // NOLINT(runtime/printf) - ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); + ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); tmp_ptr = ptr = (char_u *)skipwhite((char *)ptr); // Find start of next word. tmp_ptr = find_word_start(tmp_ptr); @@ -3275,7 +3273,7 @@ static int ins_compl_get_exp(pos_T *ini) static void ins_compl_update_shown_match(void) { while (!ins_compl_equal(compl_shown_match, - compl_leader, STRLEN(compl_leader)) + (char_u *)compl_leader, STRLEN(compl_leader)) && compl_shown_match->cp_next != NULL && !is_first_match(compl_shown_match->cp_next)) { compl_shown_match = compl_shown_match->cp_next; @@ -3284,10 +3282,10 @@ static void ins_compl_update_shown_match(void) // If we didn't find it searching forward, and compl_shows_dir is // backward, find the last match. if (compl_shows_dir_backward() - && !ins_compl_equal(compl_shown_match, compl_leader, STRLEN(compl_leader)) + && !ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader)) && (compl_shown_match->cp_next == NULL || is_first_match(compl_shown_match->cp_next))) { - while (!ins_compl_equal(compl_shown_match, compl_leader, STRLEN(compl_leader)) + while (!ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader)) && compl_shown_match->cp_prev != NULL && !is_first_match(compl_shown_match->cp_prev)) { compl_shown_match = compl_shown_match->cp_prev; @@ -3321,7 +3319,7 @@ void ins_compl_delete(void) /// "in_compl_func" is true when called from complete_check(). void ins_compl_insert(bool in_compl_func) { - ins_bytes((char *)compl_shown_match->cp_str + get_compl_len()); + ins_bytes(compl_shown_match->cp_str + get_compl_len()); compl_used_match = !match_at_original_text(compl_shown_match); dict_T *dict = ins_compl_dict_alloc(compl_shown_match); @@ -3346,7 +3344,7 @@ static void ins_compl_show_filename(void) // the text that fits in "space" between "s" and "e". char *s; char *e; - for (s = e = (char *)compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e)) { + for (s = e = compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e)) { space -= ptr2cells(e); while (space < 0) { space += ptr2cells(s); @@ -3355,7 +3353,7 @@ static void ins_compl_show_filename(void) } msg_hist_off = true; vim_snprintf((char *)IObuff, IOSIZE, "%s %s%s", lead, - (char_u *)s > compl_shown_match->cp_fname ? "<" : "", s); + s > compl_shown_match->cp_fname ? "<" : "", s); msg((char *)IObuff); msg_hist_off = false; redraw_cmdline = false; // don't overwrite! @@ -3432,7 +3430,7 @@ static int find_next_completion_match(bool allow_get_expansion, int todo, bool a if (!match_at_original_text(compl_shown_match) && compl_leader != NULL && !ins_compl_equal(compl_shown_match, - compl_leader, STRLEN(compl_leader))) { + (char_u *)compl_leader, STRLEN(compl_leader))) { todo++; } else { // Remember a matching item. @@ -3519,7 +3517,7 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match if (!compl_get_longest || compl_used_match) { ins_compl_insert(in_compl_func); } else { - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); } } else { compl_used_match = false; diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index 49d49f76b9..21dd5139d7 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -388,12 +388,12 @@ nlua_pop_typval_table_processing_end: LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState)); state->lua_callable.func_ref = nlua_ref_global(lstate, -1); - char_u *name = register_cfunc(&nlua_CFunction_func_call, - &nlua_CFunction_func_free, - state); + char *name = (char *)register_cfunc(&nlua_CFunction_func_call, + &nlua_CFunction_func_free, + state); cur.tv->v_type = VAR_FUNC; - cur.tv->vval.v_string = (char *)vim_strsave(name); + cur.tv->vval.v_string = xstrdup(name); break; } case LUA_TUSERDATA: { diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 1b874e673a..e3d6a7eec8 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -111,7 +111,7 @@ static int regex_match_line(lua_State *lstate) return luaL_error(lstate, "invalid row"); } - char_u *line = ml_get_buf(buf, rownr + 1, false); + char_u *line = (char_u *)ml_get_buf(buf, rownr + 1, false); size_t len = STRLEN(line); if (start < 0 || (size_t)start > len) { diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 65e024b707..971a47f8c9 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -332,7 +332,7 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position *bytes_read = 0; return ""; } - char *line = (char *)ml_get_buf(bp, (linenr_T)position.row + 1, false); + char *line = ml_get_buf(bp, (linenr_T)position.row + 1, false); size_t len = STRLEN(line); if (position.column > len) { *bytes_read = 0; diff --git a/src/nvim/macros.h b/src/nvim/macros.h index b84539852f..1024ca5015 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -54,7 +54,7 @@ #define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || ascii_isdigit(c)) // Returns empty string if it is NULL. -#define EMPTY_IF_NULL(x) (char *)((x) ? (x) : (char_u *)"") +#define EMPTY_IF_NULL(x) ((x) ? (x) : "") /// Adjust chars in a language according to 'langmap' option. /// NOTE that there is no noticeable overhead if 'langmap' is not set. diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 923eea145c..94b432a553 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -303,7 +303,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len // NB: replace_termcodes may produce an empty string even if orig_rhs is non-empty // (e.g. a single ^V, see :h map-empty-rhs) mapargs->rhs_is_noop = orig_rhs_len != 0 && mapargs->rhs_len == 0; - mapargs->rhs = (char_u *)replaced; + mapargs->rhs = replaced; } } else { char tmp_buf[64]; @@ -313,7 +313,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len // stores ref_no in map_str mapargs->rhs_len = (size_t)vim_snprintf(S_LEN(tmp_buf), "%c%c%c%d\r", K_SPECIAL, (char_u)KS_EXTRA, KE_LUA, rhs_lua); - mapargs->rhs = vim_strsave((char_u *)tmp_buf); + mapargs->rhs = xstrdup(tmp_buf); } } @@ -439,7 +439,7 @@ static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *ma /// and "desc" fields are used. /// "rhs", "rhs_lua", "orig_rhs" fields are cleared if "simplified" is false. /// @param sid -1 to use current_sctx -static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char_u *keys, +static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char *keys, MapArguments *args, int noremap, int mode, bool is_abbr, scid_T sid, linenr_T lnum, bool simplified) { @@ -454,8 +454,8 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, } } - mp->m_keys = vim_strsave(keys); - mp->m_str = (char *)args->rhs; + mp->m_keys = (uint8_t *)xstrdup(keys); + mp->m_str = args->rhs; mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!simplified) { @@ -767,7 +767,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, XFREE_CLEAR(mp->m_str); XFREE_CLEAR(mp->m_orig_str); } - mp->m_str = (char *)args->rhs; + mp->m_str = args->rhs; mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!keyround1_simplified) { @@ -846,7 +846,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } // Get here when adding a new entry to the maphash[] list or abbrlist. - map_add(buf, map_table, abbr_table, lhs, args, noremap, mode, is_abbrev, + map_add(buf, map_table, abbr_table, (char *)lhs, args, noremap, mode, is_abbrev, -1, // sid 0, // lnum keyround1_simplified); @@ -1265,7 +1265,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file) int hash; int count; int round; - char_u *p; + char *p; int i; *num_file = 0; // return values in case of FAIL @@ -1278,28 +1278,28 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file) for (i = 0; i < 7; i++) { if (i == 0) { - p = (char_u *)""; + p = ""; } else if (i == 1) { - p = (char_u *)""; + p = ""; } else if (i == 2) { - p = (char_u *)"