diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2021-11-16 20:27:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 20:27:59 +0100 |
commit | eba317d7a907a76e6e265c0fe0b97a87f17cf943 (patch) | |
tree | 21edca825d0de28a4024c969e26ecfe75f6dc298 /src | |
parent | 99211b008c10561560e84eabfaa22e1577ac179a (diff) | |
download | rneovim-eba317d7a907a76e6e265c0fe0b97a87f17cf943.tar.gz rneovim-eba317d7a907a76e6e265c0fe0b97a87f17cf943.tar.bz2 rneovim-eba317d7a907a76e6e265c0fe0b97a87f17cf943.zip |
refactor: reduce number of explicit char casts (#16077)
* refactor: reduce number of explicit char casts
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 2 | ||||
-rw-r--r-- | src/nvim/buffer.c | 62 | ||||
-rw-r--r-- | src/nvim/edit.c | 30 | ||||
-rw-r--r-- | src/nvim/eval/encode.c | 10 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 6 | ||||
-rw-r--r-- | src/nvim/eval/userfunc.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 6 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_eval.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 10 | ||||
-rw-r--r-- | src/nvim/fileio.c | 6 | ||||
-rw-r--r-- | src/nvim/hardcopy.c | 106 | ||||
-rw-r--r-- | src/nvim/if_cscope.c | 6 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 2 | ||||
-rw-r--r-- | src/nvim/macros.h | 2 | ||||
-rw-r--r-- | src/nvim/memline.c | 2 | ||||
-rw-r--r-- | src/nvim/message.c | 10 | ||||
-rw-r--r-- | src/nvim/misc1.c | 2 | ||||
-rw-r--r-- | src/nvim/option.c | 2 | ||||
-rw-r--r-- | src/nvim/os/env.c | 2 | ||||
-rw-r--r-- | src/nvim/path.c | 8 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 8 | ||||
-rw-r--r-- | src/nvim/runtime.c | 2 | ||||
-rw-r--r-- | src/nvim/screen.c | 2 | ||||
-rw-r--r-- | src/nvim/syntax.c | 20 | ||||
-rw-r--r-- | src/nvim/terminal.c | 2 | ||||
-rw-r--r-- | src/nvim/window.c | 2 |
27 files changed, 151 insertions, 167 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c1374ff00e..3103905819 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -71,7 +71,7 @@ Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err) FUNC_API_SINCE(3) { Dictionary result = ARRAY_DICT_INIT; - int id = syn_name2id((const char_u *)name.data); + int id = syn_name2id(name.data); if (id == 0) { api_set_error(err, kErrorTypeException, "Invalid highlight name: %s", diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index e9d89c2f91..88938d5099 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3130,7 +3130,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) // before redrawing). // - When the screen was scrolled but there is no wait-return // prompt. - set_keep_msg((char_u *)p, 0); + set_keep_msg(p, 0); } } @@ -3429,7 +3429,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use static int *stl_separator_locations = NULL; #define TMPLEN 70 - char_u buf_tmp[TMPLEN]; + char buf_tmp[TMPLEN]; char_u win_tmp[TMPLEN]; char_u *usefmt = fmt; const int save_must_redraw = must_redraw; @@ -3856,7 +3856,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use bool itemisflag = false; bool fillable = true; long num = -1; - char_u *str = NULL; + char *str = NULL; switch (opt) { case STL_FILEPATH: case STL_FULLPATH: @@ -3873,9 +3873,9 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use } trans_characters(NameBuff, MAXPATHL); if (opt != STL_FILENAME) { - str = NameBuff; + str = (char *)NameBuff; } else { - str = path_tail(NameBuff); + str = (char *)path_tail(NameBuff); } break; case STL_VIM_EXPR: // '{' @@ -3912,8 +3912,8 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use // { Evaluate the expression // Store the current buffer number as a string variable - vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "%d", curbuf->b_fnum); - set_internal_string_var("g:actual_curbuf", buf_tmp); + vim_snprintf(buf_tmp, sizeof(buf_tmp), "%d", curbuf->b_fnum); + set_internal_string_var("g:actual_curbuf", (char_u *)buf_tmp); vim_snprintf((char *)win_tmp, sizeof(win_tmp), "%d", curwin->handle); set_internal_string_var("g:actual_curwin", win_tmp); @@ -3928,7 +3928,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use } // Note: The result stored in `t` is unused. - str = eval_to_string_safe(out_p, &t, use_sandbox); + str = (char *)eval_to_string_safe(out_p, &t, use_sandbox); curwin = save_curwin; curbuf = save_curbuf; @@ -3943,8 +3943,8 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use // Check if the evaluated result is a number. // If so, convert the number to an int and free the string. if (str != NULL && *str != 0) { - if (*skipdigits(str) == NUL) { - num = atoi((char *)str); + if (*skipdigits((char_u *)str) == NUL) { + num = atoi(str); XFREE_CLEAR(str); itemisflag = false; } @@ -3957,8 +3957,8 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use && strchr((const char *)str, '%') != NULL && evaldepth < MAX_STL_EVAL_DEPTH) { size_t parsed_usefmt = (size_t)(block_start - usefmt); - size_t str_length = strlen((const char *)str); - size_t fmt_length = strlen((const char *)fmt_p); + size_t str_length = STRLEN(str); + size_t fmt_length = STRLEN(fmt_p); size_t new_fmt_len = parsed_usefmt + str_length + fmt_length + 3; char_u *new_fmt = (char_u *)xmalloc(new_fmt_len * sizeof(char_u)); @@ -4029,7 +4029,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use // Store the position percentage in our temporary buffer. // Note: We cannot store the value in `num` because // `get_rel_pos` can return a named position. Ex: "Top" - get_rel_pos(wp, buf_tmp, TMPLEN); + get_rel_pos(wp, (char_u *)buf_tmp, TMPLEN); str = buf_tmp; break; @@ -4044,14 +4044,14 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use // Note: The call will only return true if it actually // appended data to the `buf_tmp` buffer. - if (append_arg_number(wp, buf_tmp, (int)sizeof(buf_tmp), false)) { + if (append_arg_number(wp, (char_u *)buf_tmp, (int)sizeof(buf_tmp), false)) { str = buf_tmp; } break; case STL_KEYMAP: fillable = false; - if (get_keymap_str(wp, (char_u *)"<%s>", buf_tmp, TMPLEN)) { + if (get_keymap_str(wp, (char_u *)"<%s>", (char_u *)buf_tmp, TMPLEN)) { str = buf_tmp; } break; @@ -4090,7 +4090,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use case STL_ROFLAG_ALT: itemisflag = true; if (wp->w_buffer->b_p_ro) { - str = (char_u *)((opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]")); + str = (opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]"); } break; @@ -4098,8 +4098,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use case STL_HELPFLAG_ALT: itemisflag = true; if (wp->w_buffer->b_help) { - str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP" - : _("[Help]")); + str = (opt == STL_HELPFLAG_ALT) ? ",HLP" : _("[Help]"); } break; @@ -4109,7 +4108,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use // (including the brackets and null terminating character) if (*wp->w_buffer->b_p_ft != NUL && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 3) { - vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "[%s]", + vim_snprintf(buf_tmp, sizeof(buf_tmp), "[%s]", wp->w_buffer->b_p_ft); str = buf_tmp; } @@ -4122,10 +4121,10 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use // (including the comma and null terminating character) if (*wp->w_buffer->b_p_ft != NUL && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 2) { - vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), ",%s", + vim_snprintf(buf_tmp, sizeof(buf_tmp), ",%s", wp->w_buffer->b_p_ft); // Uppercase the file extension - for (char_u *t = buf_tmp; *t != 0; t++) { + for (char_u *t = (char_u *)buf_tmp; *t != 0; t++) { *t = (char_u)TOUPPER_LOC(*t); } str = buf_tmp; @@ -4135,16 +4134,13 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use case STL_PREVIEWFLAG_ALT: itemisflag = true; if (wp->w_p_pvw) { - str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV" - : _("[Preview]")); + str = (opt == STL_PREVIEWFLAG_ALT) ? ",PRV" : _("[Preview]"); } break; case STL_QUICKFIX: if (bt_quickfix(wp->w_buffer)) { - str = (char_u *)(wp->w_llist_ref - ? _(msg_loclist) - : _(msg_qflist)); + str = wp->w_llist_ref ? _(msg_loclist) : _(msg_qflist); } break; @@ -4155,17 +4151,17 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use + bufIsChanged(wp->w_buffer) * 2 + (!MODIFIABLE(wp->w_buffer)) * 4) { case 2: - str = (char_u *)"[+]"; break; + str = "[+]"; break; case 3: - str = (char_u *)",+"; break; + str = ",+"; break; case 4: - str = (char_u *)"[-]"; break; + str = "[-]"; break; case 5: - str = (char_u *)",-"; break; + str = ",-"; break; case 6: - str = (char_u *)"[+-]"; break; + str = "[+-]"; break; case 7: - str = (char_u *)",+-"; break; + str = ",+-"; break; } break; @@ -4199,7 +4195,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use if (str != NULL && *str) { // { Skip the leading `,` or ` ` if the item is a flag // and the proper conditions are met - char_u *t = str; + char_u *t = (char_u *)str; if (itemisflag) { if ((t[0] && t[1]) && ((!prevchar_isitem && *t == ',') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index ca903fdcf7..7a24ee1b32 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3292,16 +3292,11 @@ void get_complete_info(list_T *what_list, dict_T *retdict) dict_T *di = tv_dict_alloc(); tv_list_append_dict(li, di); - tv_dict_add_str(di, S_LEN("word"), - (char *)EMPTY_IF_NULL(match->cp_str)); - tv_dict_add_str(di, S_LEN("abbr"), - (char *)EMPTY_IF_NULL(match->cp_text[CPT_ABBR])); - tv_dict_add_str(di, S_LEN("menu"), - (char *)EMPTY_IF_NULL(match->cp_text[CPT_MENU])); - tv_dict_add_str(di, S_LEN("kind"), - (char *)EMPTY_IF_NULL(match->cp_text[CPT_KIND])); - tv_dict_add_str(di, S_LEN("info"), - (char *)EMPTY_IF_NULL(match->cp_text[CPT_INFO])); + tv_dict_add_str(di, S_LEN("word"), EMPTY_IF_NULL(match->cp_str)); + tv_dict_add_str(di, S_LEN("abbr"), EMPTY_IF_NULL(match->cp_text[CPT_ABBR])); + tv_dict_add_str(di, S_LEN("menu"), EMPTY_IF_NULL(match->cp_text[CPT_MENU])); + tv_dict_add_str(di, S_LEN("kind"), EMPTY_IF_NULL(match->cp_text[CPT_KIND])); + tv_dict_add_str(di, S_LEN("info"), EMPTY_IF_NULL(match->cp_text[CPT_INFO])); if (match->cp_user_data.v_type == VAR_UNKNOWN) { tv_dict_add_str(di, S_LEN("user_data"), ""); } else { @@ -4635,16 +4630,11 @@ static dict_T *ins_compl_dict_alloc(compl_T *match) { // { word, abbr, menu, kind, info } dict_T *dict = tv_dict_alloc_lock(VAR_FIXED); - tv_dict_add_str(dict, S_LEN("word"), - (const char *)EMPTY_IF_NULL(match->cp_str)); - tv_dict_add_str(dict, S_LEN("abbr"), - (const char *)EMPTY_IF_NULL(match->cp_text[CPT_ABBR])); - tv_dict_add_str(dict, S_LEN("menu"), - (const char *)EMPTY_IF_NULL(match->cp_text[CPT_MENU])); - tv_dict_add_str(dict, S_LEN("kind"), - (const char *)EMPTY_IF_NULL(match->cp_text[CPT_KIND])); - tv_dict_add_str(dict, S_LEN("info"), - (const char *)EMPTY_IF_NULL(match->cp_text[CPT_INFO])); + tv_dict_add_str(dict, S_LEN("word"), EMPTY_IF_NULL(match->cp_str)); + tv_dict_add_str(dict, S_LEN("abbr"), EMPTY_IF_NULL(match->cp_text[CPT_ABBR])); + tv_dict_add_str(dict, S_LEN("menu"), EMPTY_IF_NULL(match->cp_text[CPT_MENU])); + tv_dict_add_str(dict, S_LEN("kind"), EMPTY_IF_NULL(match->cp_text[CPT_KIND])); + tv_dict_add_str(dict, S_LEN("info"), EMPTY_IF_NULL(match->cp_text[CPT_INFO])); if (match->cp_user_data.v_type == VAR_UNKNOWN) { tv_dict_add_str(dict, S_LEN("user_data"), ""); } else { diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index b457353838..d694b8a374 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -29,8 +29,6 @@ #include "nvim/message.h" #include "nvim/vim.h" // For _() -#define utf_ptr2char(b) utf_ptr2char((char_u *)b) -#define utf_ptr2len(b) ((size_t)utf_ptr2len((char_u *)b)) #define utf_char2len(b) ((size_t)utf_char2len(b)) const char *const encode_bool_var_names[] = { @@ -614,8 +612,8 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const #define ENCODE_RAW(ch) \ (ch >= 0x20 && utf_printable(ch)) for (size_t i = 0; i < utf_len;) { - const int ch = utf_ptr2char(utf_buf + i); - const size_t shift = (ch == 0? 1: utf_ptr2len(utf_buf + i)); + const int ch = utf_ptr2char((char_u *)utf_buf + i); + const size_t shift = (ch == 0 ? 1 : ((size_t)utf_ptr2len((char_u *)utf_buf + i))); assert(shift > 0); i += shift; switch (ch) { @@ -654,11 +652,11 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const ga_append(gap, '"'); ga_grow(gap, (int)str_len); for (size_t i = 0; i < utf_len;) { - const int ch = utf_ptr2char(utf_buf + i); + const int ch = utf_ptr2char((char_u *)utf_buf + i); const size_t shift = (ch == 0? 1: utf_char2len(ch)); assert(shift > 0); // Is false on invalid unicode, but this should already be handled. - assert(ch == 0 || shift == utf_ptr2len(utf_buf + i)); + assert(ch == 0 || shift == ((size_t)utf_ptr2len((char_u *)utf_buf + i))); switch (ch) { case BS: case TAB: diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 1d9ebdb596..7549ec7ac8 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3544,7 +3544,7 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr) } if (from) { - xstrlcpy((char *)cwd, (char *)from, MAXPATHL); + STRLCPY(cwd, from, MAXPATHL); } rettv->vval.v_string = vim_strsave(cwd); @@ -4867,7 +4867,7 @@ static void f_histnr(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_hlID(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - rettv->vval.v_number = syn_name2id((const char_u *)tv_get_string(&argvars[0])); + rettv->vval.v_number = syn_name2id(tv_get_string(&argvars[0])); } /* @@ -4875,7 +4875,7 @@ static void f_hlID(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_hlexists(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - rettv->vval.v_number = highlight_exists((const char_u *)tv_get_string(&argvars[0])); + rettv->vval.v_number = highlight_exists(tv_get_string(&argvars[0])); } /* diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 6fe75e5e1f..80a22f6f9d 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1818,7 +1818,7 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, if (name != NULL) { name = vim_strsave(name); *pp = (char_u *)end; - if (strncmp((char *)name, "<SNR>", 5) == 0) { + if (STRNCMP(name, "<SNR>", 5) == 0) { // Change "<SNR>" to the byte sequence. name[0] = K_SPECIAL; name[1] = KS_EXTRA; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 145fe33284..66e30bdf2b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1440,7 +1440,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, _("%" PRId64 " lines filtered"), (int64_t)linecount); if (msg(msg_buf) && !msg_scroll) { // save message to display it after redraw - set_keep_msg((char_u *)msg_buf, 0); + set_keep_msg(msg_buf, 0); } } else { msgmore((long)linecount); @@ -3280,7 +3280,7 @@ static bool sub_joining_lines(exarg_T *eap, char_u *pat, char_u *sub, char_u *cm // TODO(vim): find a generic solution to make line-joining operations more // efficient, avoid allocating a string that grows in size. if (pat != NULL - && strcmp((const char *)pat, "\\n") == 0 + && STRCMP(pat, "\\n") == 0 && *sub == NUL && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' @@ -4468,7 +4468,7 @@ bool do_sub_msg(bool count_only) (int64_t)sub_nsubs, (int64_t)sub_nlines); if (msg(msg_buf)) { // save message to display it after redraw - set_keep_msg((char_u *)msg_buf, 0); + set_keep_msg(msg_buf, 0); } return true; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 499c6ed4f9..e622a2a68f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2647,7 +2647,7 @@ static char_u *find_command(exarg_T *eap, int *full) const int c2 = len == 1 ? NUL : eap->cmd[1]; if (command_count != CMD_SIZE) { - iemsg((char *)_("E943: Command table needs to be updated, run 'make'")); + iemsg(_("E943: Command table needs to be updated, run 'make'")); getout(1); } @@ -9130,7 +9130,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum // postponed to avoid a delay when <afile> is not used. result = (char_u *)FullName_save((char *)autocmd_fname, false); // Copy into `autocmd_fname`, don't reassign it. #8165 - xstrlcpy((char *)autocmd_fname, (char *)result, MAXPATHL); + STRLCPY(autocmd_fname, result, MAXPATHL); xfree(result); } result = autocmd_fname; diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index cfc8eb7316..348a26d723 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -566,7 +566,7 @@ static void discard_exception(except_T *excp, bool was_finished) } else { verbose_leave(); } - xstrlcpy((char *)IObuff, (const char *)saved_IObuff, IOSIZE); + STRLCPY(IObuff, saved_IObuff, IOSIZE); xfree(saved_IObuff); } if (excp->type != ET_INTERRUPT) { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9ccbdbaf58..0716b5445d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2697,7 +2697,7 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline, .attr = 0, })); } - const int id = syn_name2id((const char_u *)chunk.group); + const int id = syn_name2id(chunk.group); const int attr = (id == 0 ? 0 : syn_id2attr(id)); kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) { .start = (int)chunk.start.col, @@ -2899,7 +2899,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) if (group == NULL) { goto color_cmdline_error; } - const int id = syn_name2id((char_u *)group); + const int id = syn_name2id(group); const int attr = (id == 0 ? 0 : syn_id2attr(id)); kv_push(ccline_colors->colors, ((CmdlineColorChunk) { .start = (int)start, @@ -4989,13 +4989,13 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u ** // When expanding a function name starting with s:, match the <SNR>nr_ // prefix. - char_u *tofree = NULL; + char *tofree = NULL; if (xp->xp_context == EXPAND_USER_FUNC && STRNCMP(pat, "^s:", 3) == 0) { const size_t len = STRLEN(pat) + 20; tofree = xmalloc(len); - snprintf((char *)tofree, len, "^<SNR>\\d\\+_%s", pat + 3); - pat = tofree; + snprintf(tofree, len, "^<SNR>\\d\\+_%s", pat + 3); + pat = (char_u *)tofree; } if (xp->xp_context == EXPAND_LUA) { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index cf4037308b..321d884d9c 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -125,7 +125,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) } add_quoted_fname((char *)IObuff, IOSIZE - 100, buf, (const char *)name); // Avoid an over-long translation to cause trouble. - xstrlcat((char *)IObuff, (const char *)s, IOSIZE); + STRLCAT(IObuff, s, IOSIZE); // For the first message may have to start a new line. // For further ones overwrite the previous one, reset msg_scroll before // calling filemess(). @@ -1857,7 +1857,7 @@ failed: // - When restart_edit is set (otherwise there will be a delay before // redrawing). // - When the screen was scrolled but there is no wait-return prompt. - set_keep_msg(p, 0); + set_keep_msg((char *)p, 0); } msg_scrolled_ign = false; } @@ -3536,7 +3536,7 @@ restore_backup: } } - set_keep_msg((char_u *)msg_trunc_attr((char *)IObuff, FALSE, 0), 0); + set_keep_msg(msg_trunc_attr((char *)IObuff, false, 0), 0); } /* When written everything correctly: reset 'modified'. Unless not diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 296c5cbdbf..ab3f63c93e 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -461,10 +461,10 @@ static void prt_line_number(prt_settings_T *const psettings, const int page_line // Leave two spaces between the number and the text; depends on // PRINT_NUMBER_WIDTH. - char_u tbuf[20]; - snprintf((char *)tbuf, sizeof(tbuf), "%6ld", (long)lnum); + char tbuf[20]; + snprintf(tbuf, sizeof(tbuf), "%6ld", (long)lnum); for (int i = 0; i < 6; i++) { - (void)mch_print_text_out(&tbuf[i], 1); + (void)mch_print_text_out((char_u *)(&tbuf[i]), 1); } if (psettings->do_syntax) { @@ -669,7 +669,7 @@ void ex_hardcopy(exarg_T *eap) // Syntax highlighting of line numbers. if (prt_use_number() && settings.do_syntax) { - int id = syn_name2id((char_u *)"LineNr"); + int id = syn_name2id("LineNr"); if (id > 0) { id = syn_get_final_id(id); } @@ -1310,7 +1310,7 @@ static int prt_collate; /* * Buffers used when generating PostScript output */ -static char_u prt_line_buffer[257]; +static char prt_line_buffer[257]; static garray_T prt_ps_buffer = GA_EMPTY_INIT_VALUE; static int prt_do_conv; @@ -1334,9 +1334,9 @@ static void prt_write_file_raw_len(char_u *buffer, size_t bytes) } } -static void prt_write_file(char_u *buffer) +static void prt_write_file(char *buffer) { - prt_write_file_len(buffer, STRLEN(buffer)); + prt_write_file_len((char_u *)buffer, STRLEN(buffer)); } static void prt_write_file_len(char_u *buffer, size_t bytes) @@ -1349,7 +1349,7 @@ static void prt_write_file_len(char_u *buffer, size_t bytes) */ static void prt_write_string(char *s) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%s", s); + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%s", s); prt_write_file(prt_line_buffer); } @@ -1358,7 +1358,7 @@ static void prt_write_string(char *s) */ static void prt_write_int(int i) { - sprintf((char *)prt_line_buffer, "%d ", i); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%d ", i); prt_write_file(prt_line_buffer); } @@ -1367,7 +1367,7 @@ static void prt_write_int(int i) */ static void prt_write_boolean(int b) { - sprintf((char *)prt_line_buffer, "%s ", (b ? "T" : "F")); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%s ", (b ? "T" : "F")); prt_write_file(prt_line_buffer); } @@ -1376,14 +1376,14 @@ static void prt_write_boolean(int b) */ static void prt_def_font(char *new_name, char *encoding, int height, char *font) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "/_%s /VIM-%s /%s ref\n", new_name, encoding, font); prt_write_file(prt_line_buffer); if (prt_out_mbyte) { - sprintf((char *)prt_line_buffer, "/%s %d %f /_%s sffs\n", - new_name, height, 500./prt_ps_courier_font.wx, new_name); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), "/%s %d %f /_%s sffs\n", + new_name, height, 500./prt_ps_courier_font.wx, new_name); } else { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "/%s %d /_%s ffs\n", new_name, height, new_name); } prt_write_file(prt_line_buffer); @@ -1394,10 +1394,10 @@ static void prt_def_font(char *new_name, char *encoding, int height, char *font) */ static void prt_def_cidfont(char *new_name, int height, char *cidfont) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "/_%s /%s[/%s] vim_composefont\n", new_name, prt_cmap, cidfont); prt_write_file(prt_line_buffer); - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "/%s %d /_%s ffs\n", new_name, height, new_name); prt_write_file(prt_line_buffer); } @@ -1407,7 +1407,7 @@ static void prt_def_cidfont(char *new_name, int height, char *cidfont) */ static void prt_dup_cidfont(char *original_name, char *new_name) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "/%s %s d\n", new_name, original_name); prt_write_file(prt_line_buffer); } @@ -1444,7 +1444,7 @@ static void prt_write_real(double val, int prec) prt_real_bits(val, prec, &integer, &fraction); // Emit integer part - snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%d", integer); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%d", integer); prt_write_file(prt_line_buffer); // Only emit fraction if necessary if (fraction != 0) { @@ -1454,11 +1454,11 @@ static void prt_write_real(double val, int prec) fraction /= 10; } // Emit fraction left padded with zeros - snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), ".%0*d", + snprintf(prt_line_buffer, sizeof(prt_line_buffer), ".%0*d", prec, fraction); prt_write_file(prt_line_buffer); } - sprintf((char *)prt_line_buffer, " "); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), " "); prt_write_file(prt_line_buffer); } @@ -1467,11 +1467,11 @@ static void prt_write_real(double val, int prec) */ static void prt_def_var(char *name, double value, int prec) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "/%s ", name); prt_write_file(prt_line_buffer); prt_write_real(value, prec); - sprintf((char *)prt_line_buffer, "d\n"); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), "d\n"); prt_write_file(prt_line_buffer); } @@ -1569,8 +1569,8 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) // Look for named resource file in runtimepath STRCPY(buffer, "print"); add_pathsep((char *)buffer); - xstrlcat((char *)buffer, name, MAXPATHL); - xstrlcat((char *)buffer, ".ps", MAXPATHL); + STRLCAT(buffer, name, MAXPATHL); + STRLCAT(buffer, ".ps", MAXPATHL); resource->filename[0] = NUL; retval = (do_in_runtimepath(buffer, 0, prt_resource_name, resource->filename) && resource->filename[0] != NUL); @@ -1833,14 +1833,14 @@ static void prt_dsc_start(void) static void prt_dsc_noarg(char *comment) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%%s\n", comment); prt_write_file(prt_line_buffer); } static void prt_dsc_textline(char *comment, char *text) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%%s: %s\n", comment, text); prt_write_file(prt_line_buffer); } @@ -1848,7 +1848,7 @@ static void prt_dsc_textline(char *comment, char *text) static void prt_dsc_text(char *comment, char *text) { // TODO(vim): - should scan 'text' for any chars needing escaping! - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%%s: (%s)\n", comment, text); prt_write_file(prt_line_buffer); } @@ -1859,12 +1859,12 @@ static void prt_dsc_ints(char *comment, int count, int *ints) { int i; - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%%s:", comment); prt_write_file(prt_line_buffer); for (i = 0; i < count; i++) { - sprintf((char *)prt_line_buffer, " %d", ints[i]); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), " %d", ints[i]); prt_write_file(prt_line_buffer); } @@ -1876,15 +1876,15 @@ static void prt_dsc_resources(const char *comment, const char *type, const char FUNC_ATTR_NONNULL_ARG(2, 3) { if (comment != NULL) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%%s: %s", comment, type); } else { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%+ %s", type); } prt_write_file(prt_line_buffer); - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), " %s\n", string); prt_write_file(prt_line_buffer); } @@ -1910,7 +1910,7 @@ static void prt_dsc_requirements(int duplex, int tumble, int collate, int color, return; } - sprintf((char *)prt_line_buffer, "%%%%Requirements:"); + snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%Requirements:"); prt_write_file(prt_line_buffer); if (duplex) { @@ -1928,7 +1928,7 @@ static void prt_dsc_requirements(int duplex, int tumble, int collate, int color, if (num_copies > 1) { prt_write_string(" numcopies("); // Note: no space wanted so don't use prt_write_int() - snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%d", + snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%d", num_copies); prt_write_file(prt_line_buffer); prt_write_string(")"); @@ -1939,7 +1939,7 @@ static void prt_dsc_requirements(int duplex, int tumble, int collate, int color, static void prt_dsc_docmedia(char *paper_name, double width, double height, double weight, char *colour, char *type) { - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), + vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%%%%DocumentMedia: %s ", paper_name); prt_write_file(prt_line_buffer); prt_write_real(width, 2); @@ -2492,7 +2492,7 @@ int mch_print_begin(prt_settings_T *psettings) struct prt_ps_resource_S res_prolog; struct prt_ps_resource_S res_encoding; char buffer[256]; - char_u *p_encoding; + char *p_encoding; char_u *p; struct prt_ps_resource_S res_cidfont; struct prt_ps_resource_S res_cmap; @@ -2595,20 +2595,20 @@ int mch_print_begin(prt_settings_T *psettings) // that cannot be found then default to "latin1". // Note: VIM specific encoding header is always skipped. if (!prt_out_mbyte) { - p_encoding = enc_skip(p_penc); + p_encoding = (char *)enc_skip(p_penc); if (*p_encoding == NUL - || !prt_find_resource((char *)p_encoding, &res_encoding)) { + || !prt_find_resource(p_encoding, &res_encoding)) { // 'printencoding' not set or not supported - find alternate int props; - p_encoding = enc_skip(p_enc); - props = enc_canon_props(p_encoding); + p_encoding = (char *)enc_skip(p_enc); + props = enc_canon_props((char_u *)p_encoding); if (!(props & ENC_8BIT) - || !prt_find_resource((char *)p_encoding, &res_encoding)) { + || !prt_find_resource(p_encoding, &res_encoding)) { // 8-bit 'encoding' is not supported // Use latin1 as default printing encoding - p_encoding = (char_u *)"latin1"; - if (!prt_find_resource((char *)p_encoding, &res_encoding)) { + p_encoding = "latin1"; + if (!prt_find_resource(p_encoding, &res_encoding)) { semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), p_encoding); return FALSE; @@ -2621,9 +2621,9 @@ int mch_print_begin(prt_settings_T *psettings) // For the moment there are no checks on encoding resource files to // perform } else { - p_encoding = enc_skip(p_penc); + p_encoding = (char *)enc_skip(p_penc); if (*p_encoding == NUL) { - p_encoding = enc_skip(p_enc); + p_encoding = (char *)enc_skip(p_enc); } if (prt_use_courier) { // Include ASCII range encoding vector @@ -2641,9 +2641,9 @@ int mch_print_begin(prt_settings_T *psettings) } prt_conv.vc_type = CONV_NONE; - if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { + if (!(enc_canon_props(p_enc) & enc_canon_props((char_u *)p_encoding) & ENC_8BIT)) { // Set up encoding conversion if required - if (convert_setup(&prt_conv, p_enc, p_encoding) == FAIL) { + if (convert_setup(&prt_conv, p_enc, (char_u *)p_encoding) == FAIL) { semsg(_("E620: Unable to convert to print encoding \"%s\""), p_encoding); return false; @@ -2766,23 +2766,23 @@ int mch_print_begin(prt_settings_T *psettings) // When using Courier for ASCII range when printing multi-byte, need to // pick up ASCII encoding to use with it. if (prt_use_courier) { - p_encoding = (char_u *)prt_ascii_encoding; + p_encoding = prt_ascii_encoding; } prt_dsc_resources("IncludeResource", "font", prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); - prt_def_font("F0", (char *)p_encoding, (int)prt_line_height, + prt_def_font("F0", p_encoding, (int)prt_line_height, prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); prt_dsc_resources("IncludeResource", "font", prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]); - prt_def_font("F1", (char *)p_encoding, (int)prt_line_height, + prt_def_font("F1", p_encoding, (int)prt_line_height, prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]); prt_dsc_resources("IncludeResource", "font", prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); - prt_def_font("F2", (char *)p_encoding, (int)prt_line_height, + prt_def_font("F2", p_encoding, (int)prt_line_height, prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); prt_dsc_resources("IncludeResource", "font", prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); - prt_def_font("F3", (char *)p_encoding, (int)prt_line_height, + prt_def_font("F3", p_encoding, (int)prt_line_height, prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); } if (prt_out_mbyte) { @@ -2865,7 +2865,7 @@ void mch_print_end(prt_settings_T *psettings) // Write CTRL-D to close serial communication link if used. // NOTHING MUST BE WRITTEN AFTER THIS! - prt_write_file((char_u *)"\004"); + prt_write_file("\004"); if (!prt_file_error && psettings->outfile == NULL && !got_int && !psettings->user_abort) { diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 5b5f056164..2c44ce380d 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -601,7 +601,7 @@ static int cs_cnt_matches(size_t idx) if ((stok = strtok(NULL, (const char *)" ")) == NULL) { continue; } - if (strncmp((const char *)stok, "lines", 5)) { + if (strncmp(stok, "lines", 5)) { continue; } @@ -1214,8 +1214,8 @@ static cscmd_T *cs_lookup_cmd(exarg_T *eap) } len = strlen(stok); - for (cmdp = cs_cmds; cmdp->name != NULL; ++cmdp) { - if (strncmp((const char *)(stok), cmdp->name, len) == 0) { + for (cmdp = cs_cmds; cmdp->name != NULL; cmdp++) { + if (strncmp(stok, cmdp->name, len) == 0) { return cmdp; } } diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index b27b1ae7a8..6a8b70a158 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -957,7 +957,7 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) while ((line = fgetline(0, cookie, 0, false)) != NULL) { GA_APPEND(char_u *, &ga, line); } - char *code = (char *)ga_concat_strings_sep(&ga, "\n"); + char *code = ga_concat_strings_sep(&ga, "\n"); size_t len = strlen(code); nlua_typval_exec(code, len, name, NULL, 0, false, NULL); diff --git a/src/nvim/macros.h b/src/nvim/macros.h index faef0f69b2..c2b2c89abf 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) ((x) ? (x) : (char_u *)"") +#define EMPTY_IF_NULL(x) (char *)((x) ? (x) : (char_u *)"") // 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/memline.c b/src/nvim/memline.c index 456b1013c1..edab367f02 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2564,7 +2564,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) */ if (buf->b_ml.ml_line_count == 1) { // file becomes empty if (message) { - set_keep_msg((char_u *)_(no_lines_msg), 0); + set_keep_msg(_(no_lines_msg), 0); } i = ml_replace((linenr_T)1, (char_u *)"", true); diff --git a/src/nvim/message.c b/src/nvim/message.c index 7b6337bea2..8223e6c188 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -329,7 +329,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) if (keep && retval && vim_strsize((char_u *)s) < (int)(Rows - cmdline_row - 1) * Columns + sc_col) { - set_keep_msg((char_u *)s, 0); + set_keep_msg((char *)s, 0); } xfree(buf); @@ -732,7 +732,7 @@ static bool emsg_multiline(const char *s, bool multiline) /// @return true if wait_return not called bool emsg(const char *s) { - return emsg_multiline((const char *)s, false); + return emsg_multiline(s, false); } void emsg_invreg(int name) @@ -1288,11 +1288,11 @@ static void hit_return_msg(void) /* * Set "keep_msg" to "s". Free the old value and check for NULL pointer. */ -void set_keep_msg(char_u *s, int attr) +void set_keep_msg(char *s, int attr) { xfree(keep_msg); if (s != NULL && msg_silent == 0) { - keep_msg = vim_strsave(s); + keep_msg = vim_strsave((char_u *)s); } else { keep_msg = NULL; } @@ -3342,7 +3342,7 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1) } if (msg_attr((const char *)message, keep_msg_attr) && msg_scrolled == 0) { - set_keep_msg(message, keep_msg_attr); + set_keep_msg((char *)message, keep_msg_attr); } msg_didout = false; // Overwrite this message. msg_nowait = true; // Don't wait for this message. diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index faf0b0f633..5ecd4ca431 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -699,7 +699,7 @@ void msgmore(long n) xstrlcat(msg_buf, _(" (Interrupted)"), MSG_BUF_LEN); } if (msg(msg_buf)) { - set_keep_msg((char_u *)msg_buf, 0); + set_keep_msg(msg_buf, 0); keep_msg_more = true; } } diff --git a/src/nvim/option.c b/src/nvim/option.c index b7df856949..5dd7d708f9 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2419,7 +2419,7 @@ static char *did_set_string_option(int opt_idx, char_u **varp, bool new_value_al } } else if (varp == &p_hl) { // 'highlight' - if (strcmp((char *)(*varp), HIGHLIGHT_INIT) != 0) { + if (STRCMP(*varp, HIGHLIGHT_INIT) != 0) { errmsg = e_unsupportedoption; } } else if (varp == &p_jop) { // 'jumpoptions' diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 727b10f7a7..e9f44d2775 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -1048,7 +1048,7 @@ size_t home_replace(const buf_T *const buf, const char_u *src, char_u *const dst } if (buf != NULL && buf->b_help) { - const size_t dlen = xstrlcpy((char *)dst, (char *)path_tail(src), dstlen); + const size_t dlen = STRLCPY(dst, path_tail(src), dstlen); return MIN(dlen, dstlen - 1); } diff --git a/src/nvim/path.c b/src/nvim/path.c index 1085f7a10c..c28d848683 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -65,7 +65,7 @@ FileComparison path_full_compare(char_u *const s1, char_u *const s2, const bool if (expandenv) { expand_env(s1, exp1, MAXPATHL); } else { - xstrlcpy((char *)exp1, (const char *)s1, MAXPATHL); + STRLCPY(exp1, s1, MAXPATHL); } bool id_ok_1 = os_fileid((char *)exp1, &file_id_1); bool id_ok_2 = os_fileid((char *)s2, &file_id_2); @@ -2395,9 +2395,9 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize) if (dir_len + 1 > sizeof(NameBuff)) { continue; } - xstrlcpy((char *)NameBuff, dir, dir_len + 1); - xstrlcat((char *)NameBuff, PATHSEPSTR, sizeof(NameBuff)); - xstrlcat((char *)NameBuff, argv0, sizeof(NameBuff)); + STRLCPY(NameBuff, dir, dir_len + 1); + STRLCAT(NameBuff, PATHSEPSTR, sizeof(NameBuff)); + STRLCAT(NameBuff, argv0, sizeof(NameBuff)); if (os_can_exe((char *)NameBuff, NULL, false)) { xstrlcpy(buf, (char *)NameBuff, bufsize); return; diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 950d187ad5..bf9052de6f 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1183,7 +1183,7 @@ static void qf_store_title(qf_list_T *qfl, const char_u *title) char_u *p = xmallocz(len); qfl->qf_title = p; - xstrlcpy((char *)p, (const char *)title, len + 1); + STRLCPY(p, title, len + 1); } } @@ -1402,7 +1402,7 @@ static int qf_parse_fmt_s(regmatch_T *rmp, int midx, qffields_T *fields) len = CMDBUFFSIZE - 5; } STRCPY(fields->pattern, "^\\V"); - xstrlcat((char *)fields->pattern, (char *)rmp->startp[midx], len + 4); + STRLCAT(fields->pattern, rmp->startp[midx], len + 4); fields->pattern[len + 3] = '\\'; fields->pattern[len + 4] = '$'; fields->pattern[len + 5] = NUL; @@ -1424,7 +1424,7 @@ static int qf_parse_fmt_o(regmatch_T *rmp, int midx, qffields_T *fields) if (dsize > CMDBUFFSIZE) { dsize = CMDBUFFSIZE; } - xstrlcat((char *)fields->module, (char *)rmp->startp[midx], dsize); + STRLCAT(fields->module, rmp->startp[midx], dsize); return QF_OK; } @@ -3231,7 +3231,7 @@ static void qf_msg(qf_info_T *qi, int which, char *lead) memset(buf + len, ' ', 34 - len); buf[34] = NUL; } - xstrlcat((char *)buf, title, IOSIZE); + STRLCAT(buf, title, IOSIZE); } trunc_string(buf, buf, Columns - 1, IOSIZE); msg((char *)buf); diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 674d807e96..14f49d05d5 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -872,7 +872,7 @@ static void add_pack_start_dir(char_u *fname, void *cookie) continue; } STRLCPY(buf, fname, MAXPATHL); - xstrlcat((char *)buf, start_pat[i], sizeof buf); + STRLCAT(buf, start_pat[i], sizeof buf); if (pack_has_entries(buf)) { add_pack_dir_to_rtp(buf, true); } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 63e904079e..cc3fab3503 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3117,7 +3117,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // the match. if (cur != NULL && shl != &search_hl - && syn_name2id((char_u *)"Conceal") == cur->hlg_id) { + && syn_name2id("Conceal") == cur->hlg_id) { has_match_conc = v == (long)shl->startcol ? 2 : 1; match_conc = cur->conceal_char; } else { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 504d1cd16e..8347f1bff1 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4271,7 +4271,7 @@ static char_u *get_syn_options(char_u *arg, syn_opt_arg_T *opt, int *conceal_cha if (STRCMP(gname, "NONE") == 0) { *opt->sync_idx = NONE_IDX; } else { - syn_id = syn_name2id(gname); + syn_id = syn_name2id((char *)gname); int i; for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; ) { if (SYN_ITEMS(curwin->w_s)[i].sp_syn.id == syn_id @@ -5264,7 +5264,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } next_arg = skipwhite(arg_end); } else if (!eap->skip) { - curwin->w_s->b_syn_sync_id = syn_name2id((char_u *)"Comment"); + curwin->w_s->b_syn_sync_id = syn_name2id("Comment"); } } else if (STRNCMP(key, "LINES", 5) == 0 || STRNCMP(key, "MINLINES", 8) == 0 @@ -7403,9 +7403,9 @@ static bool highlight_list_arg(const int id, bool didh, const int type, int iarg for (int i = 0; hl_attr_table[i] != 0; i++) { if (iarg & hl_attr_table[i]) { if (buf[0] != NUL) { - xstrlcat((char *)buf, ",", 100); + xstrlcat(buf, ",", 100); } - xstrlcat((char *)buf, hl_name_table[i], 100); + xstrlcat(buf, hl_name_table[i], 100); iarg &= ~hl_attr_table[i]; // don't want "inverse" } } @@ -7605,10 +7605,10 @@ static void set_hl_attr(int idx) } } -int syn_name2id(const char_u *name) +int syn_name2id(const char *name) FUNC_ATTR_NONNULL_ALL { - return syn_name2id_len(name, STRLEN(name)); + return syn_name2id_len((char_u *)name, STRLEN(name)); } /// Lookup a highlight group name and return its ID. @@ -7641,7 +7641,7 @@ int syn_name2id_len(const char_u *name, size_t len) int syn_name2attr(const char_u *name) FUNC_ATTR_NONNULL_ALL { - int id = syn_name2id(name); + int id = syn_name2id((char *)name); if (id != 0) { return syn_id2attr(id); @@ -7652,7 +7652,7 @@ int syn_name2attr(const char_u *name) /* * Return TRUE if highlight group "name" exists. */ -int highlight_exists(const char_u *name) +int highlight_exists(const char *name) { return syn_name2id(name) > 0; } @@ -7870,7 +7870,7 @@ static void combine_stl_hlt(int id, int id_S, int id_alt, int hlcnt, int i, int void highlight_changed(void) { int id; - char_u userhl[30]; // use 30 to avoid compiler warning + char userhl[30]; // use 30 to avoid compiler warning int id_S = -1; int id_SNC = 0; int hlcnt; @@ -7919,7 +7919,7 @@ void highlight_changed(void) id_S = hlcnt + 10; } for (int i = 0; i < 9; i++) { - sprintf((char *)userhl, "User%d", i + 1); + snprintf(userhl, sizeof(userhl), "User%d", i + 1); id = syn_name2id(userhl); if (id == 0) { highlight_user[i] = 0; diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 9002ac4967..35c68fa1f6 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -393,7 +393,7 @@ void terminal_enter(void) long save_w_p_so = curwin->w_p_so; long save_w_p_siso = curwin->w_p_siso; if (curwin->w_p_cul && curwin->w_p_culopt_flags & CULOPT_NBR) { - if (strcmp((char *)curwin->w_p_culopt, "number")) { + if (STRCMP(curwin->w_p_culopt, "number")) { save_w_p_culopt = curwin->w_p_culopt; curwin->w_p_culopt = (char_u *)xstrdup("number"); } diff --git a/src/nvim/window.c b/src/nvim/window.c index ff5b39eb84..59079584ca 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -569,7 +569,7 @@ wingotofile: static void cmd_with_count(char *cmd, char_u *bufp, size_t bufsize, int64_t Prenum) { - size_t len = xstrlcpy((char *)bufp, cmd, bufsize); + size_t len = STRLCPY(bufp, cmd, bufsize); if (Prenum > 0 && len < bufsize) { vim_snprintf((char *)bufp + len, bufsize - len, "%" PRId64, Prenum); |