diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 81b93e5304..23256694af 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -204,7 +204,7 @@ static inline void clear_hist_entry(histentry_T *hisptr) /// If 'move_to_front' is true, matching entry is moved to end of history. /// /// @param move_to_front Move the entry to the front if it exists -static int in_history(int type, char *str, int move_to_front, int sep) +static int in_history(int type, const char *str, int move_to_front, int sep) { int last_i = -1; @@ -238,7 +238,7 @@ static int in_history(int type, char *str, int move_to_front, int sep) } list_T *const list = history[type][i].additional_elements; - str = history[type][i].hisstr; + char *const save_hisstr = history[type][i].hisstr; while (i != hisidx[type]) { if (++i >= hislen) { i = 0; @@ -248,7 +248,7 @@ static int in_history(int type, char *str, int move_to_front, int sep) } tv_list_unref(list); history[type][i].hisnum = ++hisnum[type]; - history[type][i].hisstr = str; + history[type][i].hisstr = save_hisstr; history[type][i].timestamp = os_time(); history[type][i].additional_elements = NULL; return true; @@ -295,7 +295,7 @@ static int last_maptick = -1; // last seen maptick /// @param histype may be one of the HIST_ values. /// @param in_map consider maptick when inside a mapping /// @param sep separator character used (search hist) -void add_to_history(int histype, char *new_entry, int in_map, int sep) +void add_to_history(int histype, const char *new_entry, int in_map, int sep) { histentry_T *hisptr; @@ -538,7 +538,7 @@ void f_histadd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } init_history(); - add_to_history(histype, (char *)str, false, NUL); + add_to_history(histype, str, false, NUL); rettv->vval.v_number = true; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index c56b8da896..3f6a876838 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -925,8 +925,7 @@ static void f_confirm(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (!error) { - rettv->vval.v_number = do_dialog(type, NULL, (char *)message, (char *)buttons, def, NULL, - false); + rettv->vval.v_number = do_dialog(type, NULL, message, buttons, def, NULL, false); } } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index d061345453..b43a509ca2 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -388,7 +388,7 @@ typedef struct { static int string_compare(const void *s1, const void *s2) FUNC_ATTR_NONNULL_ALL { if (sort_lc) { - return strcoll((char *)s1, (char *)s2); + return strcoll((const char *)s1, (const char *)s2); } return sort_ic ? STRICMP(s1, s2) : strcmp(s1, s2); } diff --git a/src/nvim/message.c b/src/nvim/message.c index 55a455a7c2..1f5d1d0e60 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -3503,8 +3503,8 @@ void msg_advance(int col) /// @param textfiel IObuff for inputdialog(), NULL otherwise /// @param ex_cmd when true pressing : accepts default and starts Ex command /// @returns 0 if cancelled, otherwise the nth button (1-indexed). -int do_dialog(int type, char *title, char *message, char *buttons, int dfltbutton, char *textfield, - int ex_cmd) +int do_dialog(int type, const char *title, const char *message, const char *buttons, int dfltbutton, + const char *textfield, int ex_cmd) { int retval = 0; char *hotkeys; @@ -3611,7 +3611,7 @@ static int copy_char(const char *from, char *to, bool lowercase) /// corresponding button has a hotkey /// /// @return Pointer to memory allocated for storing hotkeys -static char *console_dialog_alloc(const char *message, char *buttons, bool has_hotkey[]) +static char *console_dialog_alloc(const char *message, const char *buttons, bool has_hotkey[]) { int lenhotkey = HOTK_LEN; // count first button has_hotkey[0] = false; @@ -3619,7 +3619,7 @@ static char *console_dialog_alloc(const char *message, char *buttons, bool has_h // Compute the size of memory to allocate. int len = 0; int idx = 0; - char *r = buttons; + const char *r = buttons; while (*r) { if (*r == DLG_BUTTON_SEP) { len += 3; // '\n' -> ', '; 'x' -> '(x)' @@ -3665,7 +3665,7 @@ static char *console_dialog_alloc(const char *message, char *buttons, bool has_h /// The hotkeys can be multi-byte characters, but without combining chars. /// /// @return an allocated string with hotkeys. -static char *msg_show_console_dialog(char *message, char *buttons, int dfltbutton) +static char *msg_show_console_dialog(const char *message, const char *buttons, int dfltbutton) FUNC_ATTR_NONNULL_RET { bool has_hotkey[HAS_HOTKEY_LEN] = { false }; @@ -3685,7 +3685,7 @@ static char *msg_show_console_dialog(char *message, char *buttons, int dfltbutto /// @param has_hotkey An element in this array is true if corresponding button /// has a hotkey /// @param[out] hotkeys_ptr Pointer to the memory location where hotkeys will be copied -static void copy_hotkeys_and_msg(const char *message, char *buttons, int default_button_idx, +static void copy_hotkeys_and_msg(const char *message, const char *buttons, int default_button_idx, const bool has_hotkey[], char *hotkeys_ptr) { *confirm_msg = '\n'; @@ -3708,7 +3708,7 @@ static void copy_hotkeys_and_msg(const char *message, char *buttons, int default } int idx = 0; - char *r = buttons; + const char *r = buttons; while (*r) { if (*r == DLG_BUTTON_SEP) { *msgp++ = ','; diff --git a/src/nvim/path.c b/src/nvim/path.c index 9239668717..c0d1eff49e 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1805,7 +1805,7 @@ bool path_with_extension(const char *path, const char *extension) } /// Return true if "name" is a full (absolute) path name or URL. -bool vim_isAbsName(char *name) +bool vim_isAbsName(const char *name) { return path_with_url(name) != 0 || path_is_absolute(name); } @@ -1866,7 +1866,7 @@ char *fix_fname(const char *fname) #ifdef UNIX return FullName_save(fname, true); #else - if (!vim_isAbsName((char *)fname) + if (!vim_isAbsName(fname) || strstr(fname, "..") != NULL || strstr(fname, "//") != NULL # ifdef BACKSLASH_IN_FILENAME diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 3989b91203..2a60ec2bb2 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -248,8 +248,8 @@ StlClickDefinition *stl_alloc_click_defs(StlClickDefinition *cdp, long width, si } /// Fill the click definitions array if needed. -void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_recs, char *buf, - int width, bool tabline) +void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_recs, + const char *buf, int width, bool tabline) { if (click_defs == NULL) { return; @@ -270,7 +270,7 @@ void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_r } else { xfree(cur_click_def.func); } - buf = (char *)click_recs[i].start; + buf = click_recs[i].start; cur_click_def = click_recs[i].def; if (!tabline && !(cur_click_def.type == kStlClickDisabled || cur_click_def.type == kStlClickFuncRun)) { @@ -2074,9 +2074,9 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n // to be moved backwards. if (stl_items[i].start >= trunc_end_p) { stl_items[i].start -= item_offset; + } else { // Anything inside the truncated area is set to start // at the `<` truncation character. - } else { stl_items[i].start = trunc_p; } }