aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliseo Martínez <eliseomarmol@gmail.com>2015-02-12 13:49:02 +0100
committerJustin M. Keyes <justinkz@gmail.com>2015-02-18 20:54:13 -0500
commit7dd48d7af08613255bc95b63f5b6b0f096a98d22 (patch)
treefb85ab05a011eb6bc23b771569e152410d966811
parent690e43b461491507094da8eeb48a92cf2f38b282 (diff)
downloadrneovim-7dd48d7af08613255bc95b63f5b6b0f096a98d22.tar.gz
rneovim-7dd48d7af08613255bc95b63f5b6b0f096a98d22.tar.bz2
rneovim-7dd48d7af08613255bc95b63f5b6b0f096a98d22.zip
Enable -Wconversion: mark.c.
Refactoring summary: - MB_STRNICMP: Inlined. - MB_STRNCMP: Inlined.
-rw-r--r--src/nvim/CMakeLists.txt1
-rw-r--r--src/nvim/diff.c2
-rw-r--r--src/nvim/edit.c6
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/mark.c13
-rw-r--r--src/nvim/mbyte.c10
-rw-r--r--src/nvim/path.c4
-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/vim.h11
14 files changed, 53 insertions, 39 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 99e0b215de..795997c052 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -65,7 +65,6 @@ set(CONV_SOURCES
if_cscope.c
indent.c
keymap.c
- mark.c
mbyte.c
memline.c
menu.c
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/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/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 123ef377e6..5c89e9d8eb 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -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.
diff --git a/src/nvim/path.c b/src/nvim/path.c
index abeb755482..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
}
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/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))