aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-06-29 15:48:42 +0800
committerGitHub <noreply@github.com>2023-06-29 15:48:42 +0800
commitaa362a2af8ce353d7082834a54bcc124ebd2a026 (patch)
treebafb18698aa5934574d5d31e26e9871667b1d146 /src
parent7d0a23973b7d0804089e3bfeb2372f4b818d6046 (diff)
downloadrneovim-aa362a2af8ce353d7082834a54bcc124ebd2a026.tar.gz
rneovim-aa362a2af8ce353d7082834a54bcc124ebd2a026.tar.bz2
rneovim-aa362a2af8ce353d7082834a54bcc124ebd2a026.zip
refactor: remove some casts to char * (#24200)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/cmdhist.c10
-rw-r--r--src/nvim/eval/funcs.c3
-rw-r--r--src/nvim/ex_cmds.c2
-rw-r--r--src/nvim/message.c14
-rw-r--r--src/nvim/path.c4
-rw-r--r--src/nvim/statusline.c8
6 files changed, 20 insertions, 21 deletions
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index fc84cecc1a..072898706b 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 33f1ed51e5..99fec3d773 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -873,8 +873,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 40afb3250c..591f8febdc 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -389,7 +389,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 0064f0358b..c60e5c31fd 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -3511,8 +3511,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;
@@ -3619,7 +3619,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;
@@ -3627,7 +3627,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)'
@@ -3673,7 +3673,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 };
@@ -3693,7 +3693,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';
@@ -3716,7 +3716,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 ea0d5a8be1..0927a3a102 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1810,7 +1810,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);
}
@@ -1871,7 +1871,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 60523925e9..dd602ddf87 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)) {
@@ -2077,9 +2077,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;
}
}