Enable -Wconversion: mark.c.

Refactoring summary:
- MB_STRNICMP: Inlined.
- MB_STRNCMP: Inlined.
This commit is contained in:
Eliseo Martínez
2015-02-12 13:49:02 +01:00
committed by Justin M. Keyes
parent 690e43b461
commit 7dd48d7af0
14 changed files with 53 additions and 39 deletions

View File

@@ -65,7 +65,6 @@ set(CONV_SOURCES
if_cscope.c if_cscope.c
indent.c indent.c
keymap.c keymap.c
mark.c
mbyte.c mbyte.c
memline.c memline.c
menu.c menu.c

View File

@@ -1582,7 +1582,7 @@ static int diff_cmp(char_u *s1, char_u *s2)
} }
if ((diff_flags & DIFF_ICASE) && !(diff_flags & DIFF_IWHITE)) { 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. // Ignore white space changes and possibly ignore case.

View File

@@ -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) for (s = line + curwin->w_cursor.col; s > line; --s)
if (!vim_iswordc(s[-1])) if (!vim_iswordc(s[-1]))
break; break;
assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
if (s + (p - look) <= line + curwin->w_cursor.col if (s + (p - look) <= line + curwin->w_cursor.col
&& (icase && (icase
? MB_STRNICMP(s, look, p - look) ? mb_strnicmp(s, look, (size_t)(p - look))
: STRNCMP(s, look, p - look)) == 0) : STRNCMP(s, look, p - look)) == 0)
match = TRUE; match = TRUE;
} else } else
@@ -6605,10 +6606,11 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
&& TOLOWER_LOC(keytyped) == && TOLOWER_LOC(keytyped) ==
TOLOWER_LOC((int)p[-1]))) { TOLOWER_LOC((int)p[-1]))) {
line = get_cursor_pos_ptr(); line = get_cursor_pos_ptr();
assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
if ((curwin->w_cursor.col == (colnr_T)(p - look) if ((curwin->w_cursor.col == (colnr_T)(p - look)
|| !vim_iswordc(line[-(p - look) - 1])) || !vim_iswordc(line[-(p - look) - 1]))
&& (icase && (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)) : STRNCMP(line - (p - look), look, p - look))
== 0) == 0)
match = TRUE; match = TRUE;

View File

