aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-02-18 20:54:15 -0500
committerJustin M. Keyes <justinkz@gmail.com>2015-02-18 20:54:15 -0500
commitb1d079c83b3dd459114d1ba7c2ff1b07a9ee3e9e (patch)
treee80358ae4795597680b45fe984dc5f2e9ce20237
parent366662d932551e558d10f09887ddf144ed5db34b (diff)
parent36340803afe1504f15468a715172c25cfef6974c (diff)
downloadrneovim-b1d079c83b3dd459114d1ba7c2ff1b07a9ee3e9e.tar.gz
rneovim-b1d079c83b3dd459114d1ba7c2ff1b07a9ee3e9e.tar.bz2
rneovim-b1d079c83b3dd459114d1ba7c2ff1b07a9ee3e9e.zip
Merge #1979 'Enable -Wconversion'
-rwxr-xr-xclint.py2
-rw-r--r--src/nvim/CMakeLists.txt5
-rw-r--r--src/nvim/api/vim.c2
-rw-r--r--src/nvim/diff.c2
-rw-r--r--src/nvim/digraph.c4
-rw-r--r--src/nvim/edit.c6
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/ex_cmds.c3
-rw-r--r--src/nvim/fileio.c43
-rw-r--r--src/nvim/hardcopy.c13
-rw-r--r--src/nvim/indent.c12
-rw-r--r--src/nvim/keymap.c22
-rw-r--r--src/nvim/mark.c13
-rw-r--r--src/nvim/mbyte.c77
-rw-r--r--src/nvim/option.c6
-rw-r--r--src/nvim/os_unix.c11
-rw-r--r--src/nvim/path.c14
-rw-r--r--src/nvim/pos.h4
-rw-r--r--src/nvim/regexp.c6
-rw-r--r--src/nvim/search.c12
-rw-r--r--src/nvim/spell.c5
-rw-r--r--src/nvim/syntax.c2
-rw-r--r--src/nvim/tag.c12
-rw-r--r--src/nvim/term.c8
-rw-r--r--src/nvim/ui.c4
-rw-r--r--src/nvim/vim.h11
26 files changed, 117 insertions, 186 deletions
diff --git a/clint.py b/clint.py
index 5e0e5a1e2b..290abd2820 100755
--- a/clint.py
+++ b/clint.py
@@ -2776,7 +2776,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
# TODO(unknown): figure out if they're using default arguments in fn proto.
# Check if people are using the verboten C basic types.
- match = Search(r'\b(short|long(?! +double)|long long)\b', line)
+ match = Search(r'\b(short|long long)\b', line)
if match:
error(filename, linenum, 'runtime/int', 4,
'Use int16_t/int64_t/etc, rather than the C type %s'
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 922b8b85a1..1c2dad6094 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -63,9 +63,6 @@ set(CONV_SOURCES
fold.c
getchar.c
if_cscope.c
- indent.c
- keymap.c
- mark.c
mbyte.c
memline.c
menu.c
@@ -74,7 +71,6 @@ set(CONV_SOURCES
move.c
normal.c
ops.c
- os_unix.c
path.c
popupmnu.c
quickfix.c
@@ -84,7 +80,6 @@ set(CONV_SOURCES
spell.c
syntax.c
tag.c
- ui.c
window.c)
foreach(sfile ${CONV_SOURCES})
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index e3f426719e..33020c5b8c 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -578,7 +578,7 @@ Array vim_get_api_info(uint64_t channel_id)
/// `emsg` instead of `msg` to print each line)
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];
#define PUSH_CHAR(i, pos, line_buf, msg) \
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 35c00c4f23..63b0eaf4f6 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -1582,7 +1582,7 @@ static int diff_cmp(char_u *s1, char_u *s2)
}
if ((diff_flags & DIFF_ICASE) && !(diff_flags & DIFF_IWHITE)) {
- return MB_STRICMP(s1, s2);
+ return mb_stricmp(s1, s2);
}
// Ignore white space changes and possibly ignore case.
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index 243468b680..cb6bfc9cc9 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -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) {
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) {
retval = (*mb_ptr2char)(to);
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index fa4e4b2835..7913a37d2c 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -6594,9 +6594,10 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
for (s = line + curwin->w_cursor.col; s > line; --s)
if (!vim_iswordc(s[-1]))
break;
+ assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
if (s + (p - look) <= line + curwin->w_cursor.col
&& (icase
- ? MB_STRNICMP(s, look, p - look)
+ ? mb_strnicmp(s, look, (size_t)(p - look))
: STRNCMP(s, look, p - look)) == 0)
match = TRUE;
} else
@@ -6605,10 +6606,11 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
&& TOLOWER_LOC(keytyped) ==
TOLOWER_LOC((int)p[-1]))) {
line = get_cursor_pos_ptr();
+ assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
if ((curwin->w_cursor.col == (colnr_T)(p - look)
|| !vim_iswordc(line[-(p - look) - 1]))
&& (icase
- ? MB_STRNICMP(line - (p - look), look, p - look)
+ ? mb_strnicmp(line - (p - look), look, (size_t)(p - look))
: STRNCMP(line - (p - look), look, p - look))
== 0)
match = TRUE;
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 97993eb651..b06c0961c5 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -3615,7 +3615,7 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
s1 = get_tv_string_buf(rettv, buf1);
s2 = get_tv_string_buf(&var2, buf2);
if (type != TYPE_MATCH && type != TYPE_NOMATCH)
- i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2);
+ i = ic ? mb_stricmp(s1, s2) : STRCMP(s1, s2);
else
i = 0;
n1 = FALSE;
@@ -4955,7 +4955,7 @@ tv_equal (
case VAR_STRING:
s1 = get_tv_string_buf(tv1, buf1);
s2 = get_tv_string_buf(tv2, buf2);
- return (ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0;
+ return (ic ? mb_stricmp(s1, s2) : STRCMP(s1, s2)) == 0;
}
EMSG2(_(e_intern2), "tv_equal()");
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 49f33c5017..ad49153a1e 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -5257,8 +5257,7 @@ void fix_help_buffer(void)
else {
/* Do the conversion. If it fails
* use the unconverted text. */
- cp = string_convert(&vc, IObuff,
- NULL);
+ cp = string_convert(&vc, IObuff, NULL);
if (cp == NULL)
cp = IObuff;
}
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 762514a237..cd27567bd8 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -1235,7 +1235,6 @@ retry:
if (size <= 0)
break;
-
# ifdef USE_ICONV
if (iconv_fd != (iconv_t)-1) {
/*
@@ -1294,16 +1293,6 @@ retry:
}
# endif
-# ifdef MACOS_CONVERT
- if (fio_flags & FIO_MACROMAN) {
- /*
- * Conversion from Apple MacRoman char encoding to UTF-8 or
- * latin1. This is in os_mac_conv.c.
- */
- if (macroman2enc(ptr, &size, real_size) == FAIL)
- goto rewind_retry;
- } else
-# endif
if (fio_flags != 0) {
int u8c;
char_u *dest;
@@ -4029,38 +4018,6 @@ static int buf_write_bytes(struct bw_info *ip)
}
}
-
-# ifdef MACOS_CONVERT
- else if (flags & FIO_MACROMAN) {
- /*
- * Convert UTF-8 or latin1 to Apple MacRoman.
- */
- char_u *from;
- size_t fromlen;
-
- if (ip->bw_restlen > 0) {
- /* Need to concatenate the remainder of the previous call and
- * the bytes of the current call. Use the end of the
- * conversion buffer for this. */
- fromlen = len + ip->bw_restlen;
- from = ip->bw_conv_buf + ip->bw_conv_buflen - fromlen;
- memmove(from, ip->bw_rest, (size_t)ip->bw_restlen);
- memmove(from + ip->bw_restlen, buf, (size_t)len);
- } else {
- from = buf;
- fromlen = len;
- }
-
- if (enc2macroman(from, fromlen,
- ip->bw_conv_buf, &len, ip->bw_conv_buflen,
- ip->bw_rest, &ip->bw_restlen) == FAIL) {
- ip->bw_conv_error = TRUE;
- return FAIL;
- }
- buf = ip->bw_conv_buf;
- }
-# endif
-
# ifdef USE_ICONV
if (ip->bw_iconv_fd != (iconv_t)-1) {
const char *from;
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index 2dbe33d6e2..cc6aa57419 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -96,7 +96,7 @@
* 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).
*
- * 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.
* 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;
char_u *tbuf;
char_u *p;
- int l;
/* Also use the space for the line 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();
mch_print_start_line(TRUE, page_line);
for (p = tbuf; *p != NUL; ) {
- if (mch_print_text_out(p,
- (l = (*mb_ptr2len)(p))
- )) {
+ int l = (*mb_ptr2len)(p);
+ assert(l >= 0);
+ if (mch_print_text_out(p, (size_t)l)) {
++page_line;
if (page_line >= 0) /* out of room in header */
break;
@@ -884,7 +883,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
ppos->ff = TRUE;
need_break = 1;
} else {
- need_break = mch_print_text_out(line + col, outputlen);
+ need_break = mch_print_text_out(line + col, (size_t)outputlen);
if (has_mbyte)
print_pos += (*mb_ptr2cells)(line + col);
else
@@ -2871,7 +2870,7 @@ void mch_print_start_line(int margin, int page_line)
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;
char_u ch;
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 075acc6c13..5711207933 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -198,7 +199,8 @@ int set_indent(int size, int flags)
// characters and allocate accordingly. We will fill the rest with spaces
// after the if (!curbuf->b_p_et) below.
if (orig_char_len != -1) {
- newline = xmalloc(orig_char_len + size - ind_done + line_len);
+ assert(orig_char_len + size - ind_done + line_len >= 0);
+ newline = xmalloc((size_t)(orig_char_len + size - ind_done + line_len));
todo = size - ind_done;
// Set total length of indent in characters, which may have been
@@ -219,7 +221,8 @@ int set_indent(int size, int flags)
}
} else {
todo = size;
- newline = xmalloc(ind_len + line_len);
+ assert(ind_len + line_len >= 0);
+ newline = xmalloc((size_t)(ind_len + line_len));
s = newline;
}
@@ -384,7 +387,8 @@ int copy_indent(int size, char_u *src)
// Allocate memory for the result: the copied indent, new indent
// and the rest of the line.
line_len = (int)STRLEN(get_cursor_line_ptr()) + 1;
- line = xmalloc(ind_len + line_len);
+ assert(ind_len + line_len >= 0);
+ line = xmalloc((size_t)(ind_len + line_len));
p = line;
}
}
@@ -449,7 +453,7 @@ int get_number_indent(linenr_T lnum)
*/
int get_breakindent_win(win_T *wp, char_u *line) {
static int prev_indent = 0; /* cached indent value */
- static int prev_ts = 0L; /* cached tabstop value */
+ static long prev_ts = 0; /* cached tabstop value */
static char_u *prev_line = NULL; /* cached pointer to line */
static int prev_tick = 0; // changedtick of cached value
int bri = 0;
diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c
index 8d98a0a95d..67f342fd37 100644
--- a/src/nvim/keymap.c
+++ b/src/nvim/keymap.c
@@ -3,6 +3,7 @@
* special key codes.
*/
+#include <assert.h>
#include <inttypes.h>
#include "nvim/vim.h"
@@ -457,7 +458,7 @@ char_u *get_special_key_name(int c, int modifiers)
if (IS_SPECIAL(c)) {
string[idx++] = 't';
string[idx++] = '_';
- string[idx++] = KEY2TERMCAP0(c);
+ string[idx++] = (char_u)KEY2TERMCAP0(c);
string[idx++] = KEY2TERMCAP1(c);
}
/* Not a special key, only modifiers, output directly */
@@ -465,7 +466,7 @@ char_u *get_special_key_name(int c, int modifiers)
if (has_mbyte && (*mb_char2len)(c) > 1)
idx += (*mb_char2bytes)(c, string + idx);
else if (vim_isprintc(c))
- string[idx++] = c;
+ string[idx++] = (char_u)c;
else {
s = transchar(c);
while (*s)
@@ -496,7 +497,7 @@ trans_special (
{
int modifiers = 0;
int key;
- int dlen = 0;
+ unsigned int dlen = 0;
key = find_special_key(srcp, &modifiers, keycode, FALSE);
if (key == 0)
@@ -506,19 +507,22 @@ trans_special (
if (modifiers != 0) {
dst[dlen++] = K_SPECIAL;
dst[dlen++] = KS_MODIFIER;
- dst[dlen++] = modifiers;
+ dst[dlen++] = (char_u)modifiers;
}
if (IS_SPECIAL(key)) {
dst[dlen++] = K_SPECIAL;
- dst[dlen++] = KEY2TERMCAP0(key);
+ dst[dlen++] = (char_u)KEY2TERMCAP0(key);
dst[dlen++] = KEY2TERMCAP1(key);
} else if (has_mbyte && !keycode)
- dlen += (*mb_char2bytes)(key, dst + dlen);
- else if (keycode)
- dlen = (int)(add_char2buf(key, dst + dlen) - dst);
+ dlen += (unsigned int)(*mb_char2bytes)(key, dst + dlen);
+ else if (keycode) {
+ char_u *after = add_char2buf(key, dst + dlen);
+ assert(after >= dst && (uintmax_t)(after - dst) <= UINT_MAX);
+ dlen = (unsigned int)(after - dst);
+ }
else
- dst[dlen++] = key;
+ dst[dlen++] = (char_u)key;
return dlen;
}
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 5853b535cd..ddbe4e76cb 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -604,7 +604,8 @@ static char_u *mark_line(pos_T *mp, int lead_len)
if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
return vim_strsave((char_u *)"-invalid-");
- s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (int)Columns);
+ assert(Columns >= 0 && (size_t)Columns <= SIZE_MAX);
+ s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (size_t)Columns);
/* Truncate the line to fit it in the window */
len = 0;
@@ -1033,10 +1034,11 @@ void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
if (posp->lnum == lnum && posp->col >= mincol) \
{ \
posp->lnum += lnum_amount; \
+ assert(col_amount > INT_MIN && col_amount <= INT_MAX); \
if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
posp->col = 0; \
else \
- posp->col += col_amount; \
+ posp->col += (colnr_T)col_amount; \
} \
}
@@ -1329,7 +1331,7 @@ int removable(char_u *name)
copy_option_part(&p, part, 51, ", ");
if (part[0] == 'r') {
n = STRLEN(part + 1);
- if (MB_STRNICMP(part + 1, name, n) == 0) {
+ if (mb_strnicmp(part + 1, name, n) == 0) {
retval = TRUE;
break;
}
@@ -1499,12 +1501,13 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
if (load_marks) {
if (line[1] != NUL) {
int64_t lnum_64;
- unsigned u;
+ unsigned int u;
sscanf((char *)line + 2, "%" SCNd64 "%u", &lnum_64, &u);
// safely downcast to linenr_T (long); remove when linenr_T refactored
assert(lnum_64 <= LONG_MAX);
pos.lnum = (linenr_T)lnum_64;
- pos.col = u;
+ assert(u <= INT_MAX);
+ pos.col = (colnr_T)u;
switch (line[1]) {
case '"': curbuf->b_last_cursor = pos; break;
case '^': curbuf->b_last_insert = pos; break;
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index bc8f768724..5c89e9d8eb 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -143,7 +143,7 @@ static char utf8len_tab[256] =
/*
* 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,
@@ -1375,7 +1375,7 @@ static int dbcs_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 */
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)
{
- int c, k;
+ int c;
if (*n == 0) /* end of buffer */
return 0;
- k = utf8len_tab_zero[**s];
+ uint8_t k = utf8len_tab_zero[**s];
if (k == 1) {
/* ASCII character or NUL */
@@ -1440,7 +1440,7 @@ static int utf_safe_read_char_adv(char_u **s, size_t *n)
return *(*s)++;
}
- if ((size_t)k <= *n) {
+ if (k <= *n) {
/* 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
* illegal (k=0), and it's also safe to use utf_ptr2char(). */
@@ -2839,6 +2839,16 @@ int mb_strnicmp(char_u *s1, char_u *s2, size_t nn)
return 0;
}
+/* We need to call mb_stricmp() even when we aren't dealing with a multi-byte
+ * encoding because mb_stricmp() takes care of all ascii and non-ascii
+ * encodings, including characters with umlauts in latin1, etc., while
+ * STRICMP() only handles the system locale version, which often does not
+ * handle non-ascii properly. */
+int mb_stricmp(char_u *s1, char_u *s2)
+{
+ return mb_strnicmp(s1, s2, MAXCOL);
+}
+
/*
* "g8": show bytes of the UTF-8 char under the cursor. Doesn't matter what
* 'encoding' has been set to.
@@ -3504,7 +3514,8 @@ void * my_iconv_open(char_u *to, char_u *from)
* Returns the converted string in allocated memory. NULL for an error.
* 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;
size_t fromlen;
@@ -3534,8 +3545,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
tolen = len - done - 2;
/* Avoid a warning for systems with a wrong iconv() prototype by
* casting the second argument to void *. */
- if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen)
- != (size_t)-1) {
+ if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen) != SIZE_MAX) {
/* Finished, append a NUL. */
*to = NUL;
break;
@@ -3547,7 +3557,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
&& (ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) {
/* Handle an incomplete sequence at the end. */
*to = NUL;
- *unconvlenp = (int)fromlen;
+ *unconvlenp = fromlen;
break;
}
/* Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded
@@ -3581,7 +3591,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
}
if (resultlenp != NULL && result != NULL)
- *resultlenp = (int)(to - (char *)result);
+ *resultlenp = (size_t)(to - (char *)result);
return result;
}
@@ -3802,7 +3812,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.
* 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);
}
@@ -3812,18 +3822,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
* set to the number of remaining bytes.
*/
-char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
- int *unconvlenp)
+char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr,
+ size_t *lenp, size_t *unconvlenp)
{
char_u *retval = NULL;
char_u *d;
- int len;
- int i;
int l;
int c;
+ size_t len;
if (lenp == NULL)
- len = (int)STRLEN(ptr);
+ len = STRLEN(ptr);
else
len = *lenp;
if (len == 0)
@@ -3833,7 +3842,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
case CONV_TO_UTF8: /* latin1 to utf-8 conversion */
retval = xmalloc(len * 2 + 1);
d = retval;
- for (i = 0; i < len; ++i) {
+ for (size_t i = 0; i < len; ++i) {
c = ptr[i];
if (c < 0x80)
*d++ = c;
@@ -3844,13 +3853,13 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
}
*d = NUL;
if (lenp != NULL)
- *lenp = (int)(d - retval);
+ *lenp = (size_t)(d - retval);
break;
case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */
retval = xmalloc(len * 3 + 1);
d = retval;
- for (i = 0; i < len; ++i) {
+ for (size_t i = 0; i < len; ++i) {
c = ptr[i];
switch (c) {
case 0xa4: c = 0x20ac; break; /* euro */
@@ -3866,19 +3875,19 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
}
*d = NUL;
if (lenp != NULL)
- *lenp = (int)(d - retval);
+ *lenp = (size_t)(d - retval);
break;
case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */
case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */
retval = xmalloc(len + 1);
d = retval;
- for (i = 0; i < len; ++i) {
+ for (size_t i = 0; i < len; ++i) {
l = utf_ptr2len_len(ptr + i, len - i);
if (l == 0)
*d++ = NUL;
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) {
/* Illegal utf-8 byte cannot be converted */
@@ -3929,30 +3938,8 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp,
}
*d = NUL;
if (lenp != NULL)
- *lenp = (int)(d - retval);
- break;
-
-# ifdef MACOS_CONVERT
- case CONV_MAC_LATIN1:
- retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail,
- 'm', 'l', unconvlenp);
- break;
-
- case CONV_LATIN1_MAC:
- retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail,
- 'l', 'm', unconvlenp);
- break;
-
- case CONV_MAC_UTF8:
- retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail,
- 'm', 'u', unconvlenp);
- break;
-
- case CONV_UTF8_MAC:
- retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail,
- 'u', 'm', unconvlenp);
+ *lenp = (size_t)(d - retval);
break;
-# endif
# ifdef USE_ICONV
case CONV_ICONV: /* conversion with output_conv.vc_fd */
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 7242c2d925..bf7d0d0bf3 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -2059,12 +2059,6 @@ void set_init_1(void)
/* Parse default for 'fillchars'. */
(void)set_chars_option(&p_fcs);
-
-# ifdef MACOS_CONVERT
- /* Moved to os_mac_conv.c to avoid dependency problems. */
- mac_lang_init();
-# endif
-
/* enc_locale() will try to find the encoding of the current locale. */
p = enc_locale();
if (p != NULL) {
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index 455ed737ff..bfdf5969ff 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -415,10 +415,6 @@ void mch_exit(int r)
out_flush();
ml_close_all(TRUE); /* remove all memfiles */
-#ifdef MACOS_CONVERT
- mac_conv_cleanup();
-#endif
-
event_teardown();
#ifdef EXITFREE
@@ -734,7 +730,10 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
{
redraw_later_clear(); /* probably messed up screen */
msg_putchar('\n'); /* clear bottom line quickly */
- cmdline_row = Rows - 1; /* continue on last line */
+#if SIZEOF_LONG > SIZEOF_INT
+ assert(Rows <= (long)INT_MAX + 1);
+#endif
+ cmdline_row = (int)(Rows - 1); /* continue on last line */
MSG(_(e_wildexpand));
msg_start(); /* don't overwrite this message */
}
@@ -862,7 +861,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
goto notfound;
}
*num_file = i;
- *file = (char_u **)xmalloc(sizeof(char_u *) * i);
+ *file = xmalloc(sizeof(char_u *) * (size_t)i);
/*
* Isolate the individual file names.
diff --git a/src/nvim/path.c b/src/nvim/path.c
index e5f78440c2..93aa5eed3d 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -297,7 +297,7 @@ int vim_fnamecmp(char_u *x, char_u *y)
return vim_fnamencmp(x, y, MAXPATHL);
#else
if (p_fic)
- return MB_STRICMP(x, y);
+ return mb_stricmp(x, y);
return STRCMP(x, y);
#endif
}
@@ -327,7 +327,7 @@ int vim_fnamencmp(char_u *x, char_u *y, size_t len)
return cx - cy;
#else
if (p_fic)
- return MB_STRNICMP(x, y, len);
+ return mb_strnicmp(x, y, len);
return STRNCMP(x, y, len);
#endif
}
@@ -578,16 +578,6 @@ unix_expandpath (
if (*path_end != NUL)
backslash_halve(buf + len + 1);
if (os_file_exists(buf)) { /* add existing file */
-#ifdef MACOS_CONVERT
- size_t precomp_len = STRLEN(buf)+1;
- char_u *precomp_buf =
- mac_precompose_path(buf, precomp_len, &precomp_len);
-
- if (precomp_buf) {
- memmove(buf, precomp_buf, precomp_len);
- free(precomp_buf);
- }
-#endif
addfile(gap, buf, flags);
}
}
diff --git a/src/nvim/pos.h b/src/nvim/pos.h
index 7cfb52b283..7071df51e8 100644
--- a/src/nvim/pos.h
+++ b/src/nvim/pos.h
@@ -4,8 +4,8 @@
typedef long linenr_T; // line number type
typedef int colnr_T; // column number type
-#define MAXLNUM (0x7fffffffL) // maximum (invalid) line number
-#define MAXCOL (0x7fffffffL) // maximum column number, 31 bits
+#define MAXLNUM 0x7fffffff // maximum (invalid) line number
+#define MAXCOL 0x7fffffff // maximum column number, 31 bits
/*
* position in file or buffer
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 4af09915d5..8b7033b64b 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -6226,8 +6226,10 @@ static int cstrncmp(char_u *s1, char_u *s2, int *n)
if (!ireg_ic)
result = STRNCMP(s1, s2, *n);
- else
- result = MB_STRNICMP(s1, s2, *n);
+ else {
+ assert(*n >= 0);
+ result = mb_strnicmp(s1, s2, (size_t)*n);
+ }
/* if it failed and it's utf8 and we want to combineignore: */
if (result != 0 && enc_utf8 && ireg_icombine) {
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 055d2db445..095d7484a5 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -9,6 +9,7 @@
* search.c: code for normal mode searching commands
*/
+#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -1258,11 +1259,12 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat)
* ignored because we are interested in the next line -- Acevedo */
if ((compl_cont_status & CONT_ADDING)
&& !(compl_cont_status & CONT_SOL)) {
- if ((p_ic ? MB_STRICMP(p, pat) : STRCMP(p, pat)) == 0)
+ if ((p_ic ? mb_stricmp(p, pat) : STRCMP(p, pat)) == 0)
return OK;
} else if (*p != NUL) { /* ignore empty lines */
/* expanding lines or words */
- if ((p_ic ? MB_STRNICMP(p, pat, compl_length)
+ assert(compl_length >= 0);
+ if ((p_ic ? mb_strnicmp(p, pat, (size_t)compl_length)
: STRNCMP(p, pat, compl_length)) == 0)
return OK;
}
@@ -4234,8 +4236,10 @@ search_line:
) {
/* compare the first "len" chars from "ptr" */
startp = skipwhite(p);
- if (p_ic)
- matched = !MB_STRNICMP(startp, ptr, len);
+ if (p_ic) {
+ assert(len >= 0);
+ matched = !mb_strnicmp(startp, ptr, (size_t)len);
+ }
else
matched = !STRNCMP(startp, ptr, len);
if (matched && define_matched && whole
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index cbaa44d7eb..f66560f772 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -13082,8 +13082,9 @@ spell_dump_compl (
// proper case later. This isn't exactly right when
// length changes for multi-byte characters with
// ignore case...
+ assert(depth >= 0);
if (depth <= patlen
- && MB_STRNICMP(word, pat, depth) != 0)
+ && mb_strnicmp(word, pat, (size_t)depth) != 0)
--depth;
}
}
@@ -13154,7 +13155,7 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, int *dir, int d
ml_append(lnum, p, (colnr_T)0, FALSE);
} else if (((dumpflags & DUMPFLAG_ICASE)
- ? MB_STRNICMP(p, pat, STRLEN(pat)) == 0
+ ? mb_strnicmp(p, pat, STRLEN(pat)) == 0
: STRNCMP(p, pat, STRLEN(pat)) == 0)
&& ins_compl_add_infercase(p, (int)STRLEN(p),
p_ic, NULL, *dir, 0) == OK)
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 744a6c68fd..c94e6e437b 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -1391,7 +1391,7 @@ static int syn_stack_equal(synstate_T *sp)
|| six->matches[j] == NULL)
break;
if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic
- ? MB_STRICMP(bsx->matches[j],
+ ? mb_stricmp(bsx->matches[j],
six->matches[j]) != 0
: STRCMP(bsx->matches[j], six->matches[j]) != 0)
break;
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index bab594a27d..5c3d7cc30b 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -1641,7 +1641,8 @@ parse_line:
/* No match yet and are at the end of the binary search. */
break;
} else if (state == TS_SKIP_BACK) {
- if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0)
+ assert(cmplen >= 0);
+ if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0)
state = TS_STEP_FORWARD;
else
/* Have to skip back more. Restore the curr_offset
@@ -1649,7 +1650,8 @@ parse_line:
search_info.curr_offset = search_info.curr_offset_used;
continue;
} else if (state == TS_STEP_FORWARD) {
- if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0) {
+ assert(cmplen >= 0);
+ if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) {
if ((off_t)ftell(fp) > search_info.match_offset)
break; /* past last match */
else
@@ -1657,7 +1659,8 @@ parse_line:
}
} else
/* skip this match if it can't match */
- if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0)
+ assert(cmplen >= 0);
+ if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0)
continue;
/*
@@ -1691,7 +1694,8 @@ parse_line:
match = FALSE;
else {
if (orgpat.regmatch.rm_ic) {
- match = (MB_STRNICMP(tagp.tagname, orgpat.pat, cmplen) == 0);
+ assert(cmplen >= 0);
+ match = mb_strnicmp(tagp.tagname, orgpat.pat, (size_t)cmplen) == 0;
if (match)
match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat,
cmplen) == 0);
diff --git a/src/nvim/term.c b/src/nvim/term.c
index fa85860cb0..a16c1a59ca 100644
--- a/src/nvim/term.c
+++ b/src/nvim/term.c
@@ -161,10 +161,6 @@ void term_init(void)
setbuf(stdout, NULL);
out_flush();
-
-#ifdef MACOS_CONVERT
- mac_conv_init();
-#endif
}
/*
@@ -545,7 +541,7 @@ void termcapinit(char_u *name)
# define OUT_SIZE 2047
// Add one to allow term_write() in os_win32.c to append a NUL
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
void out_buf_clear(void)
@@ -558,7 +554,7 @@ void out_buf_clear(void)
*/
void out_flush(void)
{
- int len = out_pos;
+ size_t len = out_pos;
out_pos = 0;
ui_write(out_buf, len);
}
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index af8989f397..c09cca1347 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -95,7 +95,7 @@ void ui_builtin_stop(void)
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) {
// 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));
}
-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()) {
return;
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index be3f246ff4..5a89a3c861 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -290,17 +290,6 @@ enum {
# endif
#endif
-/* We need to call mb_stricmp() even when we aren't dealing with a multi-byte
- * encoding because mb_stricmp() takes care of all ascii and non-ascii
- * encodings, including characters with umlauts in latin1, etc., while
- * STRICMP() only handles the system locale version, which often does not
- * handle non-ascii properly. */
-
-# define MB_STRICMP(d, s) mb_strnicmp((char_u *)(d), (char_u *)(s), \
- (int)MAXCOL)
-# define MB_STRNICMP(d, s, n) mb_strnicmp((char_u *)(d), (char_u *)(s), \
- (int)(n))
-
#define STRCAT(d, s) strcat((char *)(d), (char *)(s))
#define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n))