mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 12:08:33 +00:00
refactor: enable -Wconversion warning for message.c
Work on https://github.com/neovim/neovim/issues/567
This commit is contained in:
@@ -165,7 +165,6 @@ set(CONV_SOURCES
|
||||
lua/treesitter.c
|
||||
mbyte.c
|
||||
memline.c
|
||||
message.c
|
||||
regexp.c
|
||||
screen.c
|
||||
search.c
|
||||
|
@@ -136,7 +136,7 @@ static int msg_grid_scroll_discount = 0;
|
||||
static void ui_ext_msg_set_pos(int row, bool scrolled)
|
||||
{
|
||||
char buf[MAX_MCO + 1];
|
||||
size_t size = utf_char2bytes(curwin->w_p_fcs_chars.msgsep, buf);
|
||||
size_t size = (size_t)utf_char2bytes(curwin->w_p_fcs_chars.msgsep, buf);
|
||||
buf[size] = '\0';
|
||||
ui_call_msg_set_pos(msg_grid.handle, row, scrolled,
|
||||
(String){ .data = buf, .size = size });
|
||||
@@ -164,7 +164,7 @@ void msg_grid_validate(void)
|
||||
{
|
||||
grid_assign_handle(&msg_grid);
|
||||
bool should_alloc = msg_use_grid();
|
||||
int max_rows = Rows - p_ch;
|
||||
int max_rows = Rows - (int)p_ch;
|
||||
if (should_alloc && (msg_grid.rows != Rows || msg_grid.cols != Columns
|
||||
|| !msg_grid.chars)) {
|
||||
// TODO(bfredl): eventually should be set to "invalid". I e all callers
|
||||
@@ -173,7 +173,7 @@ void msg_grid_validate(void)
|
||||
msg_grid.zindex = kZIndexMessages;
|
||||
|
||||
xfree(msg_grid.dirty_col);
|
||||
msg_grid.dirty_col = xcalloc(Rows, sizeof(*msg_grid.dirty_col));
|
||||
msg_grid.dirty_col = xcalloc((size_t)Rows, sizeof(*msg_grid.dirty_col));
|
||||
|
||||
// Tricky: allow resize while pager is active
|
||||
int pos = msg_scrolled ? msg_grid_pos : max_rows;
|
||||
@@ -248,7 +248,7 @@ void msg_multiline_attr(const char *s, int attr, bool check_int, bool *need_clea
|
||||
|
||||
if (next_spec != NULL) {
|
||||
// Printing all char that are before the char found by strpbrk
|
||||
msg_outtrans_len_attr((const char_u *)s, next_spec - s, attr);
|
||||
msg_outtrans_len_attr((const char_u *)s, (int)(next_spec - s), attr);
|
||||
|
||||
if (*next_spec != TAB && *need_clear) {
|
||||
msg_clr_eos();
|
||||
@@ -386,7 +386,7 @@ char_u *msg_strtrunc(char_u *s, int force)
|
||||
// may have up to 18 bytes per cell (6 per char, up to two
|
||||
// composing chars)
|
||||
len = (room + 2) * 18;
|
||||
buf = xmalloc(len);
|
||||
buf = xmalloc((size_t)len);
|
||||
trunc_string(s, buf, room, len);
|
||||
}
|
||||
}
|
||||
@@ -397,9 +397,9 @@ char_u *msg_strtrunc(char_u *s, int force)
|
||||
/// "s" and "buf" may be equal.
|
||||
void trunc_string(char_u *s, char_u *buf, int room_in, int buflen)
|
||||
{
|
||||
size_t room = room_in - 3; // "..." takes 3 chars
|
||||
size_t half;
|
||||
size_t len = 0;
|
||||
int room = room_in - 3; // "..." takes 3 chars
|
||||
int half;
|
||||
int len = 0;
|
||||
int e;
|
||||
int i;
|
||||
int n;
|
||||
@@ -454,25 +454,25 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen)
|
||||
if (i <= e + 3) {
|
||||
// text fits without truncating
|
||||
if (s != buf) {
|
||||
len = STRLEN(s);
|
||||
if (len >= (size_t)buflen) {
|
||||
len = (int)STRLEN(s);
|
||||
if (len >= buflen) {
|
||||
len = buflen - 1;
|
||||
}
|
||||
len = len - e + 1;
|
||||
if (len < 1) {
|
||||
buf[e - 1] = NUL;
|
||||
} else {
|
||||
memmove(buf + e, s + e, len);
|
||||
memmove(buf + e, s + e, (size_t)len);
|
||||
}
|
||||
}
|
||||
} else if (e + 3 < buflen) {
|
||||
// set the middle and copy the last part
|
||||
memmove(buf + e, "...", (size_t)3);
|
||||
len = STRLEN(s + i) + 1;
|
||||
if (len >= (size_t)buflen - e - 3) {
|
||||
len = (int)STRLEN(s + i) + 1;
|
||||
if (len >= buflen - e - 3) {
|
||||
len = buflen - e - 3 - 1;
|
||||
}
|
||||
memmove(buf + e + 3, s + i, len);
|
||||
memmove(buf + e + 3, s + i, (size_t)len);
|
||||
buf[e + 3 + len - 1] = NUL;
|
||||
} else {
|
||||
// can't fit in the "...", just truncate it
|
||||
@@ -671,17 +671,17 @@ static bool emsg_multiline(const char *s, bool multiline)
|
||||
if (p != NULL) {
|
||||
const size_t p_len = strlen(p);
|
||||
p[p_len] = '\n';
|
||||
redir_write(p, p_len + 1);
|
||||
redir_write(p, (ptrdiff_t)p_len + 1);
|
||||
xfree(p);
|
||||
}
|
||||
p = get_emsg_lnum();
|
||||
if (p != NULL) {
|
||||
const size_t p_len = strlen(p);
|
||||
p[p_len] = '\n';
|
||||
redir_write(p, p_len + 1);
|
||||
redir_write(p, (ptrdiff_t)p_len + 1);
|
||||
xfree(p);
|
||||
}
|
||||
redir_write(s, strlen(s));
|
||||
redir_write(s, (ptrdiff_t)strlen(s));
|
||||
}
|
||||
|
||||
// Log (silent) errors as debug messages.
|
||||
@@ -1444,7 +1444,7 @@ void msg_putchar(int c)
|
||||
|
||||
void msg_putchar_attr(int c, int attr)
|
||||
{
|
||||
char_u buf[MB_MAXBYTES + 1];
|
||||
char buf[MB_MAXBYTES + 1];
|
||||
|
||||
if (IS_SPECIAL(c)) {
|
||||
buf[0] = (char)K_SPECIAL;
|
||||
@@ -2025,7 +2025,7 @@ void msg_puts_attr(const char *const s, const int attr)
|
||||
void msg_puts_attr_len(const char *const str, const ptrdiff_t len, int attr)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
assert(len < 0 || memchr(str, 0, len) == NULL);
|
||||
assert(len < 0 || memchr(str, 0, (size_t)len) == NULL);
|
||||
// If redirection is on, also write to the redirection file.
|
||||
redir_write(str, len);
|
||||
|
||||
@@ -2074,7 +2074,7 @@ void msg_puts_attr_len(const char *const str, const ptrdiff_t len, int attr)
|
||||
}
|
||||
}
|
||||
if (!msg_use_printf() || (headless_mode && default_grid.chars)) {
|
||||
msg_puts_display((const char_u *)str, len, attr, false);
|
||||
msg_puts_display((const char_u *)str, (int)len, attr, false);
|
||||
}
|
||||
|
||||
need_fileinfo = false;
|
||||
@@ -2094,7 +2094,7 @@ void msg_printf_attr(const int attr, const char *const fmt, ...)
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
const size_t len = vim_vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
|
||||
const size_t len = (size_t)vim_vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
msg_scroll = true;
|
||||
@@ -2336,7 +2336,7 @@ bool message_filtered(char_u *msg)
|
||||
/// including horizontal separator
|
||||
int msg_scrollsize(void)
|
||||
{
|
||||
return msg_scrolled + p_ch + 1;
|
||||
return msg_scrolled + (int)p_ch + 1;
|
||||
}
|
||||
|
||||
bool msg_use_msgsep(void)
|
||||
@@ -2364,7 +2364,7 @@ void msg_scroll_up(bool may_throttle)
|
||||
} else {
|
||||
grid_del_lines(&msg_grid, 0, 1, msg_grid.rows, 0, msg_grid.cols);
|
||||
memmove(msg_grid.dirty_col, msg_grid.dirty_col + 1,
|
||||
(msg_grid.rows - 1) * sizeof(*msg_grid.dirty_col));
|
||||
(size_t)(msg_grid.rows - 1) * sizeof(*msg_grid.dirty_col));
|
||||
msg_grid.dirty_col[msg_grid.rows - 1] = 0;
|
||||
}
|
||||
} else {
|
||||
@@ -2438,7 +2438,7 @@ void msg_reset_scroll(void)
|
||||
msg_grid.throttled = false;
|
||||
// TODO(bfredl): risk for extra flicker i e with
|
||||
// "nvim -o has_swap also_has_swap"
|
||||
msg_grid_set_pos(Rows - p_ch, false);
|
||||
msg_grid_set_pos(Rows - (int)p_ch, false);
|
||||
clear_cmdline = true;
|
||||
if (msg_grid.chars) {
|
||||
// non-displayed part of msg_grid is considered invalid.
|
||||
@@ -2509,11 +2509,11 @@ static void store_sb_text(char_u **sb_str, char_u *s, int attr, int *sb_col, int
|
||||
}
|
||||
|
||||
if (s > *sb_str) {
|
||||
mp = xmalloc((sizeof(msgchunk_T) + (s - *sb_str)));
|
||||
mp->sb_eol = finish;
|
||||
mp = xmalloc((sizeof(msgchunk_T) + (size_t)(s - *sb_str)));
|
||||
mp->sb_eol = (char)finish;
|
||||
mp->sb_msg_col = *sb_col;
|
||||
mp->sb_attr = attr;
|
||||
memcpy(mp->sb_text, *sb_str, s - *sb_str);
|
||||
memcpy(mp->sb_text, *sb_str, (size_t)(s - *sb_str));
|
||||
mp->sb_text[s - *sb_str] = NUL;
|
||||
|
||||
if (last_msgchunk == NULL) {
|
||||
@@ -2691,7 +2691,7 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen)
|
||||
if (*s == '\n' && !info_message) {
|
||||
*p++ = '\r';
|
||||
}
|
||||
memcpy(p, s, len);
|
||||
memcpy(p, s, (size_t)len);
|
||||
*(p + len) = '\0';
|
||||
if (info_message) {
|
||||
mch_msg(buf);
|
||||
@@ -3264,10 +3264,10 @@ static void redir_write(const char *const str, const ptrdiff_t maxlen)
|
||||
ga_concat_len(capture_ga, str, len);
|
||||
}
|
||||
if (redir_reg) {
|
||||
write_reg_contents(redir_reg, s, len, true);
|
||||
write_reg_contents(redir_reg, s, (ssize_t)len, true);
|
||||
}
|
||||
if (redir_vname) {
|
||||
var_redir_str((char *)s, maxlen);
|
||||
var_redir_str((char *)s, (int)maxlen);
|
||||
}
|
||||
|
||||
// Write and adjust the current column.
|
||||
@@ -3615,10 +3615,10 @@ static char_u *console_dialog_alloc(const char_u *message, char_u *buttons, bool
|
||||
|
||||
// Now allocate space for the strings
|
||||
xfree(confirm_msg);
|
||||
confirm_msg = xmalloc(len);
|
||||
confirm_msg = xmalloc((size_t)len);
|
||||
*confirm_msg = NUL;
|
||||
|
||||
return xmalloc(lenhotkey);
|
||||
return xmalloc((size_t)lenhotkey);
|
||||
}
|
||||
|
||||
/// Format the dialog string, and display it at the bottom of
|
||||
|
Reference in New Issue
Block a user