@@ -3615,7 +3615,7 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
s1 = get_tv_string_buf(rettv, buf1); s1 = get_tv_string_buf(rettv, buf1);
s2 = get_tv_string_buf(&var2, buf2); s2 = get_tv_string_buf(&var2, buf2);
if (type != TYPE_MATCH && type != TYPE_NOMATCH) 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 else
i = 0; i = 0;
n1 = FALSE; n1 = FALSE;
@@ -4955,7 +4955,7 @@ tv_equal (
case VAR_STRING: case VAR_STRING:
s1 = get_tv_string_buf(tv1, buf1); s1 = get_tv_string_buf(tv1, buf1);
s2 = get_tv_string_buf(tv2, buf2); 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()"); EMSG2(_(e_intern2), "tv_equal()");

View File

@@ -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) if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
return vim_strsave((char_u *)"-invalid-"); 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 */ /* Truncate the line to fit it in the window */
len = 0; 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) \ if (posp->lnum == lnum && posp->col >= mincol) \
{ \ { \
posp->lnum += lnum_amount; \ posp->lnum += lnum_amount; \
assert(col_amount > INT_MIN && col_amount <= INT_MAX); \
if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \ if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
posp->col = 0; \ posp->col = 0; \
else \ 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, ", "); copy_option_part(&p, part, 51, ", ");
if (part[0] == 'r') { if (part[0] == 'r') {
n = STRLEN(part + 1); n = STRLEN(part + 1);
if (MB_STRNICMP(part + 1, name, n) == 0) { if (mb_strnicmp(part + 1, name, n) == 0) {
retval = TRUE; retval = TRUE;
break; 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 (load_marks) {
if (line[1] != NUL) { if (line[1] != NUL) {
int64_t lnum_64; int64_t lnum_64;
unsigned u; unsigned int u;
sscanf((char *)line + 2, "%" SCNd64 "%u", &lnum_64, &u); sscanf((char *)line + 2, "%" SCNd64 "%u", &lnum_64, &u);
// safely downcast to linenr_T (long); remove when linenr_T refactored // safely downcast to linenr_T (long); remove when linenr_T refactored
assert(lnum_64 <= LONG_MAX); assert(lnum_64 <= LONG_MAX);
pos.lnum = (linenr_T)lnum_64; pos.lnum = (linenr_T)lnum_64;
pos.col = u; assert(u <= INT_MAX);
pos.col = (colnr_T)u;
switch (line[1]) { switch (line[1]) {
case '"': curbuf->b_last_cursor = pos; break; case '"': curbuf->b_last_cursor = pos; break;
case '^': curbuf->b_last_insert = pos; break; case '^': curbuf->b_last_insert = pos; break;

View File

@@ -2839,6 +2839,16 @@ int mb_strnicmp(char_u *s1, char_u *s2, size_t nn)
return 0; 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 * "g8": show bytes of the UTF-8 char under the cursor. Doesn't matter what
* 'encoding' has been set to. * 'encoding' has been set to.

View File

@@ -297,7 +297,7 @@ int vim_fnamecmp(char_u *x, char_u *y)
return vim_fnamencmp(x, y, MAXPATHL); return vim_fnamencmp(x, y, MAXPATHL);
#else #else
if (p_fic) if (p_fic)
return MB_STRICMP(x, y); return mb_stricmp(x, y);
return STRCMP(x, y); return STRCMP(x, y);
#endif #endif
} }
@@ -327,7 +327,7 @@ int vim_fnamencmp(char_u *x, char_u *y, size_t len)
return cx - cy; return cx - cy;
#else #else
if (p_fic) if (p_fic)
return MB_STRNICMP(x, y, len); return mb_strnicmp(x, y, len);
return STRNCMP(x, y, len); return STRNCMP(x, y, len);
#endif #endif
} }

View File

@@ -4,8 +4,8 @@
typedef long linenr_T; // line number type typedef long linenr_T; // line number type
typedef int colnr_T; // column number type typedef int colnr_T; // column number type
#define MAXLNUM (0x7fffffffL) // maximum (invalid) line number #define MAXLNUM 0x7fffffff // maximum (invalid) line number
#define MAXCOL (0x7fffffffL) // maximum column number, 31 bits #define MAXCOL 0x7fffffff // maximum column number, 31 bits
/* /*
* position in file or buffer * position in file or buffer

View File

@@ -6226,8 +6226,10 @@ static int cstrncmp(char_u *s1, char_u *s2, int *n)
if (!ireg_ic) if (!ireg_ic)
result = STRNCMP(s1, s2, *n); result = STRNCMP(s1, s2, *n);
else else {
result = MB_STRNICMP(s1, s2, *n); assert(*n >= 0);
result = mb_strnicmp(s1, s2, (size_t)*n);
}
/* if it failed and it's utf8 and we want to combineignore: */ /* if it failed and it's utf8 and we want to combineignore: */
if (result != 0 && enc_utf8 && ireg_icombine) { if (result != 0 && enc_utf8 && ireg_icombine) {

View File

@@ -9,6 +9,7 @@
* search.c: code for normal mode searching commands * search.c: code for normal mode searching commands
*/ */
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.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 */ * ignored because we are interested in the next line -- Acevedo */
if ((compl_cont_status & CONT_ADDING) if ((compl_cont_status & CONT_ADDING)
&& !(compl_cont_status & CONT_SOL)) { && !(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; return OK;
} else if (*p != NUL) { /* ignore empty lines */ } else if (*p != NUL) { /* ignore empty lines */
/* expanding lines or words */ /* 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) : STRNCMP(p, pat, compl_length)) == 0)
return OK; return OK;
} }
@@ -4234,8 +4236,10 @@ search_line:
) { ) {
/* compare the first "len" chars from "ptr" */ /* compare the first "len" chars from "ptr" */
startp = skipwhite(p); startp = skipwhite(p);
if (p_ic) if (p_ic) {
matched = !MB_STRNICMP(startp, ptr, len); assert(len >= 0);
matched = !mb_strnicmp(startp, ptr, (size_t)len);
}
else else
matched = !STRNCMP(startp, ptr, len); matched = !STRNCMP(startp, ptr, len);
if (matched && define_matched && whole if (matched && define_matched && whole

View File

@@ -13082,8 +13082,9 @@ spell_dump_compl (
// proper case later. This isn't exactly right when // proper case later. This isn't exactly right when
// length changes for multi-byte characters with // length changes for multi-byte characters with
// ignore case... // ignore case...
assert(depth >= 0);
if (depth <= patlen if (depth <= patlen
&& MB_STRNICMP(word, pat, depth) != 0) && mb_strnicmp(word, pat, (size_t)depth) != 0)
--depth; --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); ml_append(lnum, p, (colnr_T)0, FALSE);
} else if (((dumpflags & DUMPFLAG_ICASE) } 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) : STRNCMP(p, pat, STRLEN(pat)) == 0)
&& ins_compl_add_infercase(p, (int)STRLEN(p), && ins_compl_add_infercase(p, (int)STRLEN(p),
p_ic, NULL, *dir, 0) == OK) p_ic, NULL, *dir, 0) == OK)

View File

@@ -1391,7 +1391,7 @@ static int syn_stack_equal(synstate_T *sp)
|| six->matches[j] == NULL) || six->matches[j] == NULL)
break; break;
if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic 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 six->matches[j]) != 0
: STRCMP(bsx->matches[j], six->matches[j]) != 0) : STRCMP(bsx->matches[j], six->matches[j]) != 0)
break; break;

View File

@@ -1641,7 +1641,8 @@ parse_line:
/* No match yet and are at the end of the binary search. */ /* No match yet and are at the end of the binary search. */
break; break;
} else if (state == TS_SKIP_BACK) { } 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; state = TS_STEP_FORWARD;
else else
/* Have to skip back more. Restore the curr_offset /* Have to skip back more. Restore the curr_offset
@@ -1649,7 +1650,8 @@ parse_line:
search_info.curr_offset = search_info.curr_offset_used; search_info.curr_offset = search_info.curr_offset_used;
continue; continue;
} else if (state == TS_STEP_FORWARD) { } 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) if ((off_t)ftell(fp) > search_info.match_offset)
break; /* past last match */ break; /* past last match */
else else
@@ -1657,7 +1659,8 @@ parse_line:
} }
} else } else
/* skip this match if it can't match */ /* 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; continue;
/* /*
@@ -1691,7 +1694,8 @@ parse_line:
match = FALSE; match = FALSE;
else { else {
if (orgpat.regmatch.rm_ic) { 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) if (match)
match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat, match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat,
cmplen) == 0); cmplen) == 0);

View File

@@ -290,17 +290,6 @@ enum {
# endif # endif
#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 STRCAT(d, s) strcat((char *)(d), (char *)(s))
#define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n)) #define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n))