Enable -Wconversion: ui.c.

Refactoring summary:
- ui_write(): len: int --> size_t
    * parse_abstract_ui_codes(): len: int --> size_t
    * string_convert(): lenp: int * --> size_t *
        - string_convert_ext(): lenp      : int * --> size_t *
                                unconvlenp: int * --> size_t *
            * utf8len_tab_zero: char[] --> uint8_t[]
            * iconv_string(): slen      : int --> size_t
                              unconvlenp: int * --> size_t *
                              resultlenp: int * --> size_t *
        - mch_print_text_out(): len: int --> size_t
    * out_pos: int --> size_t
This commit is contained in:
Eliseo Martínez 2015-02-11 18:26:48 +01:00 committed by Justin M. Keyes
parent 366662d932
commit 7a7c933b86
8 changed files with 37 additions and 39 deletions

View File

@ -84,7 +84,6 @@ set(CONV_SOURCES
spell.c spell.c
syntax.c syntax.c
tag.c tag.c
ui.c
window.c) window.c)
foreach(sfile ${CONV_SOURCES}) foreach(sfile ${CONV_SOURCES})

View File

@ -578,7 +578,7 @@ Array vim_get_api_info(uint64_t channel_id)
/// `emsg` instead of `msg` to print each line) /// `emsg` instead of `msg` to print each line)
static void write_msg(String message, bool to_err) static void write_msg(String message, bool to_err)
{ {
static int out_pos = 0, err_pos = 0; static size_t out_pos = 0, err_pos = 0;
static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE]; static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE];
#define PUSH_CHAR(i, pos, line_buf, msg) \ #define PUSH_CHAR(i, pos, line_buf, msg) \

View File

