aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEliseo Martínez <eliseomarmol@gmail.com>2015-04-26 20:32:24 +0200
committerEliseo Martínez <eliseomarmol@gmail.com>2015-04-27 19:27:07 +0200
commit7c956dcbe8017dd68bf4221893bf554302b8fd90 (patch)
tree8c4fe902ae018d385f31a045d4e2338f3463c581 /src
parentd9441444afa3e99c8116ad01b11614886aa53524 (diff)
downloadrneovim-7c956dcbe8017dd68bf4221893bf554302b8fd90.tar.gz
rneovim-7c956dcbe8017dd68bf4221893bf554302b8fd90.tar.bz2
rneovim-7c956dcbe8017dd68bf4221893bf554302b8fd90.zip
Enable -Wconversion: normal.c.
Refactor summary: - extern int opcount --> extern long opcount - bool find_decl(..., int len, ...) --> bool find_decl(..., size_t len, ...) * int find_ident_under_cursor(...) --> size_t find_ident_under_cursor(...) - int find_ident_at_pos(...) --> size_t find_ident_at_pos(...) - int modify_fname(..., int *usedlen, ..., int *fnamelen) --> int modify_fname(..., size_t *usedlen, ..., size_t *fnamelen) * char_u *eval_vars(..., int *usedlen, ...) --> char_u *eval_vars(..., size_t *usedlen, ...) - int find_cmdline_var(..., int *usedlen) --> ssize_t find_cmdline_var(..., size_t *usedlen) - static char_u *repl_cmdline(..., int srclen, ...) --> static char_u *repl_cmdline(..., size_t srclen, ...) - bool get_visual_text(..., int *lenp) --> bool get_visual_text(..., size_t *lenp) * char_u *find_file_name_in_path(..., int len, ...) --> char_u *find_file_name_in_path(..., size_t len, ...) - static char_u *eval_includeexpr(..., int len) --> static char_u *eval_includeexpr(..., size_t len) - char_u *find_file_in_path(..., int len, ...) --> char_u *find_file_in_path(..., size_t len, ...) * char_u *find_file_in_path_option(..., int len, ...) --> char_u *find_file_in_path_option(..., size_t len, ...) - char_u *find_directory_in_path(..., int len, ...) --> char_u *find_directory_in_path(..., size_t len, ...) * int spell_move_to(...) --> size_t spell_move_to(...) - int spell_check(...) --> size_t spell_check(...) - static int spell_bad_len --> static size_t spell_bad_len - void find_pattern_in_path(..., int len, ...) --> void find_pattern_in_path(..., size_t len, ...) Helped-by: Justin M. Keyes <justinkz@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/CMakeLists.txt1
-rw-r--r--src/nvim/edit.c20
-rw-r--r--src/nvim/eval.c67
-rw-r--r--src/nvim/ex_docmd.c98
-rw-r--r--src/nvim/file_search.c14
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/if_cscope.c8
-rw-r--r--src/nvim/misc2.c4
-rw-r--r--src/nvim/normal.c162
-rw-r--r--src/nvim/ops.c7
-rw-r--r--src/nvim/os/env.c13
-rw-r--r--src/nvim/path.c24
-rw-r--r--src/nvim/screen.c10
-rw-r--r--src/nvim/search.c14
-rw-r--r--src/nvim/spell.c51
-rw-r--r--src/nvim/strings.c4
-rw-r--r--src/nvim/window.c21
17 files changed, 271 insertions, 249 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index dc44c9135d..31612c7f47 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -60,7 +60,6 @@ set(CONV_SOURCES
menu.c
message.c
misc1.c
- normal.c
ops.c
path.c
quickfix.c
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index d19f10f47f..413df3c036 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -192,7 +192,7 @@ static int compl_opt_refresh_always = FALSE;
#define BACKSPACE_WORD_NOT_SPACE 3
#define BACKSPACE_LINE 4
-static int spell_bad_len = 0; /* length of located bad word */
+static size_t spell_bad_len = 0; /* length of located bad word */
static colnr_T Insstart_textlen; /* length of line when insert started */
static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
@@ -3539,11 +3539,12 @@ static int ins_compl_get_exp(pos_T *ini)
case CTRL_X_PATH_PATTERNS:
case CTRL_X_PATH_DEFINES:
find_pattern_in_path(compl_pattern, compl_direction,
- (int)STRLEN(compl_pattern), FALSE, FALSE,
- (type == CTRL_X_PATH_DEFINES
- && !(compl_cont_status & CONT_SOL))
- ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
- (linenr_T)1, (linenr_T)MAXLNUM);
+ STRLEN(compl_pattern), FALSE, FALSE,
+ ((type == CTRL_X_PATH_DEFINES
+ && !(compl_cont_status & CONT_SOL))
+ ? FIND_DEFINE
+ : FIND_ANY),
+ 1L, ACTION_EXPAND, 1, MAXLNUM);
break;
case CTRL_X_DICTIONARY:
@@ -4401,8 +4402,10 @@ static int ins_complete(int c)
compl_length = curs_col - compl_col;
compl_pattern = vim_strnsave(line + compl_col, compl_length);
} else if (ctrl_x_mode == CTRL_X_SPELL) {
- if (spell_bad_len > 0)
- compl_col = curs_col - spell_bad_len;
+ if (spell_bad_len > 0) {
+ assert(spell_bad_len <= INT_MAX);
+ compl_col = curs_col - (int)spell_bad_len;
+ }
else
compl_col = spell_word_start(startcol);
if (compl_col >= (colnr_T)startcol) {
@@ -5590,7 +5593,6 @@ static void check_spell_redraw(void)
static void spell_back_to_badword(void)
{
pos_T tpos = curwin->w_cursor;
-
spell_bad_len = spell_move_to(curwin, BACKWARD, TRUE, TRUE, NULL);
if (curwin->w_cursor.col != tpos.col)
start_arrow(&tpos);
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 7d9dc9ab51..3a8974bca1 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -8262,7 +8262,7 @@ static void f_exp(typval_T *argvars, typval_T *rettv)
static void f_expand(typval_T *argvars, typval_T *rettv)
{
char_u *s;
- int len;
+ size_t len;
char_u *errormsg;
int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
expand_T xpc;
@@ -8531,12 +8531,12 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what)
if (rettv->v_type == VAR_STRING || rettv->v_type == VAR_LIST)
xfree(fresult);
fresult = find_file_in_path_option(first ? fname : NULL,
- first ? (int)STRLEN(fname) : 0,
- 0, first, path,
- find_what,
- curbuf->b_ffname,
- find_what == FINDFILE_DIR
- ? (char_u *)"" : curbuf->b_p_sua);
+ first ? STRLEN(fname) : 0,
+ 0, first, path,
+ find_what, curbuf->b_ffname,
+ (find_what == FINDFILE_DIR
+ ? (char_u *)""
+ : curbuf->b_p_sua));
first = FALSE;
if (fresult != NULL && rettv->v_type == VAR_LIST)
@@ -8773,8 +8773,8 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv)
{
char_u *fname;
char_u *mods;
- int usedlen = 0;
- int len;
+ size_t usedlen = 0;
+ size_t len;
char_u *fbuf = NULL;
char_u buf[NUMBUFLEN];
@@ -8783,7 +8783,7 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv)
if (fname == NULL || mods == NULL)
fname = NULL;
else {
- len = (int)STRLEN(fname);
+ len = STRLEN(fname);
(void)modify_fname(mods, &usedlen, &fname, &fbuf, &len);
}
@@ -13017,19 +13017,18 @@ static void f_searchdecl(typval_T *argvars, typval_T *rettv)
int locally = 1;
int thisblock = 0;
int error = FALSE;
- char_u *name;
rettv->vval.v_number = 1; /* default: FAIL */
- name = get_tv_string_chk(&argvars[0]);
+ char_u *name = get_tv_string_chk(&argvars[0]);
if (argvars[1].v_type != VAR_UNKNOWN) {
locally = get_tv_number_chk(&argvars[1], &error) == 0;
if (!error && argvars[2].v_type != VAR_UNKNOWN)
thisblock = get_tv_number_chk(&argvars[2], &error) != 0;
}
if (!error && name != NULL)
- rettv->vval.v_number = find_decl(name, (int)STRLEN(name),
- locally, thisblock, SEARCH_KEEP) == FAIL;
+ rettv->vval.v_number = find_decl(name, STRLEN(name), locally,
+ thisblock, SEARCH_KEEP) == FAIL;
}
/*
@@ -14201,7 +14200,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv)
{
char_u *word = (char_u *)"";
hlf_T attr = HLF_COUNT;
- int len = 0;
+ size_t len = 0;
rettv_list_alloc(rettv);
@@ -14227,13 +14226,15 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv)
}
}
- list_append_string(rettv->vval.v_list, word, len);
- list_append_string(rettv->vval.v_list, (char_u *)(
- attr == HLF_SPB ? "bad" :
- attr == HLF_SPR ? "rare" :
- attr == HLF_SPL ? "local" :
- attr == HLF_SPC ? "caps" :
- ""), -1);
+ assert(len <= INT_MAX);
+ list_append_string(rettv->vval.v_list, word, (int)len);
+ list_append_string(rettv->vval.v_list,
+ (char_u *)(attr == HLF_SPB ? "bad" :
+ attr == HLF_SPR ? "rare" :
+ attr == HLF_SPL ? "local" :
+ attr == HLF_SPC ? "caps" :
+ ""),
+ -1);
}
/*
@@ -19803,10 +19804,10 @@ void ex_oldfiles(exarg_T *eap)
int
modify_fname (
char_u *src, /* string with modifiers */
- int *usedlen, /* characters after src that are used */
+ size_t *usedlen, /* characters after src that are used */
char_u **fnamep, /* file name so far */
char_u **bufp, /* buffer for allocated file name or NULL */
- int *fnamelen /* length of fnamep */
+ size_t *fnamelen /* length of fnamep */
)
{
int valid = 0;
@@ -19865,7 +19866,7 @@ repeat:
/* Append a path separator to a directory. */
if (os_isdir(*fnamep)) {
/* Make room for one or two extra characters. */
- *fnamep = vim_strnsave(*fnamep, (int)STRLEN(*fnamep) + 2);
+ *fnamep = vim_strnsave(*fnamep, STRLEN(*fnamep) + 2);
xfree(*bufp); /* free any allocated file name */
*bufp = *fnamep;
if (*fnamep == NULL)
@@ -19922,7 +19923,7 @@ repeat:
}
tail = path_tail(*fnamep);
- *fnamelen = (int)STRLEN(*fnamep);
+ *fnamelen = STRLEN(*fnamep);
/* ":h" - head, remove "/file_name", can be repeated */
/* Don't remove the first "/" or "c:\" */
@@ -19932,7 +19933,7 @@ repeat:
s = get_past_head(*fnamep);
while (tail > s && after_pathsep((char *)s, (char *)tail))
mb_ptr_back(*fnamep, tail);
- *fnamelen = (int)(tail - *fnamep);
+ *fnamelen = (size_t)(tail - *fnamep);
if (*fnamelen == 0) {
/* Result is empty. Turn it into "." to make ":cd %:h" work. */
xfree(*bufp);
@@ -19953,7 +19954,7 @@ repeat:
/* ":t" - tail, just the basename */
if (src[*usedlen] == ':' && src[*usedlen + 1] == 't') {
*usedlen += 2;
- *fnamelen -= (int)(tail - *fnamep);
+ *fnamelen -= (size_t)(tail - *fnamep);
*fnamep = tail;
}
@@ -19974,13 +19975,13 @@ repeat:
break;
if (src[*usedlen + 1] == 'e') { /* :e */
if (s > tail) {
- *fnamelen += (int)(*fnamep - (s + 1));
+ *fnamelen += (size_t)(*fnamep - (s + 1));
*fnamep = s + 1;
} else if (*fnamep <= tail)
*fnamelen = 0;
} else { /* :r */
if (s > tail) /* remove one extension */
- *fnamelen = (int)(s - *fnamep);
+ *fnamelen = (size_t)(s - *fnamep);
}
*usedlen += 2;
}
@@ -20016,10 +20017,10 @@ repeat:
if (p != NULL) {
sub = vim_strnsave(s, (int)(p - s));
str = vim_strnsave(*fnamep, *fnamelen);
- *usedlen = (int)(p + 1 - src);
+ *usedlen = (size_t)(p + 1 - src);
s = do_string_sub(str, pat, sub, flags);
*fnamep = s;
- *fnamelen = (int)STRLEN(s);
+ *fnamelen = STRLEN(s);
xfree(*bufp);
*bufp = s;
didit = TRUE;
@@ -20038,7 +20039,7 @@ repeat:
p = vim_strsave_shellescape(*fnamep, false, false);
xfree(*bufp);
*bufp = *fnamep = p;
- *fnamelen = (int)STRLEN(p);
+ *fnamelen = STRLEN(p);
*usedlen += 2;
}
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index f659538611..51010983bb 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -10,6 +10,7 @@
* ex_docmd.c: functions for executing an Ex command line.
*/
+#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
@@ -3415,7 +3416,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
{
int has_wildcards; /* need to expand wildcards */
char_u *repl;
- int srclen;
+ size_t srclen;
char_u *p;
int escaped;
@@ -3543,8 +3544,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
} else
p = NULL;
if (p != NULL) {
- (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
- p, cmdlinep);
+ (void)repl_cmdline(eap, eap->arg, STRLEN(eap->arg), p, cmdlinep);
}
}
@@ -3593,8 +3593,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
if (p == NULL)
return FAIL;
if (p != NULL) {
- (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
- p, cmdlinep);
+ (void)repl_cmdline(eap, eap->arg, STRLEN(eap->arg), p, cmdlinep);
xfree(p);
}
}
@@ -3609,22 +3608,19 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
* "repl" is the replacement string.
* Returns a pointer to the character after the replaced string.
*/
-static char_u *repl_cmdline(exarg_T *eap, char_u *src, int srclen, char_u *repl, char_u **cmdlinep)
+static char_u *repl_cmdline(exarg_T *eap, char_u *src, size_t srclen,
+ char_u *repl, char_u **cmdlinep)
{
- int len;
- int i;
- char_u *new_cmdline;
-
/*
* The new command line is build in new_cmdline[].
* First allocate it.
* Careful: a "+cmd" argument may have been NUL terminated.
*/
- len = (int)STRLEN(repl);
- i = (int)(src - *cmdlinep) + (int)STRLEN(src + srclen) + len + 3;
+ size_t len = STRLEN(repl);
+ size_t i = (size_t)(src - *cmdlinep) + STRLEN(src + srclen) + len + 3;
if (eap->nextcmd != NULL)
- i += (int)STRLEN(eap->nextcmd); /* add space for next command */
- new_cmdline = xmalloc(i);
+ i += STRLEN(eap->nextcmd); /* add space for next command */
+ char_u *new_cmdline = xmalloc(i);
/*
* Copy the stuff before the expanded part.
@@ -3632,16 +3628,16 @@ static char_u *repl_cmdline(exarg_T *eap, char_u *src, int srclen, char_u *repl,
* Copy what came after the expanded part.
* Copy the next commands, if there are any.
*/
- i = (int)(src - *cmdlinep); /* length of part before match */
- memmove(new_cmdline, *cmdlinep, (size_t)i);
+ i = (size_t)(src - *cmdlinep); /* length of part before match */
+ memmove(new_cmdline, *cmdlinep, i);
- memmove(new_cmdline + i, repl, (size_t)len);
+ memmove(new_cmdline + i, repl, len);
i += len; /* remember the end of the string */
STRCPY(new_cmdline + i, src + srclen);
src = new_cmdline + i; /* remember where to continue */
if (eap->nextcmd != NULL) { /* append next command */
- i = (int)STRLEN(new_cmdline) + 1;
+ i = STRLEN(new_cmdline) + 1;
STRCPY(new_cmdline + i, eap->nextcmd);
eap->nextcmd = new_cmdline + i;
}
@@ -5688,8 +5684,8 @@ void ex_splitview(exarg_T *eap)
}
if (eap->cmdidx == CMD_sfind || eap->cmdidx == CMD_tabfind) {
- fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg),
- FNAME_MESS, TRUE, curbuf->b_ffname);
+ fname = find_file_in_path(eap->arg, STRLEN(eap->arg),
+ FNAME_MESS, TRUE, curbuf->b_ffname);
if (fname == NULL)
goto theend;
eap->arg = fname;
@@ -5901,16 +5897,15 @@ static void ex_find(exarg_T *eap)
char_u *fname;
int count;
- fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg), FNAME_MESS,
- TRUE, curbuf->b_ffname);
+ fname = find_file_in_path(eap->arg, STRLEN(eap->arg),
+ FNAME_MESS, TRUE, curbuf->b_ffname);
if (eap->addr_count > 0) {
/* Repeat finding the file "count" times. This matters when it
* appears several times in the path. */
count = eap->line2;
while (fname != NULL && --count > 0) {
xfree(fname);
- fname = find_file_in_path(NULL, 0, FNAME_MESS,
- FALSE, curbuf->b_ffname);
+ fname = find_file_in_path(NULL, 0, FNAME_MESS, FALSE, curbuf->b_ffname);
}
}
@@ -7090,7 +7085,7 @@ static void ex_normal(exarg_T *eap)
tasave_T tabuf;
int save_insertmode = p_im;
int save_finish_op = finish_op;
- int save_opcount = opcount;
+ long save_opcount = opcount;
char_u *arg = NULL;
int l;
char_u *p;
@@ -7252,8 +7247,8 @@ void exec_normal_cmd(char_u *cmd, int remap, int silent)
static void ex_checkpath(exarg_T *eap)
{
find_pattern_in_path(NULL, 0, 0, FALSE, FALSE, CHECK_PATH, 1L,
- eap->forceit ? ACTION_SHOW_ALL : ACTION_SHOW,
- (linenr_T)1, (linenr_T)MAXLNUM);
+ eap->forceit ? ACTION_SHOW_ALL : ACTION_SHOW,
+ (linenr_T)1, (linenr_T)MAXLNUM);
}
/*
@@ -7312,10 +7307,9 @@ static void ex_findpat(exarg_T *eap)
}
}
if (!eap->skip)
- find_pattern_in_path(eap->arg, 0, (int)STRLEN(eap->arg),
- whole, !eap->forceit,
- *eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY,
- n, action, eap->line1, eap->line2);
+ find_pattern_in_path(eap->arg, 0, STRLEN(eap->arg), whole, !eap->forceit,
+ *eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY,
+ n, action, eap->line1, eap->line2);
}
@@ -7414,10 +7408,10 @@ static void ex_tag_cmd(exarg_T *eap, char_u *name)
* If found return one of the SPEC_ values and set "*usedlen" to the length of
* the variable. Otherwise return -1 and "*usedlen" is unchanged.
*/
-int find_cmdline_var(const char_u *src, int *usedlen) FUNC_ATTR_NONNULL_ALL
+ssize_t find_cmdline_var(const char_u *src, size_t *usedlen)
+ FUNC_ATTR_NONNULL_ALL
{
- int len;
- int i;
+ size_t len;
static char *(spec_str[]) = {
"%",
#define SPEC_PERC 0
@@ -7441,11 +7435,12 @@ int find_cmdline_var(const char_u *src, int *usedlen) FUNC_ATTR_NONNULL_ALL
# define SPEC_AMATCH 9
};
- for (i = 0; i < (int)ARRAY_SIZE(spec_str); ++i) {
- len = (int)STRLEN(spec_str[i]);
+ for (size_t i = 0; i < ARRAY_SIZE(spec_str); ++i) {
+ len = STRLEN(spec_str[i]);
if (STRNCMP(src, spec_str[i], len) == 0) {
*usedlen = len;
- return i;
+ assert(i <= SSIZE_MAX);
+ return (ssize_t)i;
}
}
return -1;
@@ -7475,7 +7470,7 @@ char_u *
eval_vars (
char_u *src, /* pointer into commandline */
char_u *srcstart, /* beginning of valid memory for src */
- int *usedlen, /* characters after src that are used */
+ size_t *usedlen, /* characters after src that are used */
linenr_T *lnump, /* line number for :e command, or NULL */
char_u **errormsg, /* pointer to error message */
int *escaped /* return value has escaped white space (can
@@ -7486,10 +7481,9 @@ eval_vars (
char_u *s;
char_u *result;
char_u *resultbuf = NULL;
- int resultlen;
+ size_t resultlen;
buf_T *buf;
int valid = VALID_HEAD + VALID_PATH; /* assume valid result */
- int spec_idx;
int skip_mod = FALSE;
char_u strbuf[30];
@@ -7500,7 +7494,7 @@ eval_vars (
/*
* Check if there is something to do.
*/
- spec_idx = find_cmdline_var(src, usedlen);
+ ssize_t spec_idx = find_cmdline_var(src, usedlen);
if (spec_idx < 0) { /* no match */
*usedlen = 1;
return NULL;
@@ -7520,8 +7514,9 @@ eval_vars (
* word or WORD under cursor
*/
if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD) {
- resultlen = find_ident_under_cursor(&result, spec_idx == SPEC_CWORD ?
- (FIND_IDENT|FIND_STRING) : FIND_STRING);
+ resultlen = find_ident_under_cursor(&result, (spec_idx == SPEC_CWORD
+ ? (FIND_IDENT|FIND_STRING)
+ : FIND_STRING));
if (resultlen == 0) {
*errormsg = (char_u *)"";
return NULL;
@@ -7558,7 +7553,7 @@ eval_vars (
if (*s == '<') /* "#<99" uses v:oldfiles */
++s;
i = getdigits_int(&s);
- *usedlen = (int)(s - src); /* length of what we expand */
+ *usedlen = (size_t)(s - src); /* length of what we expand */
if (src[1] == '<') {
if (*usedlen < 2) {
@@ -7657,14 +7652,13 @@ eval_vars (
return NULL;
}
- resultlen = (int)STRLEN(result); /* length of new string */
+ resultlen = STRLEN(result); /* length of new string */
if (src[*usedlen] == '<') { /* remove the file name extension */
++*usedlen;
if ((s = vim_strrchr(result, '.')) != NULL && s >= path_tail(result))
- resultlen = (int)(s - result);
+ resultlen = (size_t)(s - result);
} else if (!skip_mod) {
- valid |= modify_fname(src, usedlen, &result, &resultbuf,
- &resultlen);
+ valid |= modify_fname(src, usedlen, &result, &resultbuf, &resultlen);
if (result == NULL) {
*errormsg = (char_u *)"";
return NULL;
@@ -7750,11 +7744,11 @@ static char_u *arg_all(void)
char_u *expand_sfile(char_u *arg)
{
char_u *errormsg;
- int len;
+ size_t len;
char_u *result;
char_u *newres;
char_u *repl;
- int srclen;
+ size_t srclen;
char_u *p;
result = vim_strsave(arg);
@@ -7775,11 +7769,11 @@ char_u *expand_sfile(char_u *arg)
p += srclen;
continue;
}
- len = (int)STRLEN(result) - srclen + (int)STRLEN(repl) + 1;
+ len = STRLEN(result) - srclen + STRLEN(repl) + 1;
newres = xmalloc(len);
memmove(newres, result, (size_t)(p - result));
STRCPY(newres + (p - result), repl);
- len = (int)STRLEN(newres);
+ len = STRLEN(newres);
STRCAT(newres, p + srclen);
xfree(repl);
xfree(result);
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 42779d6b71..2777271377 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1310,15 +1310,17 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v)
char_u *
find_file_in_path (
char_u *ptr, /* file name */
- int len, /* length of file name */
+ size_t len, /* length of file name */
int options,
int first, /* use count'th matching file name */
char_u *rel_fname /* file name searching relative to */
)
{
return find_file_in_path_option(ptr, len, options, first,
- *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path,
- FINDFILE_BOTH, rel_fname, curbuf->b_p_sua);
+ (*curbuf->b_p_path == NUL
+ ? p_path
+ : curbuf->b_p_path),
+ FINDFILE_BOTH, rel_fname, curbuf->b_p_sua);
}
static char_u *ff_file_to_find = NULL;
@@ -1347,19 +1349,19 @@ void free_findfile(void)
char_u *
find_directory_in_path (
char_u *ptr, /* file name */
- int len, /* length of file name */
+ size_t len, /* length of file name */
int options,
char_u *rel_fname /* file name searching relative to */
)
{
return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath,
- FINDFILE_DIR, rel_fname, (char_u *)"");
+ FINDFILE_DIR, rel_fname, (char_u *)"");
}
char_u *
find_file_in_path_option (
char_u *ptr, /* file name */
- int len, /* length of file name */
+ size_t len, /* length of file name */
int options,
int first, /* use count'th matching file name */
char_u *path_option, /* p_path or p_cdpath */
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 832377f488..7d1666f866 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -802,7 +802,7 @@ EXTERN int State INIT(= NORMAL); /* This is the current state of the
* command interpreter. */
EXTERN int finish_op INIT(= FALSE); /* TRUE while an operator is pending */
-EXTERN int opcount INIT(= 0); /* count for pending operator */
+EXTERN long opcount INIT(= 0); /* count for pending operator */
/*
* ex mode (Q) state
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index bdaf88e574..a7052149e0 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -455,18 +455,16 @@ cs_add_common (
char *fname2 = NULL;
char *ppath = NULL;
int i;
- int len;
- int usedlen = 0;
+ size_t usedlen = 0;
char_u *fbuf = NULL;
/* get the filename (arg1), expand it, and try to stat it */
fname = xmalloc(MAXPATHL + 1);
expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
- len = (int)STRLEN(fname);
+ size_t len = STRLEN(fname);
fbuf = (char_u *)fname;
- (void)modify_fname((char_u *)":p", &usedlen,
- (char_u **)&fname, &fbuf, &len);
+ (void)modify_fname((char_u *)":p", &usedlen, (char_u **)&fname, &fbuf, &len);
if (fname == NULL)
goto add_err;
fname = (char *)vim_strnsave((char_u *)fname, len);
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
index 7a584d4ea1..87a9556202 100644
--- a/src/nvim/misc2.c
+++ b/src/nvim/misc2.c
@@ -382,8 +382,8 @@ int vim_chdir(char_u *new_dir)
char_u *dir_name;
int r;
- dir_name = find_directory_in_path(new_dir, (int)STRLEN(new_dir),
- FNAME_MESS, curbuf->b_ffname);
+ dir_name = find_directory_in_path(new_dir, STRLEN(new_dir),
+ FNAME_MESS, curbuf->b_ffname);
if (dir_name == NULL)
return -1;
r = os_chdir((char *)dir_name);
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index b7f2666968..9462a2186e 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -350,19 +350,23 @@ static int nv_compare(const void *s1, const void *s2)
*/
void init_normal_cmds(void)
{
- int i;
+ assert(NV_CMDS_SIZE <= SHRT_MAX);
/* Fill the index table with a one to one relation. */
- for (i = 0; i < (int)NV_CMDS_SIZE; ++i)
+ for (short int i = 0; i < (short int)NV_CMDS_SIZE; ++i) {
nv_cmd_idx[i] = i;
+ }
/* Sort the commands by the command character. */
- qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare);
+ qsort(&nv_cmd_idx, NV_CMDS_SIZE, sizeof(short), nv_compare);
/* Find the first entry that can't be indexed by the command character. */
- for (i = 0; i < (int)NV_CMDS_SIZE; ++i)
- if (i != nv_cmds[nv_cmd_idx[i]].cmd_char)
+ short int i;
+ for (i = 0; i < (short int)NV_CMDS_SIZE; ++i) {
+ if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) {
break;
+ }
+ }
nv_max_linear = i - 1;
}
@@ -1846,7 +1850,7 @@ do_mouse (
static pos_T orig_cursor;
colnr_T leftcol, rightcol;
pos_T end_visual;
- int diff;
+ long diff;
int old_active = VIsual_active;
int old_mode = VIsual_mode;
int regname;
@@ -2589,7 +2593,7 @@ void reset_VIsual(void)
* If a string is found, a pointer to the string is put in "*string". This
* string is not always NUL terminated.
*/
-int find_ident_under_cursor(char_u **string, int find_type)
+size_t find_ident_under_cursor(char_u **string, int find_type)
{
return find_ident_at_pos(curwin, curwin->w_cursor.lnum,
curwin->w_cursor.col, string, find_type);
@@ -2599,7 +2603,8 @@ int find_ident_under_cursor(char_u **string, int find_type)
* Like find_ident_under_cursor(), but for any window and any position.
* However: Uses 'iskeyword' from the current window!.
*/
-int find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char_u **string, int find_type)
+size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol,
+ char_u **string, int find_type)
{
char_u *ptr;
int col = 0; /* init to shut up GCC */
@@ -2707,7 +2712,8 @@ int find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char_u **strin
++col;
}
- return col;
+ assert(col >= 0);
+ return (size_t)col;
}
/*
@@ -2899,9 +2905,6 @@ void clear_showcmd(void)
bool add_to_showcmd(int c)
{
char_u *p;
- int old_len;
- int extra_len;
- int overflow;
int i;
static int ignore[] =
{
@@ -2932,12 +2935,12 @@ bool add_to_showcmd(int c)
p = transchar(c);
if (*p == ' ')
STRCPY(p, "<20>");
- old_len = (int)STRLEN(showcmd_buf);
- extra_len = (int)STRLEN(p);
- overflow = old_len + extra_len - SHOWCMD_COLS;
- if (overflow > 0)
- memmove(showcmd_buf, showcmd_buf + overflow,
- old_len - overflow + 1);
+ size_t old_len = STRLEN(showcmd_buf);
+ size_t extra_len = STRLEN(p);
+ if (old_len + extra_len > SHOWCMD_COLS) {
+ size_t overflow = old_len + extra_len - SHOWCMD_COLS;
+ memmove(showcmd_buf, showcmd_buf + overflow, old_len - overflow + 1);
+ }
STRCAT(showcmd_buf, p);
if (char_avail())
@@ -3220,11 +3223,10 @@ nv_gd (
int thisblock /* 1 for "1gd" and "1gD" */
)
{
- int len;
- char_u *ptr;
-
+ size_t len;
+ char_u *ptr;
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0
- || find_decl(ptr, len, nchar == 'd', thisblock, 0) == false)
+ || !find_decl(ptr, len, nchar == 'd', thisblock, 0))
clearopbeep(oap);
else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP)
foldOpenCursor();
@@ -3240,7 +3242,7 @@ nv_gd (
bool
find_decl (
char_u *ptr,
- int len,
+ size_t len,
bool locally,
bool thisblock,
int searchflags /* flags passed to searchit() */
@@ -3260,8 +3262,9 @@ find_decl (
/* Put "\V" before the pattern to avoid that the special meaning of "."
* and "~" causes trouble. */
+ assert(len <= INT_MAX);
sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s",
- len, ptr);
+ (int)len, ptr);
old_pos = curwin->w_cursor;
save_p_ws = p_ws;
save_p_scs = p_scs;
@@ -3586,13 +3589,16 @@ void scroll_redraw(int up, long count)
*/
static void nv_zet(cmdarg_T *cap)
{
- long n;
+ int n;
colnr_T col;
int nchar = cap->nchar;
long old_fdl = curwin->w_p_fdl;
int old_fen = curwin->w_p_fen;
bool undo = false;
+ assert(p_siso <= INT_MAX);
+ int l_p_siso = (int)p_siso;
+
if (ascii_isdigit(nchar)) {
/*
* "z123{nchar}": edit the count before obtaining {nchar}
@@ -3613,7 +3619,7 @@ static void nv_zet(cmdarg_T *cap)
else if (ascii_isdigit(nchar))
n = n * 10 + (nchar - '0');
else if (nchar == CAR) {
- win_setheight((int)n);
+ win_setheight(n);
break;
} else if (nchar == 'l'
|| nchar == 'h'
@@ -3744,8 +3750,8 @@ dozet:
col = 0; /* like the cursor is in col 0 */
else
getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL);
- if ((long)col > p_siso)
- col -= p_siso;
+ if (col > l_p_siso)
+ col -= l_p_siso;
else
col = 0;
if (curwin->w_leftcol != col) {
@@ -3762,10 +3768,10 @@ dozet:
else
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
n = curwin->w_width - curwin_col_off();
- if ((long)col + p_siso < n)
+ if (col + l_p_siso < n)
col = 0;
else
- col = col + p_siso - n + 1;
+ col = col + l_p_siso - n + 1;
if (curwin->w_leftcol != col) {
curwin->w_leftcol = col;
redraw_later(NOT_VALID);
@@ -3941,12 +3947,11 @@ dozet:
case 'W': /* "zW": add wrong word to temp word list */
{
char_u *ptr = NULL;
- int len;
+ size_t len;
if (checkclearop(cap->oap))
break;
- if (VIsual_active &&