Enable -Wconversion for getchar.c

This commit is contained in:
sach1t
2016-05-03 21:25:38 -04:00
committed by Felipe Oliveira Carvalho
parent f4979d368c
commit 8f2ac8a731
2 changed files with 57 additions and 52 deletions

View File

@@ -87,7 +87,6 @@ set(CONV_SOURCES
ex_docmd.c ex_docmd.c
ex_getln.c ex_getln.c
fileio.c fileio.c
getchar.c
mbyte.c mbyte.c
memline.c memline.c
message.c message.c

View File

@@ -144,7 +144,7 @@ static int KeyNoremap = 0; /* remapping flags */
static char_u typebuf_init[TYPELEN_INIT]; /* initial typebuf.tb_buf */ static char_u typebuf_init[TYPELEN_INIT]; /* initial typebuf.tb_buf */
static char_u noremapbuf_init[TYPELEN_INIT]; /* initial typebuf.tb_noremap */ static char_u noremapbuf_init[TYPELEN_INIT]; /* initial typebuf.tb_noremap */
static int last_recorded_len = 0; /* number of last recorded chars */ static unsigned int last_recorded_len = 0; // number of last recorded chars
static const uint8_t ui_toggle[] = { K_SPECIAL, KS_EXTRA, KE_PASTE, 0 }; static const uint8_t ui_toggle[] = { K_SPECIAL, KS_EXTRA, KE_PASTE, 0 };
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -211,7 +211,7 @@ char_u *get_recorded(void)
* (possibly mapped) characters that stopped the recording. * (possibly mapped) characters that stopped the recording.
*/ */
len = STRLEN(p); len = STRLEN(p);
if ((int)len >= last_recorded_len) { if (len >= last_recorded_len) {
len -= last_recorded_len; len -= last_recorded_len;
p[len] = NUL; p[len] = NUL;
} }
@@ -243,13 +243,15 @@ static void
add_buff ( add_buff (
buffheader_T *buf, buffheader_T *buf,
char_u *s, char_u *s,
long slen /* length of "s" or -1 */ ssize_t slen // length of "s" or -1
) )
{ {
if (slen < 0) if (slen < 0) {
slen = (long)STRLEN(s); slen = (ssize_t)STRLEN(s);
if (slen == 0) /* don't add empty strings */ }
if (slen == 0) { // don't add empty strings
return; return;
}
if (buf->bh_first.b_next == NULL) { /* first add to list */ if (buf->bh_first.b_next == NULL) { /* first add to list */
buf->bh_space = 0; buf->bh_space = 0;
@@ -264,16 +266,16 @@ add_buff (
buf->bh_index = 0; buf->bh_index = 0;
ssize_t len; ssize_t len;
if (buf->bh_space >= (int)slen) { if (buf->bh_space >= slen) {
len = STRLEN(buf->bh_curr->b_str); len = (ssize_t)STRLEN(buf->bh_curr->b_str);
STRLCPY(buf->bh_curr->b_str + len, s, slen + 1); STRLCPY(buf->bh_curr->b_str + len, s, slen + 1);
buf->bh_space -= slen; buf->bh_space -= (int)slen;
} else { } else {
if (slen < MINIMAL_SIZE) if (slen < MINIMAL_SIZE)
len = MINIMAL_SIZE; len = MINIMAL_SIZE;
else else
len = slen; len = slen;
buffblock_T *p = xmalloc(sizeof(buffblock_T) + len); buffblock_T *p = xmalloc(sizeof(buffblock_T) + (size_t)len);
buf->bh_space = (int)(len - slen); buf->bh_space = (int)(len - slen);
STRLCPY(p->b_str, s, slen + 1); STRLCPY(p->b_str, s, slen + 1);
@@ -317,11 +319,11 @@ static void add_char_buff(buffheader_T *buf, int c)
if (IS_SPECIAL(c) || c == K_SPECIAL || c == NUL) { if (IS_SPECIAL(c) || c == K_SPECIAL || c == NUL) {
/* translate special key code into three byte sequence */ /* translate special key code into three byte sequence */
temp[0] = K_SPECIAL; temp[0] = K_SPECIAL;
temp[1] = K_SECOND(c); temp[1] = (char_u)K_SECOND(c);
temp[2] = K_THIRD(c); temp[2] = (char_u)K_THIRD(c);
temp[3] = NUL; temp[3] = NUL;
} else { } else {
temp[0] = c; temp[0] = (char_u)c;
temp[1] = NUL; temp[1] = NUL;
} }
add_buff(buf, temp, -1L); add_buff(buf, temp, -1L);
@@ -694,10 +696,11 @@ static int read_redo(int init, int old_redo)
bp = bp->b_next; bp = bp->b_next;
p = bp->b_str; p = bp->b_str;
} }
buf[i] = c; buf[i] = (char_u)c;
if (i == n - 1) { /* last byte of a character */ if (i == n - 1) { // last byte of a character
if (n != 1) if (n != 1) {
c = (*mb_ptr2char)(buf); c = (*mb_ptr2char)(buf);
}
break; break;
} }
c = *p; c = *p;
@@ -882,8 +885,8 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent)
setcursor(); setcursor();
return FAIL; return FAIL;
} }
s1 = xmalloc(newlen); s1 = xmalloc((size_t)newlen);
s2 = xmalloc(newlen); s2 = xmalloc((size_t)newlen);
typebuf.tb_buflen = newlen; typebuf.tb_buflen = newlen;
/* copy the old chars, before the insertion point */ /* copy the old chars, before the insertion point */
@@ -937,7 +940,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent)
nrm = noremap; nrm = noremap;
for (i = 0; i < addlen; ++i) for (i = 0; i < addlen; ++i)
typebuf.tb_noremap[typebuf.tb_off + i + offset] = typebuf.tb_noremap[typebuf.tb_off + i + offset] =
(--nrm >= 0) ? val : RM_YES; (char_u)((--nrm >= 0) ? val : RM_YES);
/* tb_maplen and tb_silent only remember the length of mapped and/or /* tb_maplen and tb_silent only remember the length of mapped and/or
* silent mappings at the start of the buffer, assuming that a mapped * silent mappings at the start of the buffer, assuming that a mapped
@@ -965,8 +968,8 @@ void ins_char_typebuf(int c)
char_u buf[MB_MAXBYTES + 1]; char_u buf[MB_MAXBYTES + 1];
if (IS_SPECIAL(c)) { if (IS_SPECIAL(c)) {
buf[0] = K_SPECIAL; buf[0] = K_SPECIAL;
buf[1] = K_SECOND(c); buf[1] = (char_u)K_SECOND(c);
buf[2] = K_THIRD(c); buf[2] = (char_u)K_THIRD(c);
buf[3] = NUL; buf[3] = NUL;
} else { } else {
buf[(*mb_char2bytes)(c, buf)] = NUL; buf[(*mb_char2bytes)(c, buf)] = NUL;
@@ -1090,9 +1093,11 @@ static void gotchars(char_u *chars, int len)
char_u buf[2]; char_u buf[2];
int todo = len; int todo = len;
/* remember how many chars were last recorded */ // remember how many chars were last recorded
if (Recording) if (Recording) {
last_recorded_len += len; assert(len >= 0);
last_recorded_len += (unsigned int)len;
}
buf[1] = NUL; buf[1] = NUL;
while (todo--) { while (todo--) {
@@ -1101,7 +1106,7 @@ static void gotchars(char_u *chars, int len)
updatescript(c); updatescript(c);
if (Recording) { if (Recording) {
buf[0] = c; buf[0] = (char_u)c;
add_buff(&recordbuff, buf, 1L); add_buff(&recordbuff, buf, 1L);
} }
} }
@@ -1465,10 +1470,10 @@ int vgetc(void)
* Note: This will loop until enough bytes are received! * Note: This will loop until enough bytes are received!
*/ */
if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1) { if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1) {
++no_mapping; no_mapping++;
buf[0] = c; buf[0] = (char_u)c;
for (i = 1; i < n; ++i) { for (i = 1; i < n; i++) {
buf[i] = vgetorpeek(TRUE); buf[i] = (char_u)vgetorpeek(true);
if (buf[i] == K_SPECIAL if (buf[i] == K_SPECIAL
) { ) {
/* Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence, /* Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence,
@@ -1711,7 +1716,7 @@ static int vgetorpeek(int advance)
if (advance) { if (advance) {
/* Also record this character, it might be needed to /* Also record this character, it might be needed to
* get out of Insert mode. */ * get out of Insert mode. */
*typebuf.tb_buf = c; *typebuf.tb_buf = (char_u)c;
gotchars(typebuf.tb_buf, 1); gotchars(typebuf.tb_buf, 1);
} }
cmd_silent = FALSE; cmd_silent = FALSE;
@@ -1888,8 +1893,8 @@ static int vgetorpeek(int advance)
(long)!p_paste, NULL, 0); (long)!p_paste, NULL, 0);
if (!(State & INSERT)) { if (!(State & INSERT)) {
msg_col = 0; msg_col = 0;
msg_row = Rows - 1; msg_row = (int)Rows - 1;
msg_clr_eos(); /* clear ruler */ msg_clr_eos(); // clear ruler
} }
status_redraw_all(); status_redraw_all();
redraw_statuslines(); redraw_statuslines();
@@ -2417,7 +2422,7 @@ inchar (
else else
return -1; return -1;
} else { } else {
buf[0] = script_char; buf[0] = (char_u)script_char;
len = 1; len = 1;
} }
} }
@@ -2453,7 +2458,7 @@ inchar (
* Fill up to a third of the buffer, because each character may be * Fill up to a third of the buffer, because each character may be
* tripled below. * tripled below.
*/ */
len = os_inchar(buf, maxlen / 3, wait_time, tb_change_cnt); len = os_inchar(buf, maxlen / 3, (int)wait_time, tb_change_cnt);
} }
if (typebuf_changed(tb_change_cnt)) if (typebuf_changed(tb_change_cnt))
@@ -2496,8 +2501,8 @@ fix_input_buffer (
&& !script && !script
&& (i < 2 || p[1] != KS_EXTRA))) { && (i < 2 || p[1] != KS_EXTRA))) {
memmove(p + 3, p + 1, (size_t)i); memmove(p + 3, p + 1, (size_t)i);
p[2] = K_THIRD(p[0]); p[2] = (char_u)K_THIRD(p[0]);
p[1] = K_SECOND(p[0]); p[1] = (char_u)K_SECOND(p[0]);
p[0] = K_SPECIAL; p[0] = K_SPECIAL;
p += 2; p += 2;
len += 2; len += 2;
@@ -2573,11 +2578,11 @@ do_map (
int new_hash; int new_hash;
mapblock_T **abbr_table; mapblock_T **abbr_table;
mapblock_T **map_table; mapblock_T **map_table;
int unique = FALSE; bool unique = false;
int nowait = FALSE; bool nowait = false;
int silent = FALSE; bool silent = false;
int special = FALSE; bool special = false;
int expr = FALSE; bool expr = false;
int noremap; int noremap;
char_u *orig_rhs; char_u *orig_rhs;
@@ -2609,7 +2614,7 @@ do_map (
*/ */
if (STRNCMP(keys, "<nowait>", 8) == 0) { if (STRNCMP(keys, "<nowait>", 8) == 0) {
keys = skipwhite(keys + 8); keys = skipwhite(keys + 8);
nowait = TRUE; nowait = true;
continue; continue;
} }
@@ -2618,7 +2623,7 @@ do_map (
*/ */
if (STRNCMP(keys, "<silent>", 8) == 0) { if (STRNCMP(keys, "<silent>", 8) == 0) {
keys = skipwhite(keys + 8); keys = skipwhite(keys + 8);
silent = TRUE; silent = true;
continue; continue;
} }
@@ -2627,7 +2632,7 @@ do_map (
*/ */
if (STRNCMP(keys, "<special>", 9) == 0) { if (STRNCMP(keys, "<special>", 9) == 0) {
keys = skipwhite(keys + 9); keys = skipwhite(keys + 9);
special = TRUE; special = true;
continue; continue;
} }
@@ -2645,7 +2650,7 @@ do_map (
*/ */
if (STRNCMP(keys, "<expr>", 6) == 0) { if (STRNCMP(keys, "<expr>", 6) == 0) {
keys = skipwhite(keys + 6); keys = skipwhite(keys + 6);
expr = TRUE; expr = true;
continue; continue;
} }
/* /*
@@ -2653,7 +2658,7 @@ do_map (
*/ */
if (STRNCMP(keys, "<unique>", 8) == 0) { if (STRNCMP(keys, "<unique>", 8) == 0) {
keys = skipwhite(keys + 8); keys = skipwhite(keys + 8);
unique = TRUE; unique = true;
continue; continue;
} }
break; break;
@@ -3487,7 +3492,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file)
break; /* for (round) */ break; /* for (round) */
if (round == 1) { if (round == 1) {
*file = (char_u **)xmalloc(count * sizeof(char_u *)); *file = (char_u **)xmalloc((size_t)count * sizeof(char_u *));
} }
} /* for (round) */ } /* for (round) */
@@ -3651,8 +3656,8 @@ int check_abbr(int c, char_u *ptr, int col, int mincol)
/* special key code, split up */ /* special key code, split up */
if (IS_SPECIAL(c) || c == K_SPECIAL) { if (IS_SPECIAL(c) || c == K_SPECIAL) {
tb[j++] = K_SPECIAL; tb[j++] = K_SPECIAL;
tb[j++] = K_SECOND(c); tb[j++] = (char_u)K_SECOND(c);
tb[j++] = K_THIRD(c); tb[j++] = (char_u)K_THIRD(c);
} else { } else {
if (c < ABBR_OFF && (c < ' ' || c > '~')) if (c < ABBR_OFF && (c < ' ' || c > '~'))
tb[j++] = Ctrl_V; /* special char needs CTRL-V */ tb[j++] = Ctrl_V; /* special char needs CTRL-V */
@@ -3661,8 +3666,9 @@ int check_abbr(int c, char_u *ptr, int col, int mincol)
if (c >= ABBR_OFF) if (c >= ABBR_OFF)
c -= ABBR_OFF; c -= ABBR_OFF;
j += (*mb_char2bytes)(c, tb + j); j += (*mb_char2bytes)(c, tb + j);
} else } else {
tb[j++] = c; tb[j++] = (char_u)c;
}
} }
tb[j] = NUL; tb[j] = NUL;
/* insert the last typed char */ /* insert the last typed char */