mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 22:38:16 +00:00
Enable -Wconversion: mark.c.
Refactoring summary: - MB_STRNICMP: Inlined. - MB_STRNCMP: Inlined.
This commit is contained in:

committed by
Justin M. Keyes

parent
690e43b461
commit
7dd48d7af0
@@ -65,7 +65,6 @@ set(CONV_SOURCES
|
||||
if_cscope.c
|
||||
indent.c
|
||||
keymap.c
|
||||
mark.c
|
||||
mbyte.c
|
||||
memline.c
|
||||
menu.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.
|
||||
|
@@ -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;
|
||||
|
@@ -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()");
|
||||
|
@@ -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;
|
||||
|
@@ -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.
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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) {
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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))
|
||||
|
||||
|
Reference in New Issue
Block a user