@ -1532,7 +1532,9 @@ static int getexactdigraph(int char1, int char2, int meta_char)
if (convert_setup(&vc, (char_u *)"utf-8", p_enc) == OK) { if (convert_setup(&vc, (char_u *)"utf-8", p_enc) == OK) {
vc.vc_fail = true; vc.vc_fail = true;
to = string_convert(&vc, buf, &i); assert(i >= 0);
size_t len = (size_t)i;
to = string_convert(&vc, buf, &len);
if (to != NULL) { if (to != NULL) {
retval = (*mb_ptr2char)(to); retval = (*mb_ptr2char)(to);

View File

@ -5257,8 +5257,7 @@ void fix_help_buffer(void)
else { else {
/* Do the conversion. If it fails /* Do the conversion. If it fails
* use the unconverted text. */ * use the unconverted text. */
cp = string_convert(&vc, IObuff, cp = string_convert(&vc, IObuff, NULL);
NULL);
if (cp == NULL) if (cp == NULL)
cp = IObuff; cp = IObuff;
} }

View File

@ -96,7 +96,7 @@
* Sets the current position at the start of line "page_line". * Sets the current position at the start of line "page_line".
* If margin is TRUE start in the left margin (for header and line number). * If margin is TRUE start in the left margin (for header and line number).
* *
* int mch_print_text_out(char_u *p, int len); * int mch_print_text_out(char_u *p, size_t len);
* Output one character of text p[len] at the current position. * Output one character of text p[len] at the current position.
* Return TRUE if there is no room for another character in the same line. * Return TRUE if there is no room for another character in the same line.
* *
@ -495,7 +495,6 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum)
int page_line; int page_line;
char_u *tbuf; char_u *tbuf;
char_u *p; char_u *p;
int l;
/* Also use the space for the line number. */ /* Also use the space for the line number. */
if (prt_use_number()) if (prt_use_number())
@ -542,9 +541,9 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum)
page_line = 0 - prt_header_height(); page_line = 0 - prt_header_height();
mch_print_start_line(TRUE, page_line); mch_print_start_line(TRUE, page_line);
for (p = tbuf; *p != NUL; ) { for (p = tbuf; *p != NUL; ) {
if (mch_print_text_out(p, int l = (*mb_ptr2len)(p);
(l = (*mb_ptr2len)(p)) assert(l >= 0);
)) { if (mch_print_text_out(p, (size_t)l)) {
++page_line; ++page_line;
if (page_line >= 0) /* out of room in header */ if (page_line >= 0) /* out of room in header */
break; break;
@ -884,7 +883,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
ppos->ff = TRUE; ppos->ff = TRUE;
need_break = 1; need_break = 1;
} else { } else {
need_break = mch_print_text_out(line + col, outputlen); need_break = mch_print_text_out(line + col, (size_t)outputlen);
if (has_mbyte) if (has_mbyte)
print_pos += (*mb_ptr2cells)(line + col); print_pos += (*mb_ptr2cells)(line + col);
else else
@ -2871,7 +2870,7 @@ void mch_print_start_line(int margin, int page_line)
prt_half_width = FALSE; prt_half_width = FALSE;
} }
int mch_print_text_out(char_u *p, int len) int mch_print_text_out(char_u *p, size_t len)
{ {
int need_break; int need_break;
char_u ch; char_u ch;

View File

@ -143,7 +143,7 @@ static char utf8len_tab[256] =
/* /*
* Like utf8len_tab above, but using a zero for illegal lead bytes. * Like utf8len_tab above, but using a zero for illegal lead bytes.
*/ */
static char utf8len_tab_zero[256] = static uint8_t utf8len_tab_zero[256] =
{ {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
@ -1375,7 +1375,7 @@ static int dbcs_ptr2char(const char_u *p)
*/ */
int utf_ptr2char(const char_u *p) int utf_ptr2char(const char_u *p)
{ {
int len; uint8_t len;
if (p[0] < 0x80) /* be quick for ASCII */ if (p[0] < 0x80) /* be quick for ASCII */
return p[0]; return p[0];
@ -1427,12 +1427,12 @@ int utf_ptr2char(const char_u *p)
*/ */
static int utf_safe_read_char_adv(char_u **s, size_t *n) static int utf_safe_read_char_adv(char_u **s, size_t *n)
{ {
int c, k; int c;
if (*n == 0) /* end of buffer */ if (*n == 0) /* end of buffer */
return 0; return 0;
k = utf8len_tab_zero[**s]; uint8_t k = utf8len_tab_zero[**s];
if (k == 1) { if (k == 1) {
/* ASCII character or NUL */ /* ASCII character or NUL */
@ -1440,7 +1440,7 @@ static int utf_safe_read_char_adv(char_u **s, size_t *n)
return *(*s)++; return *(*s)++;
} }
if ((size_t)k <= *n) { if (k <= *n) {
/* We have a multibyte sequence and it isn't truncated by buffer /* We have a multibyte sequence and it isn't truncated by buffer
* limits so utf_ptr2char() is safe to use. Or the first byte is * limits so utf_ptr2char() is safe to use. Or the first byte is
* illegal (k=0), and it's also safe to use utf_ptr2char(). */ * illegal (k=0), and it's also safe to use utf_ptr2char(). */
@ -3504,7 +3504,8 @@ void * my_iconv_open(char_u *to, char_u *from)
* Returns the converted string in allocated memory. NULL for an error. * Returns the converted string in allocated memory. NULL for an error.
* If resultlenp is not NULL, sets it to the result length in bytes. * If resultlenp is not NULL, sets it to the result length in bytes.
*/ */
static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvlenp, int *resultlenp) static char_u * iconv_string(vimconv_T *vcp, char_u *str, size_t slen,
size_t *unconvlenp, size_t *resultlenp)
{ {
const char *from; const char *from;
size_t fromlen; size_t fromlen;
@ -3534,8 +3535,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
tolen = len - done - 2; tolen = len - done - 2;
/* Avoid a warning for systems with a wrong iconv() prototype by /* Avoid a warning for systems with a wrong iconv() prototype by
* casting the second argument to void *. */ * casting the second argument to void *. */
if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen) if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen) != SIZE_MAX) {
!= (size_t)-1) {
/* Finished, append a NUL. */ /* Finished, append a NUL. */
*to = NUL; *to = NUL;
break; break;
@ -3547,7 +3547,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
&& (ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) { && (ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) {
/* Handle an incomplete sequence at the end. */ /* Handle an incomplete sequence at the end. */
*to = NUL; *to = NUL;
*unconvlenp = (int)fromlen; *unconvlenp = fromlen;
break; break;
} }
/* Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded /* Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded
@ -3581,7 +3581,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
} }
if (resultlenp != NULL && result != NULL) if (resultlenp != NULL && result != NULL)
*resultlenp = (int)(to - (char *)result); *resultlenp = (size_t)(to - (char *)result);
return result; return result;
} }
@ -3802,7 +3802,7 @@ int convert_setup_ext(vimconv_T *vcp, char_u *from, bool from_unicode_is_utf8,
* Illegal chars are often changed to "?", unless vcp->vc_fail is set. * Illegal chars are often changed to "?", unless vcp->vc_fail is set.
* When something goes wrong, NULL is returned and "*lenp" is unchanged. * When something goes wrong, NULL is returned and "*lenp" is unchanged.
*/ */
char_u * string_convert(vimconv_T *vcp, char_u *ptr, int *lenp) char_u * string_convert(vimconv_T *vcp, char_u *ptr, size_t *lenp)
{ {
return string_convert_ext(vcp, ptr, lenp, NULL); return string_convert_ext(vcp, ptr, lenp, NULL);
} }
@ -3812,18 +3812,17 @@ char_u * string_convert(vimconv_T *vcp, char_u *ptr, int *lenp)
* an incomplete sequence at the end it is not converted and "*unconvlenp" is * an incomplete sequence at the end it is not converted and "*unconvlenp" is
* set to the number of remaining bytes. * set to the number of remaining bytes.
*/ */
char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr,
int *unconvlenp) size_t *lenp, size_t *unconvlenp)
{ {
char_u *retval = NULL; char_u *retval = NULL;
char_u *d; char_u *d;
int len;
int i;
int l; int l;
int c; int c;
size_t len;
if (lenp == NULL) if (lenp == NULL)
len = (int)STRLEN(ptr); len = STRLEN(ptr);
else else
len = *lenp; len = *lenp;
if (len == 0) if (len == 0)
@ -3833,7 +3832,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
case CONV_TO_UTF8: /* latin1 to utf-8 conversion */ case CONV_TO_UTF8: /* latin1 to utf-8 conversion */
retval = xmalloc(len * 2 + 1); retval = xmalloc(len * 2 + 1);
d = retval; d = retval;
for (i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
c = ptr[i]; c = ptr[i];
if (c < 0x80) if (c < 0x80)
*d++ = c; *d++ = c;
@ -3844,13 +3843,13 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
} }
*d = NUL; *d = NUL;
if (lenp != NULL) if (lenp != NULL)
*lenp = (int)(d - retval); *lenp = (size_t)(d - retval);
break; break;
case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */ case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */
retval = xmalloc(len * 3 + 1); retval = xmalloc(len * 3 + 1);
d = retval; d = retval;
for (i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
c = ptr[i]; c = ptr[i];
switch (c) { switch (c) {
case 0xa4: c = 0x20ac; break; /* euro */ case 0xa4: c = 0x20ac; break; /* euro */
@ -3866,19 +3865,19 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
} }
*d = NUL; *d = NUL;
if (lenp != NULL) if (lenp != NULL)
*lenp = (int)(d - retval); *lenp = (size_t)(d - retval);
break; break;
case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */ case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */
case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */ case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */
retval = xmalloc(len + 1); retval = xmalloc(len + 1);
d = retval; d = retval;
for (i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
l = utf_ptr2len_len(ptr + i, len - i); l = utf_ptr2len_len(ptr + i, len - i);
if (l == 0) if (l == 0)
*d++ = NUL; *d++ = NUL;
else if (l == 1) { else if (l == 1) {
int l_w = utf8len_tab_zero[ptr[i]]; uint8_t l_w = utf8len_tab_zero[ptr[i]];
if (l_w == 0) { if (l_w == 0) {
/* Illegal utf-8 byte cannot be converted */ /* Illegal utf-8 byte cannot be converted */
@ -3929,7 +3928,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
} }
*d = NUL; *d = NUL;
if (lenp != NULL) if (lenp != NULL)
*lenp = (int)(d - retval); *lenp = (size_t)(d - retval);
break; break;
# ifdef MACOS_CONVERT # ifdef MACOS_CONVERT

View File

@ -545,7 +545,7 @@ void termcapinit(char_u *name)
# define OUT_SIZE 2047 # define OUT_SIZE 2047
// Add one to allow term_write() in os_win32.c to append a NUL // Add one to allow term_write() in os_win32.c to append a NUL
static char_u out_buf[OUT_SIZE + 1]; static char_u out_buf[OUT_SIZE + 1];
static int out_pos = 0; /* number of chars in out_buf */ static size_t out_pos = 0; /* number of chars in out_buf */
// Clear the output buffer // Clear the output buffer
void out_buf_clear(void) void out_buf_clear(void)
@ -558,7 +558,7 @@ void out_buf_clear(void)
*/ */
void out_flush(void) void out_flush(void)
{ {
int len = out_pos; size_t len = out_pos;
out_pos = 0; out_pos = 0;
ui_write(out_buf, len); ui_write(out_buf, len);
} }

View File

@ -95,7 +95,7 @@ void ui_builtin_stop(void)
UI_CALL(stop); UI_CALL(stop);
} }
void ui_write(uint8_t *s, int len) void ui_write(uint8_t *s, size_t len)
{ {
if (silent_mode && !p_verbose) { if (silent_mode && !p_verbose) {
// Don't output anything in silent mode ("ex -s") unless 'verbose' set // Don't output anything in silent mode ("ex -s") unless 'verbose' set
@ -346,7 +346,7 @@ end:
UI_CALL(highlight_set, (ui->rgb ? rgb_attrs : cterm_attrs)); UI_CALL(highlight_set, (ui->rgb ? rgb_attrs : cterm_attrs));
} }
static void parse_abstract_ui_codes(uint8_t *ptr, int len) static void parse_abstract_ui_codes(uint8_t *ptr, size_t len)
{ {
if (!ui_active()) { if (!ui_active()) {
return; return;