diff options
-rw-r--r-- | src/nvim/channel.c | 2 | ||||
-rw-r--r-- | src/nvim/charset.c | 4 | ||||
-rw-r--r-- | src/nvim/drawscreen.c | 6 | ||||
-rw-r--r-- | src/nvim/eval.c | 6 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 6 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_session.c | 2 | ||||
-rw-r--r-- | src/nvim/globals.h | 60 | ||||
-rw-r--r-- | src/nvim/grid.c | 4 | ||||
-rw-r--r-- | src/nvim/highlight_group.c | 2 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 2 | ||||
-rw-r--r-- | src/nvim/lua/stdlib.c | 2 | ||||
-rw-r--r-- | src/nvim/main.c | 2 | ||||
-rw-r--r-- | src/nvim/match.c | 7 | ||||
-rw-r--r-- | src/nvim/message.c | 59 | ||||
-rw-r--r-- | src/nvim/move.c | 2 | ||||
-rw-r--r-- | src/nvim/os/env.c | 2 | ||||
-rw-r--r-- | src/nvim/regexp.c | 14 | ||||
-rw-r--r-- | src/nvim/runtime.c | 27 | ||||
-rw-r--r-- | src/nvim/search.c | 4 | ||||
-rw-r--r-- | src/nvim/spellfile.c | 4 | ||||
-rw-r--r-- | src/nvim/spellsuggest.c | 10 | ||||
-rw-r--r-- | src/nvim/tag.c | 2 | ||||
-rw-r--r-- | test/old/testdir/test_packadd.vim | 7 |
25 files changed, 123 insertions, 117 deletions
diff --git a/src/nvim/channel.c b/src/nvim/channel.c index f68ee2b39e..a0fe3cc734 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -218,7 +218,7 @@ void channel_create_event(Channel *chan, const char *ext_source) source = ext_source; } else { eval_fmt_source_name_line(IObuff, sizeof(IObuff)); - source = (const char *)IObuff; + source = IObuff; } assert(chan->id <= VARNUMBER_MAX); diff --git a/src/nvim/charset.c b/src/nvim/charset.c index a3aa6783ee..63459495f8 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -755,7 +755,7 @@ int ptr2cells(const char *p_in) /// @param s /// /// @return number of character cells. -int vim_strsize(char *s) +int vim_strsize(const char *s) { return vim_strnsize(s, MAXCOL); } @@ -769,7 +769,7 @@ int vim_strsize(char *s) /// @param len /// /// @return Number of character cells. -int vim_strnsize(char *s, int len) +int vim_strnsize(const char *s, int len) { assert(s != NULL); int size = 0; diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 1c8bf56e8e..13e9d1ea49 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -939,9 +939,9 @@ int showmode(void) } if (length - vim_strsize(edit_submode) > 0) { if (edit_submode_pre != NULL) { - msg_puts_attr((const char *)edit_submode_pre, attr); + msg_puts_attr(edit_submode_pre, attr); } - msg_puts_attr((const char *)edit_submode, attr); + msg_puts_attr(edit_submode, attr); } if (edit_submode_extra != NULL) { msg_puts_attr(" ", attr); // Add a space in between. @@ -950,7 +950,7 @@ int showmode(void) } else { sub_attr = attr; } - msg_puts_attr((const char *)edit_submode_extra, sub_attr); + msg_puts_attr(edit_submode_extra, sub_attr); } } } else { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index fc9ddb75ef..edaa2bb809 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -596,7 +596,7 @@ int var_redir_start(char *name, int append) /// :redir => foo /// :let foo /// :redir END -void var_redir_str(char *value, int value_len) +void var_redir_str(const char *value, int value_len) { if (redir_lval == NULL) { return; @@ -2147,10 +2147,10 @@ int pattern_match(const char *pat, const char *text, bool ic) // avoid 'l' flag in 'cpoptions' char *save_cpo = p_cpo; p_cpo = empty_option; - regmatch.regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING); + regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { regmatch.rm_ic = ic; - matches = vim_regexec_nl(®match, (char *)text, (colnr_T)0); + matches = vim_regexec_nl(®match, text, (colnr_T)0); vim_regfree(regmatch.regprog); } p_cpo = save_cpo; diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index df8004dc73..25d383d8ea 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -4670,7 +4670,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, } } - regmatch.regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING); + regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { regmatch.rm_ic = p_ic; @@ -7895,7 +7895,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } regmatch_T regmatch = { - .regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING), + .regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING), .startp = { NULL }, .endp = { NULL }, .rm_ic = false, @@ -7906,7 +7906,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (*str == NUL) { match = false; // Empty item at the end. } else { - match = vim_regexec_nl(®match, (char *)str, col); + match = vim_regexec_nl(®match, str, col); } const char *end; if (match) { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index ac3c8c4f8e..621cb764f4 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4742,7 +4742,7 @@ void ex_oldfiles(exarg_T *eap) } nr++; const char *fname = tv_get_string(TV_LIST_ITEM_TV(li)); - if (!message_filtered((char *)fname)) { + if (!message_filtered(fname)) { msg_outnum(nr); msg_puts(": "); msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li))); diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index c777efb445..a86676733f 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -201,7 +201,7 @@ void dialog_changed(buf_T *buf, bool checkall) .forceit = false, }; - dialog_msg((char *)buff, _("Save changes to \"%s\"?"), buf->b_fname); + dialog_msg(buff, _("Save changes to \"%s\"?"), buf->b_fname); if (checkall) { ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); } else { diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 855a5f7538..d47d40cbee 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -959,7 +959,7 @@ void ex_mkrc(exarg_T *eap) // When using 'viewdir' may have to create the directory. if (using_vdir && !os_isdir(p_vdir)) { - vim_mkdir_emsg((const char *)p_vdir, 0755); + vim_mkdir_emsg(p_vdir, 0755); } fd = open_exfile(fname, eap->forceit, WRITEBIN); diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 816471d7c1..571df45e89 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -169,7 +169,7 @@ EXTERN char *edit_submode_extra INIT(= NULL); // appended to edit_submode EXTERN hlf_T edit_submode_highl; // highl. method for extra info // state for putting characters in the message area -EXTERN int cmdmsg_rl INIT(= false); // cmdline is drawn right to left +EXTERN bool cmdmsg_rl INIT(= false); // cmdline is drawn right to left EXTERN int msg_col; EXTERN int msg_row; EXTERN int msg_scrolled; // Number of screen lines that windows have @@ -224,7 +224,7 @@ EXTERN bool did_wait_return INIT(= false); // wait_return() was used and // nothing written since then EXTERN bool need_maketitle INIT(= true); // call maketitle() soon -EXTERN int quit_more INIT(= false); // 'q' hit at "--more--" msg +EXTERN bool quit_more INIT(= false); // 'q' hit at "--more--" msg EXTERN int vgetc_busy INIT(= 0); // when inside vgetc() then > 0 EXTERN bool didset_vim INIT(= false); // did set $VIM ourselves @@ -233,7 +233,7 @@ EXTERN bool didset_vimruntime INIT(= false); // idem for $VIMRUNTIME /// Lines left before a "more" message. Ex mode needs to be able to reset this /// after you type something. EXTERN int lines_left INIT(= -1); // lines left for listing -EXTERN int msg_no_more INIT(= false); // don't use more prompt, truncate +EXTERN bool msg_no_more INIT(= false); // don't use more prompt, truncate // messages EXTERN int ex_nesting_level INIT(= 0); // nesting level @@ -275,7 +275,7 @@ EXTERN int trylevel INIT(= 0); /// non-zero (and ":silent!" was not used) or an exception is being thrown at /// the time an error is detected. It is set to false when "trylevel" gets /// zero again and there was no error or interrupt or throw. -EXTERN int force_abort INIT(= false); +EXTERN bool force_abort INIT(= false); /// "msg_list" points to a variable in the stack of do_cmdline() which keeps /// the list of arguments of several emsg() calls, one of which is to be @@ -308,8 +308,8 @@ EXTERN except_T *caught_stack INIT(= NULL); /// "garbage_collect_at_exit" indicates garbagecollect(1) was called. /// EXTERN bool may_garbage_collect INIT(= false); -EXTERN int want_garbage_collect INIT(= false); -EXTERN int garbage_collect_at_exit INIT(= false); +EXTERN bool want_garbage_collect INIT(= false); +EXTERN bool garbage_collect_at_exit INIT(= false); // Special values for current_SID. #define SID_MODELINE (-1) // when using a modeline @@ -360,19 +360,19 @@ EXTERN linenr_T search_last_line INIT(= MAXLNUM); // for :{first},{LAST}s/pat EXTERN bool no_smartcase INIT(= false); // don't use 'smartcase' once -EXTERN int need_check_timestamps INIT(= false); // need to check file - // timestamps asap -EXTERN int did_check_timestamps INIT(= false); // did check timestamps - // recently -EXTERN int no_check_timestamps INIT(= 0); // Don't check timestamps +EXTERN bool need_check_timestamps INIT(= false); // need to check file + // timestamps asap +EXTERN bool did_check_timestamps INIT(= false); // did check timestamps + // recently +EXTERN int no_check_timestamps INIT(= 0); // Don't check timestamps -EXTERN int autocmd_busy INIT(= false); // Is apply_autocmds() busy? +EXTERN bool autocmd_busy INIT(= false); // Is apply_autocmds() busy? EXTERN int autocmd_no_enter INIT(= false); // *Enter autocmds disabled EXTERN int autocmd_no_leave INIT(= false); // *Leave autocmds disabled EXTERN int modified_was_set; // did ":set modified" -EXTERN int did_filetype INIT(= false); // FileType event found +EXTERN bool did_filetype INIT(= false); // FileType event found // value for did_filetype when starting to execute autocommands -EXTERN int keep_filetype INIT(= false); +EXTERN bool keep_filetype INIT(= false); // When deleting the current buffer, another one must be loaded. // If we know which one is preferred, au_new_curbuf is set to it. @@ -398,7 +398,7 @@ EXTERN int mouse_dragging INIT(= 0); // extending Visual area with EXTERN vimmenu_T *root_menu INIT(= NULL); // While defining the system menu, sys_menu is true. This avoids // overruling of menus that the user already defined. -EXTERN int sys_menu INIT(= false); +EXTERN bool sys_menu INIT(= false); // All windows are linked in a list. firstwin points to the first entry, // lastwin to the last entry (can be the same as firstwin) and curwin to the @@ -501,7 +501,7 @@ EXTERN bool stderr_isatty INIT(= true); EXTERN int stdin_fd INIT(= -1); // true when doing full-screen output, otherwise only writing some messages. -EXTERN int full_screen INIT(= false); +EXTERN bool full_screen INIT(= false); /// Non-zero when only "safe" commands are allowed EXTERN int secure INIT(= 0); @@ -519,14 +519,14 @@ EXTERN int allbuf_lock INIT(= 0); EXTERN int sandbox INIT(= 0); /// Batch-mode: "-es", "-Es", "-l" commandline argument was given. -EXTERN int silent_mode INIT(= false); +EXTERN bool silent_mode INIT(= false); /// Start position of active Visual selection. EXTERN pos_T VIsual; /// Whether Visual mode is active. -EXTERN int VIsual_active INIT(= false); +EXTERN bool VIsual_active INIT(= false); /// Whether Select mode is active. -EXTERN int VIsual_select INIT(= false); +EXTERN bool VIsual_select INIT(= false); /// Register name for Select mode EXTERN int VIsual_select_reg INIT(= 0); /// Restart Select mode when next cmd finished @@ -536,7 +536,7 @@ EXTERN int VIsual_reselect; /// Type of Visual mode. EXTERN int VIsual_mode INIT(= 'v'); /// true when redoing Visual. -EXTERN int redo_VIsual_busy INIT(= false); +EXTERN bool redo_VIsual_busy INIT(= false); // The Visual area is remembered for reselection. EXTERN int resel_VIsual_mode INIT(= NUL); // 'v', 'V', or Ctrl-V @@ -704,8 +704,8 @@ EXTERN char os_buf[ ///< Buffer for the os/ layer // When non-zero, postpone redrawing. EXTERN int RedrawingDisabled INIT(= 0); -EXTERN int readonlymode INIT(= false); // Set to true for "view" -EXTERN int recoverymode INIT(= false); // Set to true for "-r" option +EXTERN bool readonlymode INIT(= false); // Set to true for "view" +EXTERN bool recoverymode INIT(= false); // Set to true for "-r" option // typeahead buffer EXTERN typebuf_T typebuf INIT(= { NULL, NULL, 0, 0, 0, 0, 0, 0, 0 }); @@ -714,13 +714,13 @@ EXTERN typebuf_T typebuf INIT(= { NULL, NULL, 0, 0, 0, 0, 0, 0, 0 }); /// :normal argument was exhausted. EXTERN bool typebuf_was_empty INIT(= false); -EXTERN int ex_normal_busy INIT(= 0); // recursiveness of ex_normal() -EXTERN int expr_map_lock INIT(= 0); // running expr mapping, prevent use of ex_normal() and text changes -EXTERN int ignore_script INIT(= false); // ignore script input -EXTERN int stop_insert_mode; // for ":stopinsert" -EXTERN bool KeyTyped; // true if user typed current char -EXTERN int KeyStuffed; // true if current char from stuffbuf -EXTERN int maptick INIT(= 0); // tick for each non-mapped char +EXTERN int ex_normal_busy INIT(= 0); // recursiveness of ex_normal() +EXTERN int expr_map_lock INIT(= 0); // running expr mapping, prevent use of ex_normal() and text changes +EXTERN bool ignore_script INIT(= false); // ignore script input +EXTERN int stop_insert_mode; // for ":stopinsert" +EXTERN bool KeyTyped; // true if user typed current char +EXTERN int KeyStuffed; // true if current char from stuffbuf +EXTERN int maptick INIT(= 0); // tick for each non-mapped char EXTERN int must_redraw INIT(= 0); // type of redraw necessary EXTERN bool skip_redraw INIT(= false); // skip redraw once @@ -776,7 +776,7 @@ EXTERN int replace_offset INIT(= 0); // offset for replace_push() EXTERN char *escape_chars INIT(= " \t\\\"|"); // need backslash in cmd line -EXTERN int keep_help_flag INIT(= false); // doing :ta from help file +EXTERN bool keep_help_flag INIT(= false); // doing :ta from help file // When a string option is NULL (which only happens in out-of-memory // situations), it is set to empty_option, to avoid having to check for NULL diff --git a/src/nvim/grid.c b/src/nvim/grid.c index cd70e98047..3c4b1e9d70 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -197,10 +197,10 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char *schar, int attr) /// like grid_puts(), but output "text[len]". When "len" is -1 output up to /// a NUL. -int grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr) +int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int col, int attr) { size_t off; - char *ptr = text; + const char *ptr = text; int len = textlen; int c; size_t max_off; diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 56fa206247..cce124de77 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -1631,7 +1631,7 @@ static bool highlight_list_arg(const int id, bool didh, const int type, int iarg } } - (void)syn_list_header(didh, vim_strsize((char *)ts) + (int)strlen(name) + 1, id, false); + (void)syn_list_header(didh, vim_strsize(ts) + (int)strlen(name) + 1, id, false); didh = true; if (!got_int) { if (*name != NUL) { diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index dfbbfe9ab5..b5dd7a3e78 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -623,7 +623,7 @@ static bool nlua_init_packages(lua_State *lstate, bool is_standalone) lua_getglobal(lstate, "require"); lua_pushstring(lstate, "vim._init_packages"); if (nlua_pcall(lstate, 1, 0)) { - os_errmsg((char *)lua_tostring(lstate, -1)); + os_errmsg(lua_tostring(lstate, -1)); os_errmsg("\n"); return false; } diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index ee5676e927..20a99b2836 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -288,7 +288,7 @@ int nlua_regex(lua_State *lstate) regprog_T *prog = NULL; TRY_WRAP(&err, { - prog = vim_regcomp((char *)text, RE_AUTO | RE_MAGIC | RE_STRICT); + prog = vim_regcomp(text, RE_AUTO | RE_MAGIC | RE_STRICT); }); if (ERROR_SET(&err)) { diff --git a/src/nvim/main.c b/src/nvim/main.c index a16badc1a0..1f16ecff76 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -2153,7 +2153,7 @@ static void print_mainerr(const char *errstr, const char *str) os_errmsg(_(errstr)); if (str != NULL) { os_errmsg(": \""); - os_errmsg((char *)str); + os_errmsg(str); os_errmsg("\""); } os_errmsg(_("\nMore info with \"")); diff --git a/src/nvim/match.c b/src/nvim/match.c index 93c8a58051..29d4b7c225 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -98,7 +98,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in if ((hlg_id = syn_check_group(grp, strlen(grp))) == 0) { return -1; } - if (pat != NULL && (regprog = vim_regcomp((char *)pat, RE_MAGIC)) == NULL) { + if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) { semsg(_(e_invarg2), pat); return -1; } @@ -1232,7 +1232,7 @@ void ex_match(exarg_T *eap) if (!eap->skip) { if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) { xfree(g); - eap->errmsg = ex_errmsg(e_trailing_arg, (const char *)end); + eap->errmsg = ex_errmsg(e_trailing_arg, end); return; } if (*end != *p) { @@ -1243,8 +1243,7 @@ void ex_match(exarg_T *eap) c = (uint8_t)(*end); *end = NUL; - match_add(curwin, (const char *)g, (const char *)p + 1, 10, id, - NULL, NULL); + match_add(curwin, g, p + 1, 10, id, NULL, NULL); xfree(g); *end = (char)c; } diff --git a/src/nvim/message.c b/src/nvim/message.c index aecb46c6bd..98ef6e5cba 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -216,13 +216,13 @@ void msg_grid_validate(void) /// When terminal not initialized (yet) os_errmsg(..) is used. /// /// @return true if wait_return() not called -int msg(char *s) +int msg(const char *s) { return msg_attr_keep(s, 0, false, false); } /// Like msg() but keep it silent when 'verbosefile' is set. -int verb_msg(char *s) +int verb_msg(const char *s) { verbose_enter(); int n = msg_attr_keep(s, 0, false, false); @@ -278,8 +278,7 @@ void msg_multiattr(HlMessage hl_msg, const char *kind, bool history) msg_ext_set_kind(kind); for (uint32_t i = 0; i < kv_size(hl_msg); i++) { HlMessageChunk chunk = kv_A(hl_msg, i); - msg_multiline_attr((const char *)chunk.text.data, chunk.attr, - true, &need_clear); + msg_multiline_attr(chunk.text.data, chunk.attr, true, &need_clear); } if (history && kv_size(hl_msg)) { add_msg_hist_multiattr(NULL, 0, 0, true, hl_msg); @@ -305,7 +304,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) // Skip messages not match ":filter pattern". // Don't filter when there is an error. - if (!emsg_on_display && message_filtered((char *)s)) { + if (!emsg_on_display && message_filtered(s)) { return true; } @@ -333,7 +332,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) // Truncate the message if needed. msg_start(); - buf = msg_strtrunc((char *)s, false); + buf = msg_strtrunc(s, false); if (buf != NULL) { s = buf; } @@ -349,8 +348,8 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) } retval = msg_end(); - if (keep && retval && vim_strsize((char *)s) < (Rows - cmdline_row - 1) * Columns + sc_col) { - set_keep_msg((char *)s, 0); + if (keep && retval && vim_strsize(s) < (Rows - cmdline_row - 1) * Columns + sc_col) { + set_keep_msg(s, 0); } need_fileinfo = false; @@ -365,7 +364,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) /// @return an allocated string or NULL when no truncating is done. /// /// @param force always truncate -char *msg_strtrunc(char *s, int force) +char *msg_strtrunc(const char *s, int force) { char *buf = NULL; @@ -395,7 +394,7 @@ char *msg_strtrunc(char *s, int force) /// Truncate a string "s" to "buf" with cell width "room". /// "s" and "buf" may be equal. -void trunc_string(char *s, char *buf, int room_in, int buflen) +void trunc_string(const char *s, char *buf, int room_in, int buflen) { int room = room_in - 3; // "..." takes 3 chars int half; @@ -503,7 +502,7 @@ int smsg_attr(int attr, const char *s, ...) va_start(arglist, s); vim_vsnprintf(IObuff, IOSIZE, s, arglist); va_end(arglist); - return msg_attr((const char *)IObuff, attr); + return msg_attr(IObuff, attr); } int smsg_attr_keep(int attr, const char *s, ...) @@ -514,7 +513,7 @@ int smsg_attr_keep(int attr, const char *s, ...) va_start(arglist, s); vim_vsnprintf(IObuff, IOSIZE, s, arglist); va_end(arglist); - return msg_attr_keep((const char *)IObuff, attr, true, false); + return msg_attr_keep(IObuff, attr, true, false); } // Remember the last sourcing name/lnum used in an error message, so that it @@ -862,7 +861,7 @@ void siemsg(const char *s, ...) } /// Give an "Internal error" message. -void internal_error(char *where) +void internal_error(const char *where) { siemsg(_(e_intern2), where); } @@ -1327,7 +1326,7 @@ 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 *s, int attr) +void set_keep_msg(const char *s, int attr) { xfree(keep_msg); if (s != NULL && msg_silent == 0) { @@ -1562,7 +1561,7 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr) // If the string starts with a composing character first draw a space on // which the composing char can be drawn. - if (utf_iscomposing(utf_ptr2char((char *)msgstr))) { + if (utf_iscomposing(utf_ptr2char(msgstr))) { msg_puts_attr(" ", attr); } @@ -1598,7 +1597,7 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr) msg_puts_attr_len(plain_start, str - plain_start, attr); } plain_start = str + 1; - msg_puts_attr((const char *)s, attr == 0 ? HL_ATTR(HLF_8) : attr); + msg_puts_attr(s, attr == 0 ? HL_ATTR(HLF_8) : attr); retval += (int)strlen(s); } else { retval++; @@ -1674,7 +1673,7 @@ int msg_outtrans_special(const char *strstart, bool from, int maxlen) // single-byte character or illegal byte text = (char *)transchar_byte_buf(NULL, (uint8_t)text[0]); } - const int len = vim_strsize((char *)text); + const int len = vim_strsize(text); if (maxlen > 0 && retval + len >= maxlen) { break; } @@ -1966,7 +1965,7 @@ void msg_prt_line(char *s, int list) /// Use grid_puts() to output one multi-byte character. /// /// @return the pointer "s" advanced to the next character. -static char *screen_puts_mbyte(char *s, int l, int attr) +static const char *screen_puts_mbyte(const char *s, int l, int attr) { int cw; attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr); @@ -2212,7 +2211,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) } else { l = utfc_ptr2len(s); } - s = screen_puts_mbyte((char *)s, l, attr); + s = screen_puts_mbyte(s, l, attr); did_last_char = true; } else { did_last_char = false; @@ -2229,7 +2228,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) if (p_more) { // Store text for scrolling back. - store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, true); + store_sb_text(&sb_str, s, attr, &sb_col, true); } inc_msg_scrolled(); @@ -2274,7 +2273,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) if (wrap && p_more && !recurse) { // Store text for scrolling back. - store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, true); + store_sb_text(&sb_str, s, attr, &sb_col, true); } if (*s == '\n') { // go to next line @@ -2312,7 +2311,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) // characters and draw them all at once later. if (cmdmsg_rl || (cw > 1 && msg_col + t_col >= Columns - 1)) { if (l > 1) { - s = screen_puts_mbyte((char *)s, l, attr) - 1; + s = screen_puts_mbyte(s, l, attr) - 1; } else { msg_screen_putchar(*s, attr); } @@ -2333,7 +2332,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) t_puts(&t_col, t_s, s, attr); } if (p_more && !recurse && !(s == sb_str + 1 && *sb_str == '\n')) { - store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, false); + store_sb_text(&sb_str, s, attr, &sb_col, false); } msg_check(); @@ -2341,7 +2340,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) /// @return true when ":filter pattern" was used and "msg" does not match /// "pattern". -bool message_filtered(char *msg) +bool message_filtered(const char *msg) { if (cmdmod.cmod_filter_regmatch.regprog == NULL) { return false; @@ -2507,7 +2506,7 @@ static sb_clear_T do_clear_sb_text = SB_CLEAR_NONE; /// @param sb_str start of string /// @param s just after string /// @param finish line ends -static void store_sb_text(char **sb_str, char *s, int attr, int *sb_col, int finish) +static void store_sb_text(const char **sb_str, const char *s, int attr, int *sb_col, int finish) { msgchunk_T *mp; @@ -2681,7 +2680,7 @@ static void t_puts(int *t_col, const char *t_s, const char *s, int attr) attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr); // Output postponed text. msg_didout = true; // Remember that line is not empty. - grid_puts_len(&msg_grid_adj, (char *)t_s, (int)(s - t_s), msg_row, msg_col, attr); + grid_puts_len(&msg_grid_adj, t_s, (int)(s - t_s), msg_row, msg_col, attr); msg_col += *t_col; *t_col = 0; // If the string starts with a composing character don't increment the @@ -3308,7 +3307,7 @@ static void redir_write(const char *const str, const ptrdiff_t maxlen) write_reg_contents(redir_reg, s, (ssize_t)len, true); } if (redir_vname) { - var_redir_str((char *)s, (int)maxlen); + var_redir_str(s, (int)maxlen); } // Write and adjust the current column. @@ -3417,7 +3416,7 @@ int verbose_open(void) /// Give a warning message (for searching). /// Use 'w' highlighting and may repeat the message after redrawing -void give_warning(char *message, bool hl) +void give_warning(const char *message, bool hl) FUNC_ATTR_NONNULL_ARG(1) { // Don't do this for ":silent". @@ -3440,7 +3439,7 @@ void give_warning(char *message, bool hl) msg_ext_set_kind("wmsg"); } - if (msg_attr((const char *)message, keep_msg_attr) && msg_scrolled == 0) { + if (msg_attr(message, keep_msg_attr) && msg_scrolled == 0) { set_keep_msg(message, keep_msg_attr); } msg_didout = false; // Overwrite this message. @@ -3450,7 +3449,7 @@ void give_warning(char *message, bool hl) no_wait_return--; } -void give_warning2(char *const message, char *const a1, bool hl) +void give_warning2(const char *const message, const char *const a1, bool hl) { vim_snprintf(IObuff, IOSIZE, message, a1); give_warning(IObuff, hl); diff --git a/src/nvim/move.c b/src/nvim/move.c index a9f7ffaa76..e74dc32fd4 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -2241,7 +2241,7 @@ void do_check_cursorbind(void) int old_VIsual_active = VIsual_active; // loop through the cursorbound windows - VIsual_select = VIsual_active = 0; + VIsual_select = VIsual_active = false; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { curwin = wp; curbuf = curwin->w_buffer; diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 30092b9142..5b8c060e7a 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -494,7 +494,7 @@ void init_homedir(void) // links. Don't do it when we can't return. if (os_dirname(os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { - var = (char *)IObuff; + var = IObuff; } if (os_chdir(os_buf) != 0) { emsg(_(e_prev_dir)); diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 122f3e2020..0b9a9bbdec 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2304,10 +2304,10 @@ static uint8_t regname[][30] = { // Returns the program in allocated memory. // Use vim_regfree() to free the memory. // Returns NULL for an error. -regprog_T *vim_regcomp(char *expr_arg, int re_flags) +regprog_T *vim_regcomp(const char *expr_arg, int re_flags) { regprog_T *prog = NULL; - char *expr = expr_arg; + const char *expr = expr_arg; regexp_engine = (int)p_re; @@ -2403,7 +2403,7 @@ void free_regexp_stuff(void) #endif -static void report_re_switch(char *pat) +static void report_re_switch(const char *pat) { if (p_verbose > 0) { verbose_enter(); @@ -2425,7 +2425,7 @@ static void report_re_switch(char *pat) /// @param nl /// /// @return true if there is a match, false if not. -static bool vim_regexec_string(regmatch_T *rmp, char *line, colnr_T col, bool nl) +static bool vim_regexec_string(regmatch_T *rmp, const char *line, colnr_T col, bool nl) { regexec_T rex_save; bool rex_in_use_save = rex_in_use; @@ -2482,7 +2482,7 @@ static bool vim_regexec_string(regmatch_T *rmp, char *line, colnr_T col, bool nl // Note: "*prog" may be freed and changed. // Return true if there is a match, false if not. -bool vim_regexec_prog(regprog_T **prog, bool ignore_case, char *line, colnr_T col) +bool vim_regexec_prog(regprog_T **prog, bool ignore_case, const char *line, colnr_T col) { regmatch_T regmatch = { .regprog = *prog, .rm_ic = ignore_case }; bool r = vim_regexec_string(®match, line, col, false); @@ -2492,7 +2492,7 @@ bool vim_regexec_prog(regprog_T **prog, bool ignore_case, char *line, colnr_T co // Note: "rmp->regprog" may be freed and changed. // Return true if there is a match, false if not. -bool vim_regexec(regmatch_T *rmp, char *line, colnr_T col) +bool vim_regexec(regmatch_T *rmp, const char *line, colnr_T col) { return vim_regexec_string(rmp, line, col, false); } @@ -2500,7 +2500,7 @@ bool vim_regexec(regmatch_T *rmp, char *line, colnr_T col) // Like vim_regexec(), but consider a "\n" in "line" to be a line break. // Note: "rmp->regprog" may be freed and changed. // Return true if there is a match, false if not. -bool vim_regexec_nl(regmatch_T *rmp, char *line, colnr_T col) +bool vim_regexec_nl(regmatch_T *rmp, const char *line, colnr_T col) { return vim_regexec_string(rmp, line, col, true); } diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index c9667d58ed..5d1c104dc5 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -914,19 +914,6 @@ static int add_pack_dir_to_rtp(char *fname, bool is_pack) const char *cur_entry = entry; copy_option_part((char **)&entry, buf, MAXPATHL, ","); - if (insp == NULL) { - add_pathsep(buf); - char *const rtp_ffname = fix_fname(buf); - if (rtp_ffname == NULL) { - goto theend; - } - bool match = path_fnamencmp(rtp_ffname, ffname, fname_len) == 0; - xfree(rtp_ffname); - if (match) { - // Insert "ffname" after this entry (and comma). - insp = entry; - } - } if ((p = strstr(buf, "after")) != NULL && p > buf @@ -940,6 +927,20 @@ static int add_pack_dir_to_rtp(char *fname, bool is_pack) after_insp = cur_entry; break; } + + if (insp == NULL) { + add_pathsep(buf); + char *const rtp_ffname = fix_fname(buf); + if (rtp_ffname == NULL) { + goto theend; + } + bool match = path_fnamencmp(rtp_ffname, ffname, fname_len) == 0; + xfree(rtp_ffname); + if (match) { + // Insert "ffname" after this entry (and comma). + insp = entry; + } + } } if (insp == NULL) { diff --git a/src/nvim/search.c b/src/nvim/search.c index 67b6f5e6a6..525cec8b02 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -4159,10 +4159,10 @@ static void show_pat_in_path(char *line, int type, bool did_show, int action, FI } if (action == ACTION_SHOW_ALL) { snprintf(IObuff, IOSIZE, "%3ld: ", count); // Show match nr. - msg_puts((const char *)IObuff); + msg_puts(IObuff); snprintf(IObuff, IOSIZE, "%4" PRIdLINENR, *lnum); // Show line nr. // Highlight line numbers. - msg_puts_attr((const char *)IObuff, HL_ATTR(HLF_N)); + msg_puts_attr(IObuff, HL_ATTR(HLF_N)); msg_puts(" "); } msg_prt_line(line, false); diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 8927b599d0..c68eee3526 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -608,7 +608,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) semsg(_(e_notopen), fname); } else if (p_verbose > 2) { verbose_enter(); - smsg((char *)e_notopen, fname); + smsg(e_notopen, fname); verbose_leave(); } goto endFAIL; @@ -4047,7 +4047,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root node = *prev; } #ifdef SPELL_PRINTTREE - smsg((char_u *)"Added \"%s\"", word); + smsg("Added \"%s\"", word); spell_print_tree(root->wn_sibling); #endif diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 705e215dfa..d28460a63d 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -551,7 +551,7 @@ void spell_suggest(int count) vim_snprintf(IObuff, IOSIZE, ":ot \"%.*s\" egnahC", sug.su_badlen, sug.su_badptr); } - msg_puts((const char *)IObuff); + msg_puts(IObuff); msg_clr_eos(); msg_putchar('\n'); @@ -570,16 +570,16 @@ void spell_suggest(int count) if (cmdmsg_rl) { rl_mirror_ascii(IObuff); } - msg_puts((const char *)IObuff); + msg_puts(IObuff); vim_snprintf(IObuff, IOSIZE, " \"%s\"", wcopy); - msg_puts((const char *)IObuff); + msg_puts(IObuff); // The word may replace more than "su_badlen". if (sug.su_badlen < stp->st_orglen) { vim_snprintf(IObuff, IOSIZE, _(" < \"%.*s\""), stp->st_orglen, sug.su_badptr); - msg_puts((const char *)IObuff); + msg_puts(IObuff); } if (p_verbose > 0) { @@ -597,7 +597,7 @@ void spell_suggest(int count) rl_mirror_ascii(IObuff + 1); } msg_advance(30); - msg_puts((const char *)IObuff); + msg_puts(IObuff); } msg_putchar('\n'); } diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 852e7e6e7c..2d9d0de951 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -726,7 +726,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose) if ((num_matches > prev_num_matches || new_tag) && num_matches > 1) { if (ic) { - msg_attr((const char *)IObuff, HL_ATTR(HLF_W)); + msg_attr(IObuff, HL_ATTR(HLF_W)); } else { msg(IObuff); } diff --git a/test/old/testdir/test_packadd.vim b/test/old/testdir/test_packadd.vim index 3121b3b4d1..64c8fd8659 100644 --- a/test/old/testdir/test_packadd.vim +++ b/test/old/testdir/test_packadd.vim @@ -20,6 +20,13 @@ func Test_packadd() call mkdir(s:plugdir . '/plugin/also', 'p') call mkdir(s:plugdir . '/ftdetect', 'p') call mkdir(s:plugdir . '/after', 'p') + + " This used to crash Vim + let &rtp = 'nosuchdir,' . s:plugdir . '/after' + packadd mytest + " plugdir should be inserted before plugdir/after + call assert_match('^nosuchdir,' . s:plugdir . ',', &rtp) + set rtp& let rtp = &rtp filetype